Skip to content

postobjcopy patterns on macOS fail with spaces in build path #1281

Description

@kieraneglin

Details

Hey there! Thank you for your work on this repo. I ran into an issue when trying to compile for an ATTiny 1616. After some sleuthing, here's my best guess as to what's going on:

On macOS, the recipe.hooks.objcopy.postobjcopy patterns in platform.txt wrap commands in bash -c "..." but leave the .elf and output file paths unquoted inside the string. When the build path contains spaces (e.g. a project inside ~/Foo Bar/), the shell splits the path on whitespace and avr-objdump/avr-nm fail with No such file or directory.

From what I can tell, the Windows pattern already quotes paths correctly using "...". The macOS and Linux patterns do not.

Steps to reproduce:

NOTE: this does not impact compilation from Arduino studio. This only seems to come into effect when called from the CLI like arduino-cli compile --profile ATtiny1616 -v --jobs 0 --build-path <path>. I'm actually not doing this directly, but an IDE extension I'm using does call the CLI in this manner for whatever reason.

  • Install megaTinyCore:megaavr 2.6.12
  • Use megaTinyCore with any sketch whose build path contains spaces
  • Compile via the CLI. the core files build successfully but the post-build step fails with exit status 1
  • Verbose output shows: avr-objdump-related no such file errors
  • See the script reports Error during build: exit status 1

Potential fix

I've applied this fix locally and it seems to work but this is far from my area of expertise:

(platform.txt, lines 129–130, 134–135):

-recipe.hooks.objcopy.postobjcopy.1.pattern.linux=bash -c "{compiler.path}{compiler.objdump.cmd} {compiler.objdump.flags} {build.path}/{build.project_name}.elf > {build.path}/{build.project_name}.lst"
-recipe.hooks.objcopy.postobjcopy.1.pattern.macosx=bash -c "{compiler.path}{compiler.objdump.cmd} {compiler.objdump.flags} {build.path}/{build.project_name}.elf > {build.path}/{build.project_name}.lst"
+recipe.hooks.objcopy.postobjcopy.1.pattern.linux=bash -c '{compiler.path}{compiler.objdump.cmd} {compiler.objdump.flags} "{build.path}/{build.project_name}.elf" > "{build.path}/{build.project_name}.lst"'
+recipe.hooks.objcopy.postobjcopy.1.pattern.macosx=bash -c '{compiler.path}{compiler.objdump.cmd} {compiler.objdump.flags} "{build.path}/{build.project_name}.elf" > "{build.path}/{build.project_name}.lst"'

-recipe.hooks.objcopy.postobjcopy.2.pattern.linux=bash -c "{compiler.path}{compiler.nm.cmd} {compiler.nm.flags}  {build.path}/{build.project_name}.elf > {build.path}/{build.project_name}.map"
-recipe.hooks.objcopy.postobjcopy.2.pattern.macosx=bash -c "{compiler.path}{compiler.nm.cmd} {compiler.nm.flags}  {build.path}/{build.project_name}.elf > {build.path}/{build.project_name}.map"
+recipe.hooks.objcopy.postobjcopy.2.pattern.linux=bash -c '{compiler.path}{compiler.nm.cmd} {compiler.nm.flags} "{build.path}/{build.project_name}.elf" > "{build.path}/{build.project_name}.map"'
+recipe.hooks.objcopy.postobjcopy.2.pattern.macosx=bash -c '{compiler.path}{compiler.nm.cmd} {compiler.nm.flags} "{build.path}/{build.project_name}.elf" > "{build.path}/{build.project_name}.map"'

The fix switches the outer bash -c delimiter to single quotes (so the inner double quotes are passed literally to the shell rather than being interpreted by arduino-cli's template expansion), and applies the same fix to Linux since it has the identical bug.


If that passes the sniff test, please let me know and I'll open a PR!

Thanks again

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions