Adding external scripts to Xcode4 - xcode

I need to do some tasks before any Archive launched in Xcode.
Is there any way in Xcode to add a .sh or .py script run before Archive ?
PS : I can complete these tasks by hand but it requires time, some tasks might be forgotten or if the process is done by someone else all the tasks can be forgotten. The problem is that these tasks are required to have a successfull Apple validation.
Thanks

You can add script build phases at any point between the existing phases. Here is a post which shows you how. In Xcode 4 you select your project, then go to the build phases tab were you usually have the "target dependencies", "compile sources", "Link binary with libraries" and "copy bundle resources" phases, just click on "Add build phase" and select "Add run script". You can select your shell, but not script in python from there.
You can also look at building xcode projects from the command line. You could call that command line from a python script and do anything else you want from "outside" the Xcode project.

Related

How to build command line utility

I have a framework that includes a command line utility. This application is called by third party applications to perform certain tasks. There is no way I can go around not having this utility.
I've written the code and added the .m file to my project. I created a new target for it of the Core Foundation type. I added the right files to the Compile Sources section under Build Phases. But for some reason, Xcode doesn't build my utility. Whenever I build the framework and expand the Products group, the command line utility is left red.
How do I force Xcode to build it?
Don't sure if I understand you correctly.You have a framework with utility and you want to include that utility to your boundary? Than you probably need to add that utility to "Copy Files" section of "Build Phases"
Or you want to build utility in your project?
Than you probably need to add "Command line tool" target to your project.
Edit: To link two targets just add dependcy target to the "Target Dependencies" section of "Build Phases" of the main target.

Copy iOS App bundle to another folder during Xcode build

I would like to copy the contents of my iOS App Bundle to a particular directory during the Xcode build stage. Can anyone tell me how to do that?
A solution using a script in "Build Phases" does not work properly since Xcode is not finished building the app when running the script. Here is a solution with a script that runs after all build tasks are finished:
Go to "Edit Scheme"
Click on the triangle next to "Build"
Select "Post-action"
Press the + button and select "New Run Script Option"
Select your app name in "Provide build settings from"
Add the following shell script:
Script:
PRODUCT="${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app"
cp -R "${PRODUCT}" ~/Desktop

Xcode Run script Build Phase "run script only when installing" option

There is a "run script only when installing" option in Xcode Run script Build Phase, I am not able to find documentation on this. What does it do?
With Run script only when installing checked, the script only runs when do Product Archive.
In the Xcode Build System Guide (Xcode 3.2.x), it says:
Run script only when installing. Runs the script only during install builds, that is, when using the install option of xcodebuild or when the build settings Deployment Location (DEPLOYMENT_LOCATION) and Deployment Postprocessing (DEPLOYMENT_POSTPROCESSING) are on.

Run a bash script in Xcode only when "Build & Run"

Is there a way, in Xcode, to run a bash script in a build phase, only when I "Build & Run" and not in all other occasions?
Actually, what I would like to do, is to write a script to update the build number every time I build and run a new version on the device.
Xcode does not tell your script why it's building — that is, if it's going to run the app afterwards or not —; only that it is building. Also note that selecting 'Run' as opposed to 'Build & Run' does not run scripts in Run Script phases.
If you build in other occasions, you can pass build settings to xcodebuild (if building from the command line) or by selecting a different build configuration (if building from the Xcode application), which you can refer to in your build scripts as environment variables. For example:
if [ "$CONFIGURATION" == "Debug" ]; then
# increment build number
fi
(This script uses the CONFIGURATION built-in build setting, but you can create custom build settings if needed.)

How to run an xcode project from bash?

I have a build script calling xcodebuild. that works, but I want to also run the project from bash as well. Effectively I want to negate the need to click "Build and Run" button from the GUI. I'm looking at xcrun but it's not too obvious to me what to do
It sounds like you want to run the product of the build, not the project itself. If you want to do that, you just need to use the bash invocation for the product. If you're building a command-line program, then there will be an executable with the product's name in the project's built products directory after a succesful build. The project's built products directory depends on your preferences for Xcode and the project, but can be determined from the $BUILT_PRODUCTS_DIR environment variable within an Xcode build phase.
I do this for one of my projects in a shell script. It let's me remotely build over SSH.
xcodebuild clean
xcodebuild
cp -rp ~/Projects/VSM/Mac/iCar/build/Release/iCar.app ~/Desktop/
open ~/Desktop/iCar.app
I chose to copy the app to the Desktop on purpose but you wouldn't have to.
try open xcode

Resources