Variable for path to XCode's SharedPrecompiledHeaders folder - xcode

During our iOS client build we run a clean to prevent/reduce failures. But last week all our build servers failed with this error
fatal error: malformed or corrupted AST file: 'could not find file 'worspace/file_name.h' referenced by AST file'
It seemed that file_name.h was no longer required and a developer removed the svn external which brought it in. But the AST files still held a reference to it - despite the clean.
After investigating I found it was the files in the following folder
var/folders/f3/bznwl6md2bx82f1fv_kkdzl00000gn/C/com.apple.DeveloperTools/5.0.2-5A3005/Xcode/SharedPrecompiledHeaders
Deleting SharedPrecompiledHeaders fixed the issue. At the time I manually did this.
But I'd like a way to automate it. Is there an environmental variable/alternative that can be used to find this directory? I noticed it varies between machines.

The environment variable you are looking for is SHARED_PRECOMPS_DIR

The final solution was to place the shared precomps dir within the checkout. This allowed the build servers to completely clean the workspace between builds.
Achieved this by passing in the SHARED_PRECOMPS_DIR to xcodebuild.
e.g.
xcodebuild -project ProjectName -target "Target" -configuration Configuration -sdk SDKName SHARED_PRECOMPS_DIR=/absolute/path/to/checkout
By passing this value in at the command line the SHARED_PRECOMPS_DIR was set for all projects. i.e. Including Dependent Projects.

Lane's answer is correct. If you need to retrieve this value from the command line parse the output of
xcodebuild -project myProj.xcodeproj -target "myTarg" -showBuildSettings
For further details see How do I print a list of "Build Settings" in Xcode project?

Related

What is Xcode test build path?

In Xcode, pressing ⌘B (build target) can build the project, it will generate the build in the path ~/Library/Developer/Xcode/DerivedData/{AppName}-{hash}.
How could I know the whole path of the build (with the hash value) by a script? Can I find that path in my .xcodeproj?
When I use ⇧⌘U (build test target only), where can I find the test target build?
The build paths can be controlled using BUILT_PRODUCTS_DIR , PROJECT_TEMP_DIR , CONFIGURATION_BUILD_DIR and CONFIGURATION_TEMP_DIR etc . https://help.apple.com/xcode/mac/11.4/#/itcaec37c2a6
There's no need to extract them from some non-public file format specification.
If you must do it, init a temporary git repo with a xcodeproj file in it. Commit it. Make a change in one of the variables and then run git diff.
How could I know the whole path of the build (with the hash value) by a script?
Change to the same folder where your project or workspace is
Run xcodebuild -showBuildSettings
May need to add the proper scheme or target. See man xcodebuild
See sample below to find by script
When I ... build for test target only, where can I find the test target build?
It will be in the same folder with a name similar to <Test_Target_Name>-Runner.app. This is useful as you can use for Cloud device testing services.
# This example works with Xcode project with a single scheme
# Echo to stdout
xcodebuild -showBuildSettings
xcodebuild -showBuildSettings | grep CONFIGURATION_BUILD_DIR
# save to a variable for use in your script
# A little brutal, so I'm open to other ways to do this.
CONFIGURATION_BUILD_DIR=$(xcodebuild -showBuildSettings 2> /dev/null | grep CONFIGURATION_BUILD_DIR | sed 's/[ ]*CONFIGURATION_BUILD_DIR = //')
echo $CONFIGURATION_BUILD_DIR
If you are using Xcode Server Bots
cd ${XCS_PRIMARY_REPO_DIR}
xcodebuild -showBuildSettings
Sample output:
/Users/roblabs/Library/Developer/Xcode/DerivedData/openmaptiles-ios-demo-eectbiabcmhajpdbcoqnaipiaqpd/Build/Products/Release-iphoneos
As noted in https://stackoverflow.com/a/57512068,
The default value is $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
For further documentation on the build setting properties, see Build Setting Reference at developer.apple.com. The link that #puio listed is also useful.

Make sure your project build settings are generating a dSYM file. DEBUG_INFORMATION_FORMAT should be set to dwarf-with-dsym for all configurations

