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

Fixing is_clang wrongly returning false on macOS #67

Closed
wants to merge 2 commits into from
Closed

Fixing is_clang wrongly returning false on macOS #67

wants to merge 2 commits into from

Conversation

heybdj
Copy link
Contributor

@heybdj heybdj commented May 21, 2020

is_clang returns ‘false’ if cc() returns a full path to the clang executable (e.g., CC=$(xcrun --find clang), causing the driver function cc() to return “/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang”).

This fix does the same comparison as before, but on the token at the end of the full path.

is_clang returns ‘false’ if cc() returns a full path to the clang executable (e.g., CC=$(xcrun --find clang), causing the driver function cc() to return “/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang”).

This fix does the same comparison as before, but on the token at the end of the full path.
@SanderMertens
Copy link
Owner

Ah, could you modify the PR so that it uses strrchr? That way you don't need the loop / malloc. Works like this:

char *ptr = strrchr(cc, UT_OS_PS); // ptr now points to the last occurrence of / or \

Removes unneccesary loop and malloc. Currently assumes that path separator is a single byte in size.

Tested against the following strings:

```c
const char *test_strings[22] = {
    "clang",
    "clang ",
    " clang ",
    "./clang",
    ".\\clang",
    "clang++",
    "clang++ ",
    " clang++ ",
    "./clang++",
    ".\\clang++",
    "/clang/",
    "/clang++/",
    "\\clang++\\",
    "clang/gcc",
    "clang/g++",
    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang",
    " ",
    "",
    "\\",
    "/",
    NULL,
    "\0"
};
```
@heybdj
Copy link
Contributor Author

heybdj commented May 27, 2020

Ooh, yes, that's great! I pushed an update 🙂 Thanks for checking, @SanderMertens!

@SanderMertens SanderMertens force-pushed the master branch 2 times, most recently from 25afe73 to 44374c9 Compare July 17, 2020 05:52
@SanderMertens
Copy link
Owner

I just merged your change with master (not sure why it's not showing up here). I tweaked it a little bit so that your fix can be used for all compilers. Thanks again!

(and sorry again for being so late- not sure if "late" even covers it anymore :p)

@SanderMertens
Copy link
Owner

For ref, this is what the code looks like now: https://github.com/SanderMertens/bake/blob/master/drivers/lang/c/src/gcc/driver.c#L73

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