`postobjcopy` patterns on macOS fail with spaces in build path

Open Beginner friendly
#1,281 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
bash
Domain
build-system, cli

Research direction

Start in platform.txt at the recipe.hooks.objcopy.postobjcopy patterns around lines 129–135 and compare the Linux and macOS commands with the Windows quoting. Reproduce an arduino-cli compile using a build path containing spaces, then verify the post-build avr-objdump and avr-nm steps complete successfully on the affected platforms.

Written by the indexing model from the issue text.

Description

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

Dominant language
C
Stars
681
Forks
161
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SpenceKonde/megaTinyCore

All issues in SpenceKonde/megaTinyCore

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.