Skip to content

Commit 6f5e242

Browse files
Put utility folders in the include path during include detection
When compiling source files from a library, the utility folder of the library itself is in the include path. When doing include detection, this did not happen, which could lead to compilation errors. Because of the broken (but recently fixed) errorhandling in include detection, this error was not visible to the user. It would only have a visible effect if a library included another library *after* including a file from its utility folder through the include path, and that other library was not otherwise pulled in. In practice, this would almost never occur, but with the new caching the cache would be invalidated and this problem became visible. This is fixed by simply including the utility folder in the include path during include detection. This required explicitly passing the include path through the GCCPreprocRunnerForDiscoveringIncludes and GCCPreprocRunner. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 7dd4e1c commit 6f5e242

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/arduino.cc/builder/container_add_prototypes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type ContainerAddPrototypes struct{}
4343
func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
4444
sourceFile := filepath.Join(ctx.SketchBuildPath, filepath.Base(ctx.Sketch.MainFile.Name)+".cpp")
4545
commands := []types.Command{
46-
&GCCPreprocRunner{SourceFilePath: sourceFile, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
46+
&GCCPreprocRunner{SourceFilePath: sourceFile, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, Includes: ctx.IncludeFolders},
4747
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
4848
&FilterSketchSource{Source: &ctx.SourceGccMinusE},
4949
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},

src/arduino.cc/builder/container_find_includes.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,19 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
312312
for {
313313
var include string
314314
cache.ExpectFile(sourcePath)
315+
316+
includes := ctx.IncludeFolders
317+
if library, ok := sourceFile.Origin.(*types.Library); ok && library.UtilityFolder != "" {
318+
includes = append(includes, library.UtilityFolder)
319+
}
315320
if unchanged && cache.valid {
316321
include = cache.Next().Include
317322
if first && ctx.Verbose {
318323
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_CACHED_INCLUDES, sourcePath)
319324
}
320325
} else {
321326
commands := []types.Command{
322-
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourcePath, TargetFilePath: targetFilePath},
327+
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourcePath, TargetFilePath: targetFilePath, Includes: includes},
323328
&IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE},
324329
}
325330
for _, command := range commands {
@@ -340,7 +345,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
340345
library := ResolveLibrary(ctx, include)
341346
if library == nil {
342347
// Library could not be resolved, show error
343-
err := runCommand(ctx, &GCCPreprocRunner{SourceFilePath: sourcePath, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
348+
err := runCommand(ctx, &GCCPreprocRunner{SourceFilePath: sourcePath, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, Includes: includes})
344349
return i18n.WrapError(err)
345350
}
346351

src/arduino.cc/builder/gcc_preproc_runner.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ import (
4444
type GCCPreprocRunner struct {
4545
SourceFilePath string
4646
TargetFileName string
47+
Includes []string
4748
}
4849

4950
func (s *GCCPreprocRunner) Run(ctx *types.Context) error {
50-
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFileName)
51+
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFileName, s.Includes)
5152
if err != nil {
5253
return i18n.WrapError(err)
5354
}
@@ -72,10 +73,11 @@ func (s *GCCPreprocRunner) Run(ctx *types.Context) error {
7273
type GCCPreprocRunnerForDiscoveringIncludes struct {
7374
SourceFilePath string
7475
TargetFilePath string
76+
Includes []string
7577
}
7678

7779
func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error {
78-
properties, _, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFilePath)
80+
properties, _, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFilePath, s.Includes)
7981
if err != nil {
8082
return i18n.WrapError(err)
8183
}
@@ -98,7 +100,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error {
98100
return nil
99101
}
100102

101-
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string) (properties.Map, string, error) {
103+
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (properties.Map, string, error) {
102104
if targetFilePath != utils.NULLFile() {
103105
preprocPath := ctx.PreprocPath
104106
err := utils.EnsureFolderExists(preprocPath)
@@ -112,7 +114,6 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string
112114
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath
113115
properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath
114116

115-
includes := ctx.IncludeFolders
116117
includes = utils.Map(includes, utils.WrapWithHyphenI)
117118
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
118119
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)

0 commit comments

Comments
 (0)