{"title":"Building Xcode Projects from the Command Line","html_url":"https://deallocatedobjects.com/posts/building-xcode-projects-from-the-command-line","source_url":"","markdown_content":"Building iOS and Mac projects from the command-line could be a lot easier to work with.\r\n\r\nHopefully this post will give you a couple ways to make that happen.\r\n\r\nI wanna talk about two different little tools that help ease the process of scripting or working with Xcode projects from the command line.\r\n\r\n### xcodebuild-rb\r\n\r\n[`xcodebuild-rb`](https://github.com/lukeredpath/xcodebuild-rb]) is a neat little ruby gem that lets you create a `Rakefile` inside the root of your Xcode project's folder that looks like this:\r\n\r\n``` ruby\r\nrequire 'rubygems'\r\nrequire 'xcodebuild'\r\n\r\nXcodeBuild::Tasks::BuildTask.new\r\n```\r\n\r\nWhat does that get you?\r\n\r\nWell, after creating that `Rakefile`, running a quick `rake -T` (which will list all available `rake` tasks) will output something like this:\r\n\r\n``` bash\r\nrake xcode:build       # Builds the specified target(s).\r\nrake xcode:clean       # Cleans the build using the same build settings.\r\nrake xcode:cleanbuild  # Builds the specified target(s) from a clean slate.\r\n```\r\n\r\nOne of the coolest features of `xcodebuild-rb` is it's use of \"formatters\". One of my favorite formatters is called \"progress\". You can enable it like this:\r\n\r\n``` ruby\r\nXcodeBuild::Tasks::BuildTask.new do |t|\r\n  t.formatter = XcodeBuild::Formatters::ProgressFormatter.new\r\nend\r\n```\r\n\r\nThen when you build using `xcodebuild-rb`, your output will look something like this:\r\n\r\n``` bash\r\nBuilding target: ExampleProject (in ExampleProject.xcproject)\r\n=============================================================\r\n\r\nConfiguration: Release\r\n..............\r\n\r\nFinished in 2.226883 seconds.\r\nBuild succeeded.\r\n```\r\n\r\n[Read more about `xcodebuild-rb` on Github](https://github.com/lukeredpath/xcodebuild-rb)\r\n\r\n\r\n### xcodearchive\r\n\r\nApple ships Xcode with a command line tool called `xcodebuild`, which as the name suggests, builds an Xcode project. One drawback about the built-in `xcodebuild` tool is that it can't create `.ipa` archive files. \r\n\r\nWell, enter [`xcodearchive`](https://github.com/gcerquant/xcodearchive/blob/master/xcodearchive.rb).\r\n\r\nUnlike `xcodebuild-rb`, `xcodearchive` isn't a ruby gem. It is just a `.rb` file that you can put anywhere you'd like and run.\r\n\r\n`xcodearchive` has a ton of great features, check out the USAGE output:\r\n\r\n``` bash\r\nUsage: xcodearchive [OPTIONS]\r\n        --version\r\n                                     Show version number\r\n    -v, --verbose                    Output more information\r\n    -g, --growl                      Show growl alerts to inform about progress of the build\r\n    -n, --do_not_keep_dsym_symbols   Do not keep the dSYM symbols\r\n    -s, --show                       Show archive in Finder once created\r\n    -c, --clean                      Do a clean before building the Xcode project\r\n    -o, --ipa_export_path FOLDER     Set the path of the folder where the ipa will be saved. Default is '~/Desktop'\r\n    -i DEVELOPPER_IDENTITY,          Force the developper identity value\r\n        --developper_identity\r\n    -p, --project PROJECT            Specifiy xcode project\r\n    -h, --help                       Display this screen\r\n\r\n```\r\n\r\n[Read more about `xcodearchive` on Github](https://github.com/gcerquant/xcodearchive/blob/master/xcodearchive.rb)\r\n\r\nIf you aren't already automating the tedious parts of your build and release processes, you are missing out. As any iOS developer knows, building and releasing can become some of the most monotonous and annoying parts of our jobs, hopefully these little tools will inspire you to start scripting your way to a smoother build/release cycle.","html_content":"<p>Building iOS and Mac projects from the command-line could be a lot easier to work with.</p>\n\n<p>Hopefully this post will give you a couple ways to make that happen.</p>\n\n<p>I wanna talk about two different little tools that help ease the process of scripting or working with Xcode projects from the command line.</p>\n\n<h2 id=\"xcodebuild-rb\" data-level=\"3\">xcodebuild-rb</h2>\n\n<p><a href=\"https://github.com/lukeredpath/xcodebuild-rb\"><code>xcodebuild-rb</code></a> is a neat little ruby gem that lets you create a <code>Rakefile</code> inside the root of your Xcode project’s folder that looks like this:</p>\n<figure class=\"code\" data-lang=\"ruby\"><figcaption><span class=\"lang\">Ruby</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">require</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> 'rubygems'</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">require</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> 'xcodebuild'</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">XcodeBuild</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">Tasks</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">BuildTask</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">new</span></span></code></pre></figure>\n<p>What does that get you?</p>\n\n<p>Well, after creating that <code>Rakefile</code>, running a quick <code>rake -T</code> (which will list all available <code>rake</code> tasks) will output something like this:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">rake</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> xcode:build</span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">       # Builds the specified target(s).</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">rake</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> xcode:clean</span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">       # Cleans the build using the same build settings.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">rake</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> xcode:cleanbuild</span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">  # Builds the specified target(s) from a clean slate.</span></span></code></pre></figure>\n<p>One of the coolest features of <code>xcodebuild-rb</code> is it’s use of “formatters”. One of my favorite formatters is called “progress”. You can enable it like this:</p>\n<figure class=\"code\" data-lang=\"ruby\"><figcaption><span class=\"lang\">Ruby</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">XcodeBuild</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">Tasks</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">BuildTask</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">new</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> do</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> |t|</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  t.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">formatter</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> XcodeBuild</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">Formatters</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">::</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">ProgressFormatter</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">new</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">end</span></span></code></pre></figure>\n<p>Then when you build using <code>xcodebuild-rb</code>, your output will look something like this:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Building</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> target:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> ExampleProject</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (in </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">ExampleProject.xcproject</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">=============================================================</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Configuration:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> Release</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">..............</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Finished</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> in</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 2.226883</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> seconds.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Build</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> succeeded.</span></span></code></pre></figure>\n<p><a href=\"https://github.com/lukeredpath/xcodebuild-rb\">Read more about <code>xcodebuild-rb</code> on Github</a></p>\n\n<h2 id=\"xcodearchive\" data-level=\"3\">xcodearchive</h2>\n\n<p>Apple ships Xcode with a command line tool called <code>xcodebuild</code>, which as the name suggests, builds an Xcode project. One drawback about the built-in <code>xcodebuild</code> tool is that it can’t create <code>.ipa</code> archive files. </p>\n\n<p>Well, enter <a href=\"https://github.com/gcerquant/xcodearchive/blob/master/xcodearchive.rb\"><code>xcodearchive</code></a>.</p>\n\n<p>Unlike <code>xcodebuild-rb</code>, <code>xcodearchive</code> isn’t a ruby gem. It is just a <code>.rb</code> file that you can put anywhere you’d like and run.</p>\n\n<p><code>xcodearchive</code> has a ton of great features, check out the USAGE output:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Usage:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> xcodearchive</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> [OPTIONS]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">        --version</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">                                     Show</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> version</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> number</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -v,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --verbose</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">                    Output</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> more</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> information</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -g,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --growl</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">                      Show</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> growl</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> alerts</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> to</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> inform</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> about</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> progress</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> of</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> build</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -n,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --do_not_keep_dsym_symbols</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">   Do</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> not</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> keep</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> dSYM</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> symbols</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -s,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --show</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">                       Show</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> archive</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> in</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> Finder</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> once</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> created</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -c,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --clean</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">                      Do</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> a</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> clean</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> before</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> building</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> Xcode</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> project</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -o,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --ipa_export_path</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> FOLDER</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">     Set</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> path</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> of</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> folder</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> where</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> ipa</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> will</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> be</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> saved.</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> Default</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> is</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> '~/Desktop'</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -i</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> DEVELOPPER_IDENTITY,</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">          Force</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> the</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> developper</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> identity</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> value</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">        --developper_identity</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -p,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --project</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> PROJECT</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">            Specifiy</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> xcode</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> project</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    -h,</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> --help</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">                       Display</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> this</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> screen</span></span></code></pre></figure>\n<p><a href=\"https://github.com/gcerquant/xcodearchive/blob/master/xcodearchive.rb\">Read more about <code>xcodearchive</code> on Github</a></p>\n\n<p>If you aren’t already automating the tedious parts of your build and release processes, you are missing out. As any iOS developer knows, building and releasing can become some of the most monotonous and annoying parts of our jobs, hopefully these little tools will inspire you to start scripting your way to a smoother build/release cycle.</p>","created_at":"2013-11-16T05:10:25.576Z","updated_at":"2013-11-16T05:10:25.576Z"}