Skip to content

Fix relaunching scancode on Apple silicon using Rosetta 2 emulation #2835 - #3018

Merged
pombredanne merged 3 commits into
aboutcode-org:developfrom
MarcelBochtler:mac-arm64
Jul 11, 2022
Merged

Fix relaunching scancode on Apple silicon using Rosetta 2 emulation #2835#3018
pombredanne merged 3 commits into
aboutcode-org:developfrom
MarcelBochtler:mac-arm64

Conversation

@MarcelBochtler

@MarcelBochtler MarcelBochtler commented Jul 9, 2022

Copy link
Copy Markdown
Contributor

Related to #2835.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁

Running `uname -m` on Apple silicon machines always results in `arm64`,
regardless if Bash is running in Rosetta 2 emulation or natively.
Check if scancode and configure is running in emulation mode (see [1]),
before relaunching it, to avoid an infinite loop.

[1]: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment

Signed-off-by: Marcel Bochtler <git@bochtler.io>
Calling `bash -c` with `$@` results in only the first parameter being
passed to the subshell. Use `$*` to ensure all parameters are correctly
passed to the Rosetta 2 emulated subshell.

Signed-off-by: Marcel Bochtler <git@bochtler.io>
@MarcelBochtler MarcelBochtler changed the title Fix relaunching scancode on Apple silicon using Rosetta 2 emulation Fix relaunching scancode on Apple silicon using Rosetta 2 emulation #2835 Jul 9, 2022

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcelBochtler Thank you ++ for testing and fixing this.... you are awesome!

This commit carries over a patch applied to the scancode and configure
scripts to ensure that extractcode can work correctly in X86 emulated
mode on Apple ARM silicon,

* Only relaunch extractcode when not in emulation mode
Running `uname -m` on Apple silicon machines always results in `arm64`,
regardless if Bash is running in Rosetta 2 emulation or natively. Check
if extractcode is running in emulation mode (see [1]), before
relaunching it, to avoid an infinite loop.

*Pass all parameters to the relaunched shell
Calling `bash -c` with `$@` results in only the first parameter being
passed to the subshell. Use `$*` to ensure all parameters are correctly
passed to the Rosetta 2 emulated subshell.

[1]: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment

Reported-by: Marcel Bochtler <git@bochtler.io>
Authored-by: Marcel Bochtler <git@bochtler.io>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne

Copy link
Copy Markdown
Member

@MarcelBochtler I carried over your patch to the extractcode script too... And I will merge shortly.
Thank you ++ again 🙇

@pombredanne

Copy link
Copy Markdown
Member

Thanks!
Merging

@pombredanne
pombredanne merged commit 8689bc7 into aboutcode-org:develop Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants