Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access Xcode environment (and build) variables from an external script?

I am writing a script to automate my iOS building. It will be run outside of Xcode, either via Terminal or from build automating software. Is there any way to have access to Xcode environment variables in my script, so I don't have to try and derive them myself?

For example, can I get access to PROJECT_DIR instead of assuming I'm in the current directory and running pwd?

I am currently hardcoding the product names for my different build configurations. (I'm also hard coding the build configs, but I could parse them them from xcodebuild -list.) Is there a way to get the app if you know the build config name?

(I saw this related question but it doesn't have an answer for me.)

like image 301
zekel Avatar asked Feb 03 '23 16:02

zekel


1 Answers

The Xcode environment variables are only defined for child processes of the xcodebuildcommand-line tool.

One solution I used is to have a very simple script as part of my build process (Project->New Build Phase->Add Run Script Build Phase). All this script does is export the necessary variables and call a script in my path somewhere.

That script could be generated by your build script before calling xcodebuild and voilà! you have an external script that has access to Xcode build variables.

like image 56
Philippe Avatar answered Feb 13 '23 06:02

Philippe