The theme for my reading this week had to do with automating testing for iOS. You can build an iOS app (
xcodebuild), install it on the device (I prefer to use PhoneGap’s
ios-deploy), and then run Instruments (
instruments) with only a single Terminal. While figuring all of this out, I needed to learn bash’s flow control, which a good introduction to bash helped me learn pretty well.
While this post only talks about a certain aspect of the
xcodebuild arguments (
-destination), the post is full of enough working examples for me to get a build that I could install on a device. For the purposes of iOS device building, you want your
-destination in one of three forms:
The first two should generate a build for the device’s architecture (if you have “Build Active Architecture Only” set to YES in the Build Settings). The last one can build without a device attached and should generate a product with both the 32- and 64-bit binaries included. Building both 32- and 64-bit binaries takes longer, a lot longer if you have a lot of code and/or libraries.
By default, the build products end up in your DerivedData folder, if you want them going to a custom location you can either:
- Specify a new
-derivedDataPath buildwill place all the derived data in your current directory and the app will be either in
build/Build/Products/Debug-iphoneosdepending on your
- Specify a custom
CONFIGURATION_BUILD_DIRpath with an absolute path. So,
CONFIGURATION_BUILD_DIR=~/buildwould place the app file in the build directory of your home directory.
For reference for all of
xcodebuild‘s options, you can go to the corresponding man page.
Not an article or a blog post, but a very useful GitHub repository to install and launch (if you wish) app files to a device. Older versions had difficulty with both the latest OS X (El Capitan) and iOS 9, but the latest version of this repository fixes these issues making this one of the better command line iOS installation tools.
This post is coming up on 4 years old and mostly talks about UIAutomation, but it also describes launching Instruments through the command line. If your goal is testing specific simulators, jc has another post for this. While instruments can handle installing the app file to a simulator automatically, if you want to run instruments on device, you have to already have the app installed on the device.
Another useful command:
instruments -s devices will list all connected devices and simulators. For other options, you can refer to its man page.
I wanted to make a shell script to run my custom build-install-instrument flow. However, I have never actually written a shell script before. LinuxCommand.org has two good tutorial series Learning The Shell and Writing Shell Scripts that goes through basic bash command line usage and basis script writing, including flow control. Bash syntax, especially how bash does conditions, is strange.