Skip to content

Commit c1c9b1b

Browse files
Store SourceFiles in Context.CollectedSourceFiles
Previously, the include detection kept a queue of strings representing full paths to source files that still needed to be processed and iterated over it. This commit turns this into a queue containing the (new) SourceFile struct. This gives the include detection code a bit more context about a source file, allowing to also generate the object and dependency file paths. Previously this was not feasible, since it did not know the origin (library/sketch) of a path, so it could not decide where within the build path the object file should live. This does not actually use this new context yet, but it will be useful when introducing caching next. Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
1 parent 0c64d15 commit c1c9b1b

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/arduino.cc/builder/add_additional_entries_to_context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (s *AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
6868
ctx.WarningsLevel = DEFAULT_WARNINGS_LEVEL
6969
}
7070

71-
ctx.CollectedSourceFiles = &types.UniqueStringQueue{}
71+
ctx.CollectedSourceFiles = &types.UniqueSourceFileQueue{}
7272

7373
ctx.LibrariesResolutionResults = make(map[string]types.LibraryResolutionResult)
7474
ctx.HardwareRewriteResults = make(map[*types.Platform][]types.PlatforKeyRewrite)

src/arduino.cc/builder/container_find_includes.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,28 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
4747
appendIncludeFolder(ctx, ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH])
4848
}
4949

50-
sketchBuildPath := ctx.SketchBuildPath
5150
sketch := ctx.Sketch
52-
ctx.CollectedSourceFiles.Push(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"))
51+
mergedfile, err := types.MakeSourceFile(ctx, sketch, filepath.Base(sketch.MainFile.Name)+".cpp")
52+
if err != nil {
53+
return i18n.WrapError(err)
54+
}
55+
ctx.CollectedSourceFiles.Push(mergedfile)
5356

5457
sourceFilePaths := ctx.CollectedSourceFiles
55-
queueSourceFilesFromFolder(sourceFilePaths, ctx.SketchBuildPath, /* recurse */ false)
58+
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, ctx.SketchBuildPath, /* recurse */ false)
5659
srcSubfolderPath := filepath.Join(ctx.SketchBuildPath, constants.SKETCH_FOLDER_SRC)
5760
if info, err := os.Stat(srcSubfolderPath); err == nil && info.IsDir() {
58-
queueSourceFilesFromFolder(sourceFilePaths, srcSubfolderPath, /* recurse */ true)
61+
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, /* recurse */ true)
5962
}
6063

6164
for !sourceFilePaths.Empty() {
62-
err := findIncludesUntilDone(ctx, sourceFilePaths.Pop().(string))
65+
err := findIncludesUntilDone(ctx, sourceFilePaths.Pop())
6366
if err != nil {
6467
return i18n.WrapError(err)
6568
}
6669
}
6770

68-
err := runCommand(ctx, &FailIfImportedLibraryIsWrong{})
71+
err = runCommand(ctx, &FailIfImportedLibraryIsWrong{})
6972
if err != nil {
7073
return i18n.WrapError(err)
7174
}
@@ -87,11 +90,11 @@ func runCommand(ctx *types.Context, command types.Command) error {
8790
return nil
8891
}
8992

90-
func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
93+
func findIncludesUntilDone(ctx *types.Context, sourceFile types.SourceFile) error {
9194
targetFilePath := utils.NULLFile()
9295
for {
9396
commands := []types.Command{
94-
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
97+
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFile.SourcePath(ctx), TargetFilePath: targetFilePath},
9598
&IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE},
9699
}
97100
for _, command := range commands {
@@ -119,12 +122,12 @@ func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
119122
appendIncludeFolder(ctx, library.SrcFolder)
120123
sourceFolders := types.LibraryToSourceFolder(library)
121124
for _, sourceFolder := range sourceFolders {
122-
queueSourceFilesFromFolder(ctx.CollectedSourceFiles, sourceFolder.Folder, sourceFolder.Recurse)
125+
queueSourceFilesFromFolder(ctx, ctx.CollectedSourceFiles, library, sourceFolder.Folder, sourceFolder.Recurse)
123126
}
124127
}
125128
}
126129

127-
func queueSourceFilesFromFolder(queue *types.UniqueStringQueue, folder string, recurse bool) error {
130+
func queueSourceFilesFromFolder(ctx *types.Context, queue *types.UniqueSourceFileQueue, origin interface{}, folder string, recurse bool) error {
128131
extensions := func(ext string) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext] }
129132

130133
filePaths := []string{}
@@ -134,7 +137,11 @@ func queueSourceFilesFromFolder(queue *types.UniqueStringQueue, folder string, r
134137
}
135138

136139
for _, filePath := range filePaths {
137-
queue.Push(filePath)
140+
sourceFile, err := types.MakeSourceFile(ctx, origin, filePath)
141+
if (err != nil) {
142+
return i18n.WrapError(err)
143+
}
144+
queue.Push(sourceFile)
138145
}
139146

140147
return nil

src/arduino.cc/builder/types/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Context struct {
4646
PreprocPath string
4747
SketchObjectFiles []string
4848

49-
CollectedSourceFiles *UniqueStringQueue
49+
CollectedSourceFiles *UniqueSourceFileQueue
5050

5151
Sketch *Sketch
5252
Source string

0 commit comments

Comments
 (0)