Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e72f683

Browse files
cmaglieper1234
andauthored
Now compile --only-compilation-database will run all pre-* hooks (#1549)
* Clean up some useless constants * made legacy/builder.go independent from legacy/constants * Now 'compile --only-compilation-database' will run all pre-* hooks Some platforms make sketch preparation see #1547 Fix #1547 Co-authored-by: per1234 <accounts@perglass.com>
1 parent bf4a784 commit e72f683

File tree

7 files changed

+44
-61
lines changed

7 files changed

+44
-61
lines changed

‎cli/compile/compile.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func NewCommand() *cobra.Command {
112112
command.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
113113
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
114114
})
115-
command.Flags().BoolVar(&compilationDatabaseOnly, "only-compilation-database", false, tr("Just produce the compilation database, without actually compiling."))
115+
command.Flags().BoolVar(&compilationDatabaseOnly, "only-compilation-database", false, tr("Just produce the compilation database, without actually compiling. All build commands are skipped except pre* hooks."))
116116
command.Flags().BoolVar(&clean, "clean", false, tr("Optional, cleanup the build folder and do not use any cached build."))
117117
// We must use the following syntax for this flag since it's also bound to settings.
118118
// This must be done because the value is set when the binding is accessed from viper. Accessing from cobra would only

‎docs/platform-specification.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ recipe.hooks.sketch.prebuild.02.pattern=echo 2
399399
recipe.hooks.sketch.prebuild.11.pattern=echo 11
400400
```
401401

402+
Note: all the `pre*` hooks are executed while producing the "compilation database" (a JSON file with the list of
403+
commands to run to compile the sketch), but the `post*` hooks and all compile commands are skipped. See the
404+
[`arduino-cli compile`](commands/arduino-cli_compile.md) command reference for more info.
405+
402406
## Global platform.txt
403407

404408
Properties defined in a platform.txt created in the **hardware** subfolder of the Arduino IDE installation folder will

‎legacy/builder/builder.go‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/sketch"
2525
"github.com/arduino/arduino-cli/i18n"
2626
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
27-
"github.com/arduino/arduino-cli/legacy/builder/constants"
2827
"github.com/arduino/arduino-cli/legacy/builder/phases"
2928
"github.com/arduino/arduino-cli/legacy/builder/types"
3029
"github.com/arduino/arduino-cli/legacy/builder/utils"
@@ -55,46 +54,46 @@ func (s *Builder) Run(ctx *types.Context) error {
5554

5655
&WarnAboutPlatformRewrites{},
5756

58-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
57+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"},
5958

6059
&ContainerMergeCopySketchFiles{},
6160

62-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Detecting libraries used...")),
61+
utils.LogIfVerbose("info", tr("Detecting libraries used...")),
6362
&ContainerFindIncludes{},
6463

6564
&WarnAboutArchIncompatibleLibraries{},
6665

67-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Generating function prototypes...")),
66+
utils.LogIfVerbose("info", tr("Generating function prototypes...")),
6867
&PreprocessSketch{},
6968

70-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Compiling sketch...")),
71-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
69+
utils.LogIfVerbose("info", tr("Compiling sketch...")),
70+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.prebuild", Suffix: ".pattern"},
7271
&phases.SketchBuilder{},
73-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
72+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
7473

75-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Compiling libraries...")),
76-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
74+
utils.LogIfVerbose("info", tr("Compiling libraries...")),
75+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.libraries.prebuild", Suffix: ".pattern"},
7776
&UnusedCompiledLibrariesRemover{},
7877
&phases.LibrariesBuilder{},
79-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
78+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.libraries.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
8079

81-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Compiling core...")),
82-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
80+
utils.LogIfVerbose("info", tr("Compiling core...")),
81+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.core.prebuild", Suffix: ".pattern"},
8382
&phases.CoreBuilder{},
84-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
83+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.core.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
8584

86-
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, tr("Linking everything together...")),
87-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_PRELINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},
85+
utils.LogIfVerbose("info", tr("Linking everything together...")),
86+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.linking.prelink", Suffix: ".pattern"},
8887
&phases.Linker{},
89-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_POSTLINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},
88+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.linking.postlink", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9089

91-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY_PREOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
92-
&RecipeByPrefixSuffixRunner{Prefix: "recipe.objcopy.", Suffix: constants.HOOKS_PATTERN_SUFFIX},
93-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY_POSTOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
90+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.objcopy.preobjcopy", Suffix: ".pattern"},
91+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.objcopy.", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
92+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.objcopy.postobjcopy", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9493

9594
&MergeSketchWithBootloader{},
9695

97-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
96+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9897
}
9998

10099
mainErr := runCommands(ctx, commands)
@@ -149,7 +148,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
149148

150149
&ContainerBuildOptions{},
151150

152-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
151+
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"},
153152

154153
&ContainerMergeCopySketchFiles{},
155154

@@ -203,7 +202,7 @@ func runCommands(ctx *types.Context, commands []types.Command) error {
203202

204203
func PrintRingNameIfDebug(ctx *types.Context, command types.Command) {
205204
if ctx.DebugLevel >= 10 {
206-
ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Ts: {0} - Running: {1}", strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())
205+
ctx.GetLogger().Fprintln(os.Stdout, "debug", "Ts: {0} - Running: {1}", strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())
207206
}
208207
}
209208

‎legacy/builder/constants/constants.go‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,6 @@ const FOLDER_CORE = "core"
4747
const FOLDER_PREPROC = "preproc"
4848
const FOLDER_SKETCH = "sketch"
4949
const FOLDER_TOOLS = "tools"
50-
const hooks_core = hooks + ".core"
51-
const HOOKS_CORE_POSTBUILD = hooks_core + hooks_postbuild_suffix
52-
const HOOKS_CORE_PREBUILD = hooks_core + hooks_prebuild_suffix
53-
const hooks_libraries = hooks + ".libraries"
54-
const HOOKS_LIBRARIES_POSTBUILD = hooks_libraries + hooks_postbuild_suffix
55-
const HOOKS_LIBRARIES_PREBUILD = hooks_libraries + hooks_prebuild_suffix
56-
const hooks_linking = hooks + ".linking"
57-
const HOOKS_LINKING_POSTLINK = hooks_linking + hooks_postlink_suffix
58-
const HOOKS_LINKING_PRELINK = hooks_linking + hooks_prelink_suffix
59-
const hooks_objcopy = hooks + ".objcopy"
60-
const HOOKS_OBJCOPY_POSTOBJCOPY = hooks_objcopy + hooks_postobjcopy_suffix
61-
const HOOKS_OBJCOPY_PREOBJCOPY = hooks_objcopy + hooks_preobjcopy_suffix
62-
const HOOKS_PATTERN_SUFFIX = ".pattern"
63-
const HOOKS_POSTBUILD = hooks + hooks_postbuild_suffix
64-
const hooks_postbuild_suffix = ".postbuild"
65-
const hooks_postlink_suffix = ".postlink"
66-
const hooks_postobjcopy_suffix = ".postobjcopy"
67-
const HOOKS_PREBUILD = hooks + hooks_prebuild_suffix
68-
const hooks_prebuild_suffix = ".prebuild"
69-
const hooks_prelink_suffix = ".prelink"
70-
const hooks_preobjcopy_suffix = ".preobjcopy"
71-
const hooks = "recipe.hooks"
72-
const hooks_sketch = hooks + ".sketch"
73-
const HOOKS_SKETCH_POSTBUILD = hooks_sketch + hooks_postbuild_suffix
74-
const HOOKS_SKETCH_PREBUILD = hooks_sketch + hooks_prebuild_suffix
7550
const LIBRARY_ALL_ARCHS = "*"
7651
const LIBRARY_EMAIL = "email"
7752
const LIBRARY_FOLDER_ARCH = "arch"

‎legacy/builder/recipe_runner.go‎

Lines changed: 4 additions & 3 deletions
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
}

‎legacy/builder/test/recipe_runner_test.go‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import (
1919
"testing"
2020

2121
"github.com/arduino/arduino-cli/legacy/builder"
22-
"github.com/arduino/arduino-cli/legacy/builder/constants"
2322
"github.com/arduino/arduino-cli/legacy/builder/types"
2423
"github.com/arduino/go-properties-orderedmap"
25-
"github.com/stretchr/testify/require"
2624
)
2725

2826
// TODO
@@ -38,18 +36,11 @@ func TestRecipeRunner(t *testing.T) {
3836

3937
commands := []types.Command{
4038
&builder.AddAdditionalEntriesToContext{},
41-
&builder.RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
39+
&builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"},
4240
}
4341

4442
for _, command := range commands {
4543
err := command.Run(ctx)
4644
NoError(t, err)
4745
}
4846
}
49-
50-
func TestRecipesComposition(t *testing.T) {
51-
require.Equal(t, "recipe.hooks.core.postbuild", constants.HOOKS_CORE_POSTBUILD)
52-
require.Equal(t, "recipe.hooks.postbuild", constants.HOOKS_POSTBUILD)
53-
require.Equal(t, "recipe.hooks.linking.prelink", constants.HOOKS_LINKING_PRELINK)
54-
require.Equal(t, "recipe.hooks.objcopy.preobjcopy", constants.HOOKS_OBJCOPY_PREOBJCOPY)
55-
}

‎test/test_compile_part_4.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ 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@2.0.1", f"--additional-urls={url}"])
303+
304+
sketch_path = copy_sketch("sketch_simple")
305+
assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path])
306+
307+
295308
def test_compile_sketch_with_tpp_file_include(run_command, copy_sketch):
296309
assert run_command(["update"])
297310

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /