Skip to content

Commit 602008a

Browse files
committed
Now 'compile --only-compilation-database' will run all pre-* hooks
Some platforms make sketch preparation see #1547 Fix #1547
1 parent c33e2a2 commit 602008a

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

legacy/builder/builder.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ func (s *Builder) Run(ctx *types.Context) error {
6969
utils.LogIfVerbose("info", tr("Compiling sketch...")),
7070
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.prebuild", Suffix: ".pattern"},
7171
&phases.SketchBuilder{},
72-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.postbuild", Suffix: ".pattern"},
72+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
7373

7474
utils.LogIfVerbose("info", tr("Compiling libraries...")),
7575
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.libraries.prebuild", Suffix: ".pattern"},
7676
&UnusedCompiledLibrariesRemover{},
7777
&phases.LibrariesBuilder{},
78-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.libraries.postbuild", Suffix: ".pattern"},
78+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.libraries.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
7979

8080
utils.LogIfVerbose("info", tr("Compiling core...")),
8181
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.core.prebuild", Suffix: ".pattern"},
8282
&phases.CoreBuilder{},
83-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.core.postbuild", Suffix: ".pattern"},
83+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.core.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
8484

8585
utils.LogIfVerbose("info", tr("Linking everything together...")),
8686
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.linking.prelink", Suffix: ".pattern"},
8787
&phases.Linker{},
88-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.linking.postlink", Suffix: ".pattern"},
88+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.linking.postlink", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
8989

9090
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.objcopy.preobjcopy", Suffix: ".pattern"},
91-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.objcopy.", Suffix: ".pattern"},
92-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.objcopy.postobjcopy", Suffix: ".pattern"},
91+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.objcopy.", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
92+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.objcopy.postobjcopy", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9393

9494
&MergeSketchWithBootloader{},
9595

96-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.postbuild", Suffix: ".pattern"},
96+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9797
}
9898

9999
mainErr := runCommands(ctx, commands)

legacy/builder/recipe_runner.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929
)
3030

3131
type RecipeByPrefixSuffixRunner struct {
32-
Prefix string
33-
Suffix string
32+
Prefix string
33+
Suffix string
34+
SkipIfOnlyUpdatingCompilationDatabase bool
3435
}
3536

3637
func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error {
@@ -53,7 +54,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error {
5354
return errors.WithStack(err)
5455
}
5556

56-
if ctx.OnlyUpdateCompilationDatabase {
57+
if ctx.OnlyUpdateCompilationDatabase && s.SkipIfOnlyUpdatingCompilationDatabase {
5758
if ctx.Verbose {
5859
ctx.GetLogger().Println("info", tr("Skipping: {0}"), strings.Join(command.Args, " "))
5960
}

test/test_compile_part_4.py

+16
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ def test_compile_with_esp8266_bundled_libraries(run_command, data_dir, copy_sket
292292
assert "\n".join(expected_output) not in res.stdout
293293

294294

295+
def test_generate_compile_commands_json_with_esp32(run_command, data_dir, copy_sketch):
296+
# https://github.com/arduino/arduino-cli/issues/1547
297+
assert run_command(["update"])
298+
299+
# Update index with esp32 core and install it
300+
url = "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json"
301+
assert run_command(["core", "update-index", f"--additional-urls={url}"])
302+
assert run_command(["core", "install", "esp32:esp32", f"--additional-urls={url}"])
303+
304+
# Install a library with the same name as one bundled with the core
305+
assert run_command(["lib", "install", "SD"])
306+
307+
sketch_path = copy_sketch("sketch_simple")
308+
assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path])
309+
310+
295311
def test_compile_sketch_with_tpp_file_include(run_command, copy_sketch):
296312
assert run_command(["update"])
297313

0 commit comments

Comments
 (0)