5

I use the following script to run XCode (7.0.1 7A1001) on OSX Yosemite 10.10.5:

export FOO=bar #this should not be necessary, but just in case
launchctl setenv FOO bar #should make it visible to all GUI applications (=XCode)
open -a xcode

I then open a workspace with two projects: App1 and App2. In both projects I put $(HOME)/$(FOO) in the Header Search Paths field.

  • In App1 it is resolved to /Users/ohads/bar as expected.
  • In App2 it is resolved to /Users/ohads/ - note how the HOME variable is resolved, but the FOO variable is not.

What's going on here? Why the discrepancy? How can I make FOO work in App2 - is there some special flag or declaration I'm missing?

BTW, as if that's not weird enough, App1 works even when I only use export (as opposed to launchctl which is what one should use for GUI applications, seeing as export should only affect cash applications).

Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198
  • Hi! What version of OSX you are using? – Laser Oct 20 '15 at 11:56
  • @Arseniy added to question – Ohad Schneider Oct 20 '15 at 11:57
  • Are you sure you don't have `FOO` defined somewhere in the App2 settings ? – Paul R Oct 20 '15 at 12:00
  • `launchctl setenv` should work, however I don't see why you cannot use paths relative to the Xcode project and just ensure the Xcode project is in the right place? Using an environment variable in this way, actually makes your process harder. – trojanfoe Oct 20 '15 at 12:02
  • Pretty sure, because in my actual case FOO is dependent on the current directory, and I can see the change reflected when I open XCode from a different folder. – Ohad Schneider Oct 20 '15 at 12:02
  • @trojanfoe we are using xcconfig files that are common to many projects so that won't work. And even if it did, I'm not going to change our entire build configuration at this point (I wasn't the one who created it, FWIW). Besides, like you said `launchctl` should have worked, so what am I missing? – Ohad Schneider Oct 20 '15 at 12:04
  • Well that's fair enough. – trojanfoe Oct 20 '15 at 12:12
  • 2
    The `export` should be sufficient, since `open -a xcode` opens the GUI app from within a `bash` session. GUI apps that are opened from the Finder, which is not started from a `bash` session, are the ones who need `launchctl`. (Unless `open` does not fork/exec the process, instead sending a message to the OS to open the app, in which case this comment is irrelevant.) – chepner Oct 20 '15 at 12:55
  • @chepner thanks for clarifying, but regardless, it doesn't work. However I believe I did find the solution, will add an answer. – Ohad Schneider Oct 20 '15 at 13:02

1 Answers1

13

Looks like this has to do with new XCode 7 behavior. In order for XCode to use environment variables the following command must be issued:

$ defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO

Once this command is issued, both export and launchctl work (as per chepner's comment). I can only guess it was working in App1 because it was created in an older XCode version.

Community
  • 1
  • 1
Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198