I've recently started getting this error:
2015-03-23 11:35:48.902 run[60036:1047011] Crashlytics.framework/run 1.3.14
2015-03-23 11:35:48.911 run[60036:1047011]
Crashlytics: dSYM Error
Unable to process <your app>.app.dSYM at path /path/to/<your app>.app.dSYM
Make sure your project build settings are generating a dSYM file. DEBUG_INFORMATION_FORMAT should be set to dwarf-with-dsym for all configurations. This could also be a timing issue, make sure the Crashlytics run script build phase is the last build phase and no other scripts have moved the dSYM from the location Xcode generated it.
Command /bin/sh failed with exit code 1
I tried this answer Unable to copy dSYM file into archive but all my Generate Debug Symbols are set to YES
Any further suggestions?
The below solution worked for me.
Go to build setting of your project, then Search for debug information format in build setting and search for "Debug information format" then set "Debug information format" to "DWARF with dSYM file"
and make sure Generate debug symbol in build setting is set to Yes.
Check for true "run script only when installing" on Run Script
Elaborating Bruno's response, if you already have a script phase that you need to run all the time, create a new dedicated phase in order to avoid conflicts.
I removed Fabric and Crashlytics and added them back again from the beginning just like I were to install it the first time around. It worked.
see also https://twittercommunity.com/t/how-to-reinstall-fabric-crashlytics/37890

xcodebuild: find where the output app file is

Is there anyway to specify where to put the output file (ie .app) for xcodebuild? By default it is in:
/Users/myusername/Library/Developer/Xcode/DerivedData/Project-crkyjjbuqqnqqvfxehsjsarzlbbr/Build/Products/Release-iphoneos/Project.app
As I need to find the output Project.app file, if there is no way to specify the path, can I use a script to look for that "/Users/myusername/Library/Developer/Xcode/DerivedData/" folder and inside it find the one with latest modified date and prefix "Project-"? What does the script look like?
Thanks
Override the CONFIGURATION_BUILD_DIR environment variable in an xcodebuild argument. For instance, this command would put its build products under "/tmp/sportsball/":
xcodebuild -workspace Sportsball.xcworkspace -scheme "Sportsball Debug" -configuration Debug clean build CONFIGURATION_BUILD_DIR=/tmp/sportsball/

xcodebuild commands give different results when run from the command line than when run from within Jenkins

I'm setting up a CI system using Jenkins and was finding that the build was failing because xcodebuild reports there are no schemes when I was executing the line
-xcodebuild -workspace XXX -scheme NNN.
I couldn't figure out why this could be happening, so to eliminate something screwy being up with my workspace I created a new project template using XCode and found that I am getting a difference in behavior for any xcodebuild command and for any workspace/project.
The template project was called scrap and if from the terminal command line I run this command for example:
xcodebuild -list
It outputs
Information about project "scrap":
Targets:
scrap
Build Configurations:
Debug
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
Schemes:
scrap
But if I run xcodebuild -list from within Jenkins then the output instead is:
Building in workspace /Users/Shared/Jenkins/Home/workspace/scrap
[scrap] $ /bin/sh -xe /var/folders/ph/s6dvlfq9769741g_yzmjlmz000007c/T/hudson3765407964219991487.sh
+ xcodebuild -list
Information about project "scrap":
Targets:
scrap
Build Configurations:
Debug
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
This project contains no schemes.
This is the most simple of jenkins jobs - all I do is create a new job, set it to a free-style software project, then add a build step of Execut shell and add the xcodebuild -list command, that's it.
Why is xcodebuild saying there are no schemes when there are? And why is it behaving differently when run from within Jenkins?
Figured out that all you need to do is to set the scheme to be shared.
Scheme > Manage Schemes
Make sure "Shared" is checked.
This will then generate out a new folder/file .../xcshareddata/xcschemes/???.xcscheme
Check this file into your source control and scheme should now appear on your jenkins box.
you must ignore your .xcodeproj/xcuserdata/.xcuserdatad in your .gitignore file.
xcodebuild -list get schemes from .xcodeproj/xcuserdata/.xcuserdatad/xcschemes.
jenkins server has no this file so get no schemes,you can open *.xcodeproj in your jenkins server,it will create the file and then do xcodebuild -list can get the current schemes.I have the same problem and solved by the method above.

Why does xcodebuild give different build results than XCode UI

I have a series of projects within a workspace, and trying to use the following type of command to build them via the command line:
"Xcodebuild -project XXX"
or
"Xcodebuild -workspace XXX -scheme YYY"
Some of my projects build fine but others give strange errors, like "'XXX' for instance message does not declare a method with selector" or "ld: library not found for -lMyLibrary"
However all these projects build fine from within the XCode UI without issues.
Based on this is seems that the command line and UI builds are using a different toolset, but that seems like a very bad idea so I'm hoping I'm wrong about this. Or possibly there are just a few different build flags being set on the command line build.
I can try to troubleshoot the issues one by one but I'm hoping I can write a script which does the exact same type of build as the UI.
Any ideas?
Without including -configuration, xcodebuild is going to use the default configuration for each project. Generally that's Release. In Xcode, the Configuration you select will be applied to every project regardless of default.
Given your errors, your most likely problem is that you've used the build pane (why I hate the build pane for large projects), and you've made the classic mistake of applying some settings for Debug rather than all configurations.

Resources