Re: How To Run Terminal.app from Xcode
Re: How To Run Terminal.app from Xcode
- Subject: Re: How To Run Terminal.app from Xcode
- From: Andreas Grosam <email@hidden>
- Date: Thu, 03 Nov 2011 21:13:40 +0100
Thank you very much Bayes and Ken!
I've set DYLD_FRAMEWORK_PATH with launchctl setenv - but new shells will not inherit this variable - as opposed to any other random variable.
I've now set DYLD_FRAMEWORK_PATH in my .profile. This seems to work (re-login required) (although I would prefer a less intrusive solution).
Then, the script in the Xcode Post-action would be become quite simple, though:
open -a Terminal.app ${BUILT_PRODUCTS_DIR}/AllTests
This would work, but there is one remaining issue: I need to set the current working directory for the running executable to ${BUILT_PRODUCTS_DIR}. This seems to be easier than it actually is. But I can't just create a script:
cd ${BUILT_PRODUCTS_DIR}
./AllTests
and then in Xcode's Post-action:
open -a Terminal.app theScript
since then no Xcode build settings are available in the script.
I could ask the args in the main function and determine the path from argv[0] and then set the working directory with a platform specific function. But I would prefer a simpler solution.
Any further ideas?
Andreas
On Nov 3, 2011, at 5:56 PM, Ken Thomases wrote:
> On Nov 3, 2011, at 10:51 AM, Andreas Grosam wrote:
>
>> My unit test app runs as a console program. In order to run, it requires an environment variable set:
>> DYLD_FRAMEWORK_PATH=<path/to/library>
>
>> Well, now to streamline my workflow I would like to run the unit test directly after the build phase in Terminal.app. My attempts to setup the a "Post-action" in the Build section in the Scheme editor so far failed. The Terminal.app will be launched which a new window starting the required executable, but the environment variable DYLD_FRAMEWORK_PATH is not set. So,I get a dynamic linker error at runtime
>
>> The bash script looks as follows:
>>
>> export DYLD_FRAMEWORK_PATH=/Users/path/to/library
>> cd ${BUILT_PRODUCTS_DIR}
>> open -a Terminal.app AllTests
>>
>> This above also fails when launched from within Terminal. It seems, the environment variables will not be inherited.
>
> First, this only _launches_ Terminal.app if it wasn't already running. If it launches it, then Terminal.app does inherit the environment variable. If Terminal was already running, then the above doesn't affect Terminal's environment. Either way, though, the shells which are running within Terminal's windows initialize fresh environments and then sets then up using /etc/profile and the like. So, the shells effectively never inherit the environment of the Terminal process itself.
>
>
>> So, how can I launch Terminal with proper environment variables set - or get this to work by other means?
>
> You can have Terminal launch a shell which first sets the environment variable and then runs your test program. Or, you can use AppleScript to open a new Terminal window and issue individual commands to it. In that way, you can issue one command to set the environment variable and another to run the test program.
>
> Regards,
> Ken
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden