xcodebuild: find where the output app file is - xcode

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/

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.

Variable for path to XCode's SharedPrecompiledHeaders folder

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?

Test Coverage via command line Xcode 5.1

I have unit tests in xcode 5.1, ios7.1, when I run them via the test command within xcode I can see gcda and gcdo files generated in the appropriate place. When I invoke the test command via the command line I only get gcdo files. It must be something to do with the __gcov_flush method that needs to be called to generate the files (I put logs in the flush method I see it in the gui logs but not the terminal logs). I used help from these SO questions
Code coverage from command line
Followed basically all of this one
I have also followed the usual advice and set
Generate Test Coverage Files: YES
Instrument Program Flow: YES
At a project level.
My command:
xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -configuration Debug -sdk $IPHONESIMULATOR_VERSION ONLY_ACTIVE_ARCH=YES clean build test
Is there a reason why it would work within xcode but not via the command line?

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.

Build are not tagged as unstable when unit test fails

I have added a new job in my hudson server which builds the project with a makefile.
Execute shell command:
#!/bin/bash
cd $JOB_NAME
make
My makefile looks like this
SDK_31 = iphonesimulator3.1
TARGET_DEV = myProject
TARGET_TEST = unitTest
all: debug
debug:
xcodebuild -sdk ${SDK_31} -target "${TARGET_DEV}" -configuration Debug
xcodebuild -sdk ${SDK_31} -target "${TARGET_TEST}" -configuration Debug
clean:
xcodebuild -alltargets clean
rm -rf build
But when hudson build the projects, some unit tests fail but the build is tagged as successful.
What should I have to do to have an "unstable project" ?
Best regards,
You should configure Hudson to record unit test results, by enabling the 'Publish Junit test result report' post-build action.
post-build actions http://img141.imageshack.us/img141/5136/hudsonjunit.png
Update: If you can't get JUnit XML output, you should be able to use the Text-finder plugin to change the build status:
This plugin lets you search keywords in the files you specified and use that to mark the build as success or a failure.
I found this handy ruby script by Christian Hedin that converts the output of OCUnit tests (the format used by Xcode) into JUnit xml files (the format used by Hudson).
You can grab the script on github:
http://github.com/ciryon/OCUnit2JUnit
and for an explanation of how to use it, here's his blog post about it:
http://blog.jayway.com/2010/01/31/continuos-integration-for-xcode-projects/
Basically, you pipe xcodebuild into ocunit2junit.rb with a command like this:
/usr/bin/xcodebuild -target UnitTests | /usr/local/bin/ocunit2junit.rb
and it places the xml files into a test-reports folder that it creates at the root of your project folder. Then tell Hudson to copy the test-reports/*.xml artifacts as the JUnit results and you're set.
This setup will allow Hudson to correctly identify if a unit test has passed or failed and correctly mark the stability of the build.
I've been using it for a month now and it works great. The setup was very simple.

Resources