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

shims/super/cc: handle double dash in args #19082

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

alebcay
Copy link
Member

@alebcay alebcay commented Jan 12, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

The cc shim currently does not handle invocations where -- is passed as an argument, which (conventionally) indicates that all following arguments be treated as positional (non-optional) arguments. As a result, any refurbished args may get appended after the -- where they are erroneously treated as input file paths:

clang: error: no such file or directory: '-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk'
clang: error: no such file or directory: '--sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk'; did you mean '--sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk'?
clang: error: no such file or directory: '-isystem/opt/homebrew/include'
clang: error: no such file or directory: '-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers'
clang: error: no such file or directory: '-L/opt/homebrew/lib'
clang: error: no such file or directory: '-L/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries'
clang: error: no such file or directory: '-Wl,-headerpad_max_install_names'

This kind of error was encountered in the wild in some core PRs, e.g. Homebrew/homebrew-core#203929, Homebrew/homebrew-core#203934, Homebrew/homebrew-core#203932, Homebrew/homebrew-core#203944.

This pull request ensures that any modifications to the arguments are applied before the -- (if -- is present).

Before:

clang called with: -- test.c
superenv added:    -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk -isystem/opt/homebrew/include -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names
superenv executed: clang -- test.c -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk -isystem/opt/homebrew/include -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names

After:

clang called with: -- test.c
superenv added:    -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk -isystem/opt/homebrew/include -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names
superenv executed: clang -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk -isystem/opt/homebrew/include -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names -- test.c

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Thanks; nice work!

Library/Homebrew/shims/super/cc Outdated Show resolved Hide resolved
@alebcay alebcay force-pushed the cc-handle-double-dash branch from 3171a64 to 1ec8a04 Compare January 12, 2025 19:49
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jan 13, 2025
Merged via the queue into Homebrew:master with commit 880bfb5 Jan 13, 2025
28 checks passed
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.

3 participants