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.
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 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'm working on a project in Xamarin.iOS, and it happens to go through a build server (running on a Mac).
The build seems to commonly fail, but even with the --verbose or -v it seems to Silently fail. For example, right now, it seems to fail after optimizing the graphics for iOS. The last line of the build says Build complete -- 0 errors, 0 warnings. But then I get a Build step 'Execute shell' marked build as failure from Jenkins. I know that this is a failure in the mdtool build, because I have had a successful build before, and I know there are several more steps before it actually succeeds.
The next step in the successful process should be Compiling to native code, but for some reason it fails before getting to that, or at least outputting it to the console.
Thanks in advance for the help!
There's a few places in the mdtool build logic that didn't properly catch exceptions when executing shell programs which I (hopefully) fixed for Xamarin Studio 4.0.2.
Without seeing the full build log it's hard to say for sure, but it might be that whatever shell command that it is trying to execute either doesn't exist or isn't marked with execute permissions.
The programs that I can think of off the top of my head that mdtool will invoke for the iOS builds are:
pngcrush (optimizes .png files)
plutil (optimizes .plist and .strings files)
codesign (although this one gets called after compiling to native code)
and of course, mtouch which is what is used to compile IL to native code. The mtouch command is part of Xamarin.iOS while the other 3 utilities are part of Mac OS X (or Xcode).
The solution for the other person with a similar problem that I helped debug a week or 2 ago was because he had modified his PATH environment that launchd launched apps with to not include /usr/bin and so mdtool couldn't find the utility programs listed above.
I'm not very familiar with Jenkins (I know we use it at Xamarin, but I'm not part of the team that does), so make sure that the PATH environment that it launches mdtool under is setup to include /usr/bin.
Hope that helps.
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)?