Skip to content
  • Sponsor arduino/arduino-cli

  • Notifications You must be signed in to change notification settings
  • Fork 411

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

Closed
espressif/arduino-esp32
#9220
@ArminJo

Description

@ArminJo

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

Activity

assigned and unassigned on Oct 27, 2023
per1234

per1234 commented on Oct 27, 2023

@per1234
Contributor

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.

added
topic: codeRelated to content of the project itself
and removed
type: imperfectionPerceived defect in any part of project
on Oct 27, 2023
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[/+] on Oct 27, 2023
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[/+] on Oct 27, 2023
ArminJo

ArminJo commented on Oct 27, 2023

@ArminJo
Author

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

added a commit that references this issue on Feb 7, 2024
2f96dcf

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Hooks are recognized even when pattern property name uses string key in place of numeric index · Issue #2369 · arduino/arduino-cli