Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks are recognized even when pattern property name uses string key in place of numeric index #2369

Closed
3 tasks done
ArminJo opened this issue Oct 15, 2023 · 2 comments · Fixed by espressif/arduino-esp32#9220
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@ArminJo
Copy link

ArminJo commented Oct 15, 2023

Describe the problem

Here https://arduino.github.io/arduino-cli/0.34/platform-specification/#pre-and-post-build-hooks-since-arduino-ide-165
the hook recipe.hooks.core.prebuild.set_core_build_flag is not documented.
But it is used By ESP32 platform.txt line 195 ff.

# Set -DARDUINO_CORE_BUILD only on core file compilation
file_opts.path={build.path}/file_opts
recipe.hooks.prebuild.set_core_build_flag.pattern=bash -c ": > {file_opts.path}"
recipe.hooks.core.prebuild.set_core_build_flag.pattern=bash -c "echo -DARDUINO_CORE_BUILD > {file_opts.path}"
recipe.hooks.core.postbuild.set_core_build_flag.pattern=bash -c ": > {file_opts.path}"

recipe.hooks.prebuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{file_opts.path}"
recipe.hooks.core.prebuild.set_core_build_flag.pattern.windows=cmd /c echo "-DARDUINO_CORE_BUILD" > "{file_opts.path}"
recipe.hooks.core.postbuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{file_opts.path}"

see also Sloeber/arduino-eclipse-plugin#1582

To reproduce

Compile any sketch with any ESP32 board:

Creating esp32 image...
Merged 1 ELF section
Successfully created esp32 image.
cmd /c if exist "C:\\Users\\...\\Temp\\.arduinoIDE-unsaved2023915-8796-1rs03z4.hnwd\\SimpleReceiver\\build_opt.h" COPY /y "C:\\Users\\...\\Temp\\.arduinoIDE-unsaved2023915-8796-1rs03z4.hnwd\\SimpleReceiver\\build_opt.h" "C:\\Users\\...\\Temp\\arduino\\sketches\\10BDBB355C916CDD0AC5166109C1A196\\build_opt.h"
cmd /c if not exist "C:\\Users\\...\\Temp\\arduino\\sketches\\10BDBB355C916CDD0AC5166109C1A196\\build_opt.h" type nul > "C:\\Users\\...\\Temp\\arduino\\sketches\\10BDBB355C916CDD0AC5166109C1A196\\build_opt.h"
cmd /c type nul > "C:\\Users\\Armin\\AppData\\Local\\Temp\\arduino\\sketches\\10BDBB355C916CDD0AC5166109C1A196/file_opts"

see last line, where the recipe is executed.

Expected behavior

Please document it, or disable it if it is not officially supported.
Thanks

Arduino CLI version

2.2.0

Operating system

Windows

Operating system version

10

Additional context

Please document it, or disable it, if it is not officially supported.
Thanks

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@ArminJo ArminJo added the type: imperfection Perceived defect in any part of project label Oct 15, 2023
@per1234 per1234 assigned per1234 and unassigned per1234 Oct 27, 2023
@per1234
Copy link
Contributor

per1234 commented Oct 27, 2023

Hi @ArminJo. Thanks for your report. The specification is as intended. The ESP32 platform developers are unnecessarily abusing an incidental behavior where strings happen to be supported in addition to integers as the index in the build hook pattern properties:

if err := b.RunRecipe("recipe.hooks.core.prebuild", ".pattern", false); err != nil {

recipes := findRecipes(buildProperties, prefix, suffix)

if strings.HasPrefix(key, patternPrefix) && strings.HasSuffix(key, patternSuffix) && buildProperties.Get(key) != "" {

So this should be considered a bug in the ESP32 platform and we will not provide explicit support for this format of build hook pattern properties.

I think your proposal that the Arduino CLI codebase be changed to drop support for this non-compliant usage is reasonable since otherwise we end up risking being forced to officially support this jankiness after it spreads to many other platforms due to cursory copy/pasting by platform authors who don't make the effort to understand what they are copying.

The github.com/arduino/go-properties-orderedmap module used to parse platform.txt provides specific handling of the list format used by the hook pattern properties:

https://pkg.go.dev/github.com/arduino/go-properties-orderedmap#Map.ExtractSubIndexSets

Numeric subindex cannot be mixed with non-numeric, in that case only the numeric sub index sets will be returned.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself topic: build-process Related to the sketch build process and removed type: imperfection Perceived defect in any part of project labels Oct 27, 2023
@per1234 per1234 changed the title recipe.hooks.[core.]prebuild.set_core_build_flag is not documented but used by ESP32 Hooks are recognized even when pattern name uses string key in place of numeric index Oct 27, 2023
@per1234 per1234 changed the title Hooks are recognized even when pattern name uses string key in place of numeric index Hooks are recognized even when pattern property name uses string key in place of numeric index Oct 27, 2023
@ArminJo
Copy link
Author

ArminJo commented Oct 27, 2023

Thank you very much for this analysis! 🥇
It seems that the ESP 3.x version does not use this recipe any more 😀 .

@ArminJo ArminJo closed this as completed Oct 27, 2023
pillo79 added a commit to pillo79/arduino-esp32 that referenced this issue Feb 7, 2024
The Arduino Platform Specification requires that the recipe hooks are
distinguished by a number and does not endorse using text labels. Fix
all the usages of recipe hooks to use numbers.

Closes arduino/arduino-cli#2369 .
pillo79 added a commit to pillo79/arduino-esp32 that referenced this issue Feb 7, 2024
The Arduino Platform Specification requires that the recipe hooks are
distinguished by a number and does not endorse using text labels. Fix
all the usages of recipe hooks to use numbers.

Closes arduino/arduino-cli#2369 .
pillo79 added a commit to pillo79/arduino-esp32 that referenced this issue Feb 7, 2024
The Arduino Platform Specification requires that the recipe hooks are
distinguished by a number and does not endorse using text labels. Fix
all the usages of recipe hooks to use numbers.

Closes arduino/arduino-cli#2369 .
me-no-dev pushed a commit to espressif/arduino-esp32 that referenced this issue Feb 7, 2024
The Arduino Platform Specification requires that the recipe hooks are
distinguished by a number and does not endorse using text labels. Fix
all the usages of recipe hooks to use numbers.

Closes arduino/arduino-cli#2369 .
me-no-dev pushed a commit to espressif/arduino-esp32 that referenced this issue Feb 7, 2024
The Arduino Platform Specification requires that the recipe hooks are
distinguished by a number and does not endorse using text labels. Fix
all the usages of recipe hooks to use numbers.

Closes arduino/arduino-cli#2369 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants