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: remove isysroot space to fix cpp #6749

Merged
merged 1 commit into from
Nov 20, 2019

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Nov 16, 2019

  • 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 tests with your changes locally?

This is a fix to #5153, where the cpp shim was broken in Xcode 10 and later.

It turns out that Xcode's cpp is just a dumb script. Here's a snippet from it:

while [ $# -gt 0 ]
do
        A="$1"
        shift

        case "$A" in
        -nostdinc)
                NSI=yes
                ;;
        -traditional)
                ;;
        -I*)
                INCS=("${INCS[@]}" "$A")
                ;;
        -imacros|-include|-idirafter|-iprefix|-iwithprefix)
                INCS=("${INCS[@]}" "$A" "$1")
                shift
                ;;
        -*)
                OPTS=("${OPTS[@]}" "$A")
                ;;
        *)
                FOUNDFILES=yes
                # If we've found an input name and there's still an arg left,
                # that next arg will be the output file.
                if [ $# -eq 1 ]; then
                    OUTPUT="$1"
                    # and get rid of last arg
                    shift
                fi
                $CPP -traditional "${INCS[@]}" -x c "${OPTS[@]}" "$A" \
                     -o "$OUTPUT" || exit $?
                ;;
        esac
done

It splits arguments by spaces, and completely breaks down when we pass -isysroot sdk. The entire flow revolves around $#, $1 and shift which work by splitting by spaces so sees -isysroot and sdk as separate arguments. Here is a demonstration of what happens:

$ cpp -isysroot/A -isysroot/B test.ext
xcrun cc -E -traditional  -x c  -isysroot/A -isysroot/B test.ext -o -

$ cpp -isysroot /A -isysroot /B test.ext
xcrun cc -E -traditional  -x c  -isysroot /A -o -
xcrun cc -E -traditional  -x c  -isysroot -isysroot /B test.ext -o -

The script does have special handling for -imacros, -include, -idirafter, -iprefix and -iwithprefix to work with spaces (or rather require spaces), but not -isysroot.

When interacting with clang directly, -isysroot works both with and without spaces between -isysroot and the path. In fact, originally spaces weren't supported there either - that's a later innovation. MacPorts doesn't put a space after -isysroot for that reason, albeit that older toolchain support isn't a concern in Homebrew.

Considering -isysroot without spaces still works today, I propose removing the space as that fixes all the problems without having to do special cpp handling. Note that -isystem already behaves this way.

@maxim-belkin
Copy link
Contributor

maxim-belkin commented Nov 18, 2019

👍

-isysroot sdk is processed by the -*) option above. Therefore, one has to escape spaces between words that are part of the same "option" as is the case with -isysroot sdk. In the current syntax, both -isysroot and sdk are provided to cpp as separate words and, therefore, processed by cpp individually. So, unless there is more to it, the "fix" can still have a space between -isysroot and sdk, but these words have to be part of the same "option":

args << "-isysroot #{sysroot}"

@Bo98
Copy link
Member Author

Bo98 commented Nov 18, 2019

Indeed that should also work. Ruby will handle the rest.

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.

Works for me, thanks @Bo98 for another great PR!

@MikeMcQuaid MikeMcQuaid merged commit a123d90 into Homebrew:master Nov 20, 2019
@Bo98 Bo98 deleted the cpp-fix branch November 20, 2019 12:51
@lock lock bot added the outdated PR was locked due to age label Jan 1, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 1, 2020
@Bo98 Bo98 restored the cpp-fix branch February 26, 2020 09:24
@Bo98 Bo98 deleted the cpp-fix branch February 26, 2020 09:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants