-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#1148 - Add CARTHAGE_PATH env var with executable path #1154
Conversation
The resulting |
Isn't this almost same as #1151 ? |
Yes it is—except this aims to make the value the path to carthage, instead of just a simple |
The second point in the description is the main reason for preferring this over |
👍 @auibrian, I like the idea of having the I guess, instead of two vars, we can just have one variable |
Done. I've made it so that it will set |
@@ -84,6 +84,11 @@ public struct BuildArguments { | |||
args += [ "BITCODE_GENERATION_MODE=\(bitcodeGenerationMode.rawValue)" ] | |||
} | |||
|
|||
if let carthagePath = NSBundle.mainBundle().executablePath | |||
where NSBundle.mainBundle().executableURL?.lastPathComponent?.lowercaseString.rangeOfString("carthage") != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you fetching the path twice here via two different properties? Also, calling lowercaseString
is unnecessary work when you can just do a case-insensitive compare, and using rangeOfString()
seems incorrect because it'll also trigger on a tool named thisIsNotCarthage
or somesuch. I'd recommend something like
if let executableURL = NSBundle.mainBundle().executableURL
where executableURL.lastPathComponent?.caseInsensitiveCompare("carthage") == .OrderedSame,
let executablePath = executableURL.path {
args += [ "CARTHAGE_PATH=\(carthagePath)" ]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I truly don't remember my thinking in changing to use executablePath
as well as executableURL
, that should be fixed.
The use of lowercaseString
is directly a result of using rangeOfString()
and the reason for that was an explicit desire to catch the use of any binary with carthage
in the name. I was envisioning the binary names being carthage_0.14
or along those lines. Matching against a tool named thisIsNotCarthage
would be an undesirable effect of course. I could conceivably use a proper regex to make sure carthage
only featured at the beginning of the string but then someone might name the binary carthageIsNotThisTool
.
I'm not really sure if it is preferable to only catch the canonical name carthage
or to allow a bit of leeway in case users rename their binaries. If it doesn't end up only working for carthage
I will update it to use localizedStandardContainsString()
rather than lowerCaseString.rangeOfString()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localizedStandardContainsString()
would be a weird thing to use here. This is an executable name, not a localized string, and the user's current selected locale should not in any way affect whether the executable is considered to be Carthage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, lowercaseString.containsString()
it is, assuming we want to allow for the renaming of the binary at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's still unnecessary work. Why construct a new lowercase string when it's trivial to just do a lowercase compare? I still disagree about doing rangeOfString
, because people don't typically rename executables, but if you really want to, then you can use rangeOfString("carthage", options: [.CaseInsensitiveSearch]) != nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was around people who had multiple versions installed, maybe a beta and a release version. If it's not considered helpful I can make the check just for carthage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you even do that? The carthage
binary relies on CarthageKit.framework, which is installed in /Library/Frameworks. I don't see how you can possibly have multiple versions of Carthage installed unless you put them in different directories with a copy of CarthageKit.framework in the same directory (that's the only way to get it to load a different version of CarthageKit.framework than the one in /Library/Frameworks). And if they're in different directories then there's no reason to rename the executable.
I've merged #1151 so that the I'd like to also make this environment variable available—but I'd like to make it part of Would you be willing to update the PR to do that? |
No problem, I'll look into it. |
@auibrian Are you still interested in updating this PR? |
I am, I'll update it in the next few days. Thanks! |
Rather than having CARTHAGE_PATH set in CarthageKit, have it set in the carthage binary.
68164b4
to
e606c3b
Compare
@mdiep Alright, this is ready to go now. Sorry for the delay. |
Thanks again for the PR! |
- Use `NSBundle.executablePath` over `executableURL?.path` - Pass `carthagePath` directly to `setenv` - Add a missing space before comma
- Use `NSBundle.executablePath` over `executableURL?.path` - Pass `carthagePath` directly to `setenv` - Add a missing space after comma
Per @schwa's request (#1148) and @kballard's idea this adds a $CARTHAGE environment variable which is set to the path of the currently running carthage executable so that the build can: