Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcodebuild failing to pick up environment values from project file?

I'm using Xcode 3.2.6, MacOSX.

I have a globally visible environment setting:

ICU_SRC=~/Documents/icu/source

This really is an environment setting, it's set at login time. When I open up Terminal, it's there.

In my project, under Header Search Paths I've added this:

$(ICU_SRC)/i18n
$(ICU_SRC)/common

These expand correctly when I compile inside the IDE. When I look at the build results, I see this:

-I/Users/eric.grunin/Documents/icu/source/i18n
-I/Users/eric.grunin/Documents/icu/source/common

When I build from the command line, however, it fails. What I see is this:

-I/i18n
-I/common

Here's the command I'm using to compile:

/usr/bin/env -i xcodebuild -project my_project.xcodeproj -target "my_program" -configuration Release -sdk macosx10.6 build

What am I doing wrong?

Edited to add:

Apple explains Setting environment variables for user processes

like image 335
egrunin Avatar asked Nov 23 '25 14:11

egrunin


2 Answers

Sometimes it works better if you specify the env vars before the xcodebuild command, as in

# NOT this
xcodebuild ... options ... SOMEVAR=somevalue

# But this instead works better
SOMEVAR=somevalue xcodebuild ... options ...

This works especially well for PRODUCT_NAME when working with cocoapods.

like image 179
Joel Avatar answered Nov 27 '25 22:11

Joel


You need to "connect" xcode build to Xcode using your scheme.

From xcodebuild side : xcodebuild ... options ... yourVAR=yourValue

From Xcode -> Product -> Scheme -> Edit Scheme... -> Arguments -> Environment Variables (name) someKey (Value) $yourVAR

The key is that the name of yourVAR in xcodebuild will be referred from Xcode arguments, by using '$'.

In order to access the environment variable later from code, you need to use

ProcessInfo.processInfo.environment["someKey"]

Xcode Environment Variables from your Scheme

like image 44
Z. Ziv Avatar answered Nov 27 '25 21:11

Z. Ziv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!