I need to run a custom shell script on the clean step in Xcode (Xcode 9 to be exact). I have a set of makefiles that build my dependencies, initially I was calling this script in the run script phase, but then the outputs of these makefiles never get cleaned. So I though that if I handled the Xcode environemnt variable ${ACTION} in this script then it could also clean them. The issue is - the script is not called on clean.
There were several posts regarding this so here is what I've tried:
Making an additional aggregate target. I added the target and put a script that handles ${ACTION} from the build environment, but that script is never executed upon clean. When cleaning there is only a Clean.remove clean line in build log.
Making an external build system target (some older posts stated an external script target, but I could not find that in Xcode 9). This then allows me to execute a custom script (if I replace the default /usr/bin/make command to my script), but in this case the ${ACTION} environment variable is not set (I verified this in the build output, it always has export ACTION= in it), thus I cannot distinguish between clean and build phases.
Regarding the aggregate target, it has the output files property, if I specify them - could that make Xcode clean them?
A bit of a zombie, but closest to the issue that I am seeing. This appears to be a bug in the new build system. Using the old build system, the action is set. Two options here:
Use the Legacy build system.
Use separate external targets that call your script and manually pass the action parameter required and swap schemes manually as needed.
Related
In xcode 10.2, there is a run-script build phase. I have a script to copy a framework to a specific pod in DerivedData/somename-someguid/products/etc...
However, it seems that the script is not running first based on the print statements and it fails to find the file. If I manually copy the file there first, I can see the output of my script in the build log and it succeeds.
I tried dragging it up in the build-phase panel. I also tried adding it to the copy-file section, but copy does not understand how to embed with the correct pod.
Is there a way to specify the order of running these scripts? Is there a pre-everything section I don't know about?
Of course, it turns out I had the run script phase on the main app project instead of the pod project targets not realizing it built the pods first. So adding it there fixes it. Saving other noobs from this mistake by leaving the question up....
I am trying to build the facebook-ios-sdk as part of my project build phases.
In short, the script checks for the build folder, and if it does not exist runs scripts/build_framework.sh
When executing the build phase script I get the following error:
Check dependencies [BEROR]CodeSign error: code signing is required for
product type 'Static Library' in SDK 'Simulator - iOS 6.0'
The build works as expected when running from the terminal.
The closest SO answer I saw was this, but it appears to be for an older version, and the link to the tutorial provided is no longer valid.
XCode is setting a lot of environment variables, and these must be interfering with the script. If you knew which environment variables were the culprit, you could clear them before running your script, but there are dozens and I didn't want to spend the time figuring that out.
Instead, I decided to run the script without XCODE's environment variables. If you run the script this way, you will only get the PATH environment variable in your new shell. This seems to fix things for me:
env -i PATH=$PATH ./Submodules/facebook-ios-sdk/scripts/build_framework.sh
I can't seem to get Xcode 4 to reliably execute my pre-actions. I've tried cleaning and rebuilding. It doesn't seem to do it consistently. Is it even trying? I can't tell. I've put some echos in it (it's a bash script) and nothing is happening. This all worked in Xcode 3.
Note that your pre-build actions are not executed in your project's source directory. They are executed somewhere in Library/Developer/XCode/DerivedData/.
If you want to play with files in your project's source directory before compilation, you need to prepend it with ${PROJECT_DIR}/.
You need to add a "Run Script" to your build phases, and then drag it's position above the compile sources build phase.
I don't understand the purpose of a "pre-action" yet, doesn't seem to even get executed. However in my case I just needed a script to execute before my sources were compiled.
Remember that pre-actions do not pick up env variables. They are primarily meant to load or notify that the build is starting. If it worked in Xcode 3, you may want to use it more as a build script than a pre-action.
I currently have a project that I'm building with a makefile. This project includes some additional software (jflex) which is not on one of the default system search paths (it's installed to (/opt/local/bin/). My .profile file adds this directory to my PATH, and so building the project from a terminal window succeeds.
However, if I try to run the makefile from within XCode (XCode project with an externally managed makefile), it fails since it's not looking in /opt/local/bin for jflex, and as such can't find it.
How can I change the settings of my XCode project to correctly build from within XCode? I assume there's some kind of path setting in XCode, or some kind of additional argument I can have XCode give to make so that it doesn't fail. Alternately, I could hardcode the path into my makefile if I could detect that it was being run from XCode (although this is the less preferable option for me, since my makefile will sometimes need to be called from the command line and I'd rather keep it simple).
I'm relatively new to using XCode, so apologies if I've missed something obvious.
Instead of calling make directly, you could call a shell script as the "Build Tool" in the "External Build Tool Configuration" pane. Then modify the path in the shell script and call make from there, i.e.
#!/bin/sh
PATH=/opt/local/bin:$PATH
make
Don't forget to set permissions such that Xcode can run the script, and provide the full path to the script as the "Build Tool".
May not be the best way, But can you launch XCode from command line. It will inherit the Path from it.
Or, in the XCode launcher change:
XCode
to
PATH=$PATH:/opt/local/bin/ XCode
may work (depending on launcher)
Or, did you relaunch the launcher/window manager (logout and back in again after setting .profile)?
I have a custom script step in my build process that zips the executable. However this is executing before the executable is signed which is pretty useless.
Is there a way to zip the build output after the code is signed, within the Xcode build process. I can certainly do it externally if i need to, but I'd like to make it part of my Xcode build script.
Generally you'd create an Aggregate Target that first builds your main target, then runs a Run Script Build Phase to postprocess it.