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.
Related
I am writing a swift CLI app, and am doing acceptance testing on it using Bats (Bash Automated Testing System). I have an "external build tool" target that invokes bats from a shell script. This target declares dependencies on a few CLI app executable targets (including my main app). Then I have a scheme that builds the Bats target and also runs an XCTest target.
I haven't been able to consistently guarantee that the executable dependencies finish building completely before the Bats script is invoked. Whether I declare my scheme as parallelizable or not, I will inconsistently run into issues where the Bats script is invoked, but it can't find one of the executables it depends on since it hasn't yet been added to $TARGET_BUILD_DIR.
From the build logs, I can always see that the needed executable target has finished compiling, but when the issue occurs, the target is conspicuously missing completed steps for Link <executable>, Sign <executable>, and Register execution policy exception for <executable>.
My best interpretation of the problem is that Xcode releases locks for the target with the dependencies only once all dependencies have finished compiling, and not necessarily when the builds for those targets have completed fully.
The most reliable workaround I have found is to sleep 1 in my shell script before invoking Bats. I also tried putting an aggregate target in between my external build tool target and the dependencies, but this didn't work reliably. Is there a way to have Xcode delay execution of the external build tool until the build of the dependent targets has fully completed?
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 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.
I have an XCode project which I would like to add source files to via scripting.
Is it possible to add compile sources via a run script build phase?
If so, how would I go about this?
I haven't found any documentation or examples of this, so I'm not sure it's possible.
You can create target that runs script. In this script any sources could be passed to xcodebuild arguments.
If this is not what is needed, XCode project by itself is an xml, so any files could be added to any targets, but project should be reloaded after, so I don't know how to add files to target withing runnign this target build.
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.