Skip to content

Commit b7d8f28

Browse files
Show errors during include detection properly
When an include could not be resolved, the preprocessor was ran again to show the include error as reported by the compiler to the user. However, the preprocessor was now always run against the main sketch, instead of the file currently being processed. Unless the problem was in fact in the main sketch, this caused no error to be shown and include detection continued with the next file instead of being aborted as intended. This fixes the problem by running the preprocessor on the right file. In the future, this error handling might be a bit more improved, but for now this should be sufficient. Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
1 parent 874b3b6 commit b7d8f28

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/arduino.cc/builder/container_add_prototypes.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
package builder
3131

3232
import (
33+
"path/filepath"
34+
3335
"arduino.cc/builder/constants"
3436
"arduino.cc/builder/ctags"
3537
"arduino.cc/builder/i18n"
@@ -39,8 +41,9 @@ import (
3941
type ContainerAddPrototypes struct{}
4042

4143
func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
44+
sourceFile := filepath.Join(ctx.SketchBuildPath, filepath.Base(ctx.Sketch.MainFile.Name)+".cpp")
4245
commands := []types.Command{
43-
&GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
46+
&GCCPreprocRunner{SourceFilePath: sourceFile, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4447
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
4548
&FilterSketchSource{Source: &ctx.SourceGccMinusE},
4649
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},

src/arduino.cc/builder/container_find_includes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
340340
library := ResolveLibrary(ctx, include)
341341
if library == nil {
342342
// Library could not be resolved, show error
343-
err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
343+
err := runCommand(ctx, &GCCPreprocRunner{SourceFilePath: sourcePath, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
344344
return i18n.WrapError(err)
345345
}
346346

src/arduino.cc/builder/gcc_preproc_runner.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ import (
4242
)
4343

4444
type GCCPreprocRunner struct {
45+
SourceFilePath string
4546
TargetFileName string
4647
}
4748

4849
func (s *GCCPreprocRunner) Run(ctx *types.Context) error {
49-
sketchBuildPath := ctx.SketchBuildPath
50-
sketch := ctx.Sketch
51-
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName)
50+
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFileName)
5251
if err != nil {
5352
return i18n.WrapError(err)
5453
}

0 commit comments

Comments
 (0)