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

#1148 - Add CARTHAGE_PATH env var with executable path #1154

Merged
merged 2 commits into from
Apr 8, 2016

Conversation

auibrian
Copy link
Contributor

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:

  • know it is running under carthage
  • call copy-frameworks, etc with the same version of carthage if desired.

@lilyball
Copy link
Contributor

The resulting $CARTHAGE variable contains the path to the directory containing carthage, not the path to carthage itself. That's not very useful.

@bhargavg
Copy link
Contributor

Isn't this almost same as #1151 ?

@mdiep
Copy link
Member

mdiep commented Feb 24, 2016

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 YES. Is there a reason why we should prefer this?

@auibrian
Copy link
Contributor Author

The second point in the description is the main reason for preferring this over YES: it would allow for run script phases to use the same carthage binary that the build was being exec'd by. I can split it out into something like CARTHAGE_PATH as well. I'm just updating it now to contain the path to carthage itself.

@bhargavg
Copy link
Contributor

👍 @auibrian, I like the idea of having the CARTHAGE_PATH available to build scripts.

I guess, instead of two vars, we can just have one variable CARTHAGE_PATH that will be set to path of carthage if installed, else, will not be set at all.

@auibrian
Copy link
Contributor Author

Done. I've made it so that it will set CARTHAGE_PATH if the binary name contains carthage at all.

@auibrian auibrian changed the title #1148 - Add CARTHAGE env var with executable path #1148 - Add CARTHAGE_PATH env var with executable path Feb 24, 2016
@@ -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 {
Copy link
Contributor

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)" ]
}

Copy link
Contributor Author

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().

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@mdiep
Copy link
Member

mdiep commented Feb 26, 2016

I've merged #1151 so that the CARTHAGE variable will be available when building with CarthageKit (which carthage uses).

I'd like to also make this environment variable available—but I'd like to make it part of carthage and not CarthageKit. I think we should be able to set the variable in main.swift. That will (1) allow us to get rid of the check to see if the executable name is carthage and (2) allow people to distinguish between carthage and another project that uses CarthageKit.

Would you be willing to update the PR to do that?

@auibrian
Copy link
Contributor Author

No problem, I'll look into it.

@mdiep
Copy link
Member

mdiep commented Mar 26, 2016

@auibrian Are you still interested in updating this PR?

@auibrian
Copy link
Contributor Author

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.
@auibrian
Copy link
Contributor Author

auibrian commented Apr 7, 2016

@mdiep Alright, this is ready to go now. Sorry for the delay.

@mdiep
Copy link
Member

mdiep commented Apr 8, 2016

Thanks again for the PR!

@mdiep mdiep merged commit fb66c70 into Carthage:master Apr 8, 2016
ikesyo added a commit that referenced this pull request Apr 8, 2016
- Use `NSBundle.executablePath` over `executableURL?.path`
- Pass `carthagePath` directly to `setenv`
- Add a missing space before comma
ikesyo added a commit that referenced this pull request Apr 8, 2016
- Use `NSBundle.executablePath` over `executableURL?.path`
- Pass `carthagePath` directly to `setenv`
- Add a missing space after comma
mdiep added a commit that referenced this pull request Apr 9, 2016
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.

4 participants