title: Unique Xcode BUILD_PATH environment variable in build.xml not usable
body: <p>I have a problem with our ant script / Jenkins since using CocoaPods (which I think is not the real cause for the problem, it's more a class of problems), which turned the Xcode project in a Xcode workspace.</p>
  
  <p>We use Jenkins for the OTA (over the air) distribution.</p>
  
  <p>Therein is a job, which executes an ant script. The build.xml is:</p>
  
  <pre><code>&lt;project name="iOS Compile" default="simulatorbuild" basedir="."&gt;
  
      &lt;!-- properties --&gt; 
      &lt;property file="default.properties" /&gt;
  
      &lt;property environment="env" /&gt;
      &lt;property name="sdk.simulator" value="iphonesimulator${sdk.version}" /&gt;
      &lt;property name="sdk.device" value="iphoneos${sdk.version}" /&gt;
      &lt;property name="build.dir" location="build"/&gt;
  
      &lt;!-- clean --&gt;
      &lt;target name="clean"&gt;
          &lt;exec executable="xcodebuild" failonerror="true"&gt;
              &lt;arg line="clean" /&gt;    
          &lt;/exec&gt;
  
          &lt;delete dir="${build.dir}" /&gt;
          &lt;mkdir dir="build"/&gt;
      &lt;/target&gt;
  
  
      &lt;!-- simulator build --&gt;
      &lt;target name="simulatorbuild" depends="clean"&gt;
          &lt;exec executable="xcodebuild" failonerror="true"&gt;
              &lt;arg line="-sdk ${sdk.simulator}" /&gt;
              &lt;arg line="-configuration ${config.simulator}" /&gt;       
              &lt;!--&lt;arg line="-target ${target.app}" /&gt;--&gt;
              &lt;arg line="-workspace ${app.title}.xcworkspace" /&gt;
              &lt;arg line="-scheme ${app.title}" /&gt;
          &lt;/exec&gt;
      &lt;/target&gt;
  
      &lt;!-- simulator build for code coverage --&gt;
      &lt;target name="-cc_simulatorbuild"&gt;
          &lt;exec executable="xcodebuild" failonerror="true"&gt;
              &lt;arg line="-sdk ${sdk.simulator}" /&gt;
              &lt;arg line="-configuration ${config.simulator}" /&gt;       
              &lt;!--&lt;arg line="-target ${target.app}" /&gt;--&gt;
              &lt;arg line="-workspace ${app.title}.xcworkspace" /&gt;
              &lt;arg line="-scheme ${app.title}" /&gt;
  
              &lt;!-- Changing some project settings to activate code coverage. --&gt;
              &lt;!--&lt;arg line="OTHER_CFLAGS=- -coverage" /&gt; --&gt;
  
              &lt;arg line="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" /&gt;
              &lt;arg line="GCC_GENERATE_TEST_COVERAGE_FILES=YES" /&gt;
              &lt;!--&lt;arg line="GCC_PRECOMPILE_PREFIX_HEADER=NO" /&gt;--&gt;
          &lt;/exec&gt;
      &lt;/target&gt;
  
      &lt;!-- device build --&gt;   
      &lt;target name="devicebuild"&gt;
          &lt;exec executable="xcodebuild" failonerror="true"&gt;
              &lt;arg line="-sdk ${sdk.device}" /&gt;
              &lt;arg line="-configuration ${config.device}" /&gt;
              &lt;!--&lt;arg line="-target ${target.app}" /&gt;--&gt;
              &lt;arg line="-workspace ${app.title}.xcworkspace" /&gt;
              &lt;arg line="-scheme ${app.title}" /&gt;
          &lt;/exec&gt;
      &lt;/target&gt;
  
      &lt;!-- unit tests --&gt;
      &lt;target name="unittest" depends="simulatorbuild"&gt;
          &lt;exec executable="xcodebuild" output="${build.dir}/tmp" errorproperty="error.unittest"&gt;
              &lt;arg line="-sdk ${sdk.simulator}" /&gt;
              &lt;arg line="-configuration Debug" /&gt;
              &lt;arg line="-target ${target.unittests}" /&gt;
          &lt;/exec&gt;
  
          &lt;exec executable="ruby"&gt;
              &lt;arg line="ocunit2junit.rb" /&gt;
              &lt;arg file="${build.dir}/tmp" /&gt;
          &lt;/exec&gt;
  
          &lt;delete file="${build.dir}/tmp" /&gt;
      &lt;/target&gt;
  
      &lt;!-- code coverage --&gt;
      &lt;target name="codecoverage" depends="-cc_simulatorbuild"&gt;
          &lt;exec executable="xcodebuild" output="${build.dir}/tmp" errorproperty="error.unittest"&gt;
              &lt;arg line="-sdk ${sdk.simulator}" /&gt;
              &lt;arg line="-configuration Debug" /&gt;
              &lt;arg line="-target ${target.unittests}" /&gt;
  
              &lt;!-- Changing some project settings to activate code coverage. --&gt;
              &lt;!--&lt;arg line="OTHER_CFLAGS=- -coverage" /&gt; --&gt; 
  
              &lt;arg line="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" /&gt;
              &lt;arg line="GCC_GENERATE_TEST_COVERAGE_FILES=YES" /&gt;
          &lt;/exec&gt;
  
          &lt;exec executable="ruby"&gt;
              &lt;arg line="ocunit2junit.rb" /&gt;
              &lt;arg file="${build.dir}/tmp" /&gt;
          &lt;/exec&gt;
  
          &lt;delete file="${build.dir}/tmp" /&gt;
  
          &lt;mkdir dir="${build.dir}/code-coverage"/&gt;
          &lt;exec executable="python"&gt;
              &lt;arg line="gcovr" /&gt;
              &lt;arg line="-x" /&gt;               &lt;!-- set XML-Output--&gt;
              &lt;arg line="-v" /&gt;               &lt;!-- set more output details --&gt;
              &lt;arg line="-r '${basedir}'" /&gt;  &lt;!-- set the root dir --&gt;
              &lt;arg line="-o '${build.dir}/code-coverage/coverage.xml'" /&gt;  
          &lt;/exec&gt;
      &lt;/target&gt;
  
  
      &lt;!-- Distribute Target --&gt;
      &lt;target name="distribute" depends="devicebuild"&gt;
          &lt;echo message="Set up Over-The-Air-Distribution"/&gt;
          &lt;property name="fileprefix" value="${env.JOB_NAME}-${env.BUILD_NUMBER}-${config.device}"/&gt;
          &lt;property name="app.path" value="${build.dir}/${config.device}-iphoneos/${target.app}.app"/&gt;
          &lt;property name="dSYM.path" value="${build.dir}/${config.device}-iphoneos/${target.app}.app.dSYM"/&gt;
          &lt;property name="output.dir" location="${basedir}/output"/&gt;
          &lt;delete dir="${output.dir}" /&gt;
          &lt;mkdir dir="${output.dir}/${fileprefix}" /&gt;
  
          &lt;exec executable="perl"&gt;
              &lt;arg line="parsePlist.pl" /&gt;
              &lt;arg line="${target.app}" /&gt;
          &lt;/exec&gt;
          &lt;property file="${target.app}-Infoplist.properties" /&gt;
  
          &lt;!-- generate ipa file --&gt;       
          &lt;exec executable="xcrun" failonerror="true"&gt;
              &lt;arg line="-verbose" /&gt;
              &lt;arg line="-sdk ${sdk.device}" /&gt;
              &lt;arg line="PackageApplication" /&gt;
              &lt;arg line="-v '${app.path}'" /&gt;
              &lt;arg line="-o '${output.dir}/${fileprefix}/${app.title}.ipa'" /&gt;
              &lt;arg line="--sign '${codesign}'" /&gt;
              &lt;arg line="--embed '${basedir}/${provisioningprofile}'" /&gt;
          &lt;/exec&gt;
  
          &lt;!-- manage app icons --&gt;
          &lt;copy file="${basedir}/${icon.small}" tofile="${output.dir}/${fileprefix}/Icon-57.png"/&gt;
          &lt;copy file="${basedir}/${icon.large}" tofile="${output.dir}/${fileprefix}/Icon-512.png"/&gt;
  
          &lt;!--copy file="${dSYM.path}" tofile="${output.dir}/${fileprefix}/${target.app}.app.dSYM"/--&gt;
  
          &lt;!-- generate app manifest --&gt;
          &lt;echoxml file="${output.dir}/${fileprefix}/app-manifest.plist"&gt;
              &lt;!--&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;--&gt;
              &lt;plist version="1.0"&gt;
                  &lt;dict&gt;
                      &lt;key&gt;items&lt;/key&gt;
                      &lt;array&gt; 
                          &lt;dict&gt;
                              &lt;key&gt;assets&lt;/key&gt;
                              &lt;array&gt;
                                  &lt;dict&gt;
                                      &lt;key&gt;kind&lt;/key&gt;
                                      &lt;string&gt;software-package&lt;/string&gt;
                                      &lt;key&gt;url&lt;/key&gt;
                                      &lt;string&gt;${OTAURL}/output/${fileprefix}/${app.title}.ipa&lt;/string&gt;
                                  &lt;/dict&gt;
                                  &lt;dict&gt;
                                      &lt;key&gt;kind&lt;/key&gt;
                                      &lt;string&gt;full-size-image&lt;/string&gt;
                                      &lt;key&gt;needs-shine&lt;/key&gt;
                                      &lt;true/&gt;
                                      &lt;key&gt;url&lt;/key&gt;
                                      &lt;string&gt;${OTAURL}/output/${fileprefix}/Icon-512.png&lt;/string&gt;
                                  &lt;/dict&gt;
                                  &lt;dict&gt;
                                      &lt;key&gt;kind&lt;/key&gt;
                                      &lt;string&gt;display-image&lt;/string&gt;
                                      &lt;key&gt;needs-shine&lt;/key&gt;
                                      &lt;true/&gt;
                                      &lt;key&gt;url&lt;/key&gt;
                                      &lt;string&gt;${OTAURL}/output/${fileprefix}/Icon-57.png&lt;/string&gt;
                                  &lt;/dict&gt;
                              &lt;/array&gt;
                              &lt;key&gt;metadata&lt;/key&gt;
                              &lt;dict&gt;
                                  &lt;key&gt;bundle-identifier&lt;/key&gt;
                                  &lt;string&gt;${CFBundleIdentifier}&lt;/string&gt;
                                  &lt;key&gt;bundle-version&lt;/key&gt;
                                  &lt;string&gt;${CFBundleShortVersionString} #${env.BUILD_NUMBER}&lt;/string&gt;
                                  &lt;key&gt;kind&lt;/key&gt;
                                  &lt;string&gt;software&lt;/string&gt;
                                  &lt;key&gt;title&lt;/key&gt;
                                  &lt;string&gt;${app.title}&lt;/string&gt;
                                  &lt;key&gt;subtitle&lt;/key&gt;
                                  &lt;string&gt;${app.subtitle}&lt;/string&gt;
                              &lt;/dict&gt;
                          &lt;/dict&gt;
                      &lt;/array&gt;
                  &lt;/dict&gt;
              &lt;/plist&gt;
          &lt;/echoxml&gt;
      &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>There is also a default.properties file:</p>
  
  <pre><code># default properties
  sdk.version         = 5.1
  app.title           = &lt;APP_NAME&gt;
  app.subtitle        = &lt;APP_NAME&gt;
  config.simulator    = Debug
  config.device       = Release
  target.app          = &lt;APP_NAME&gt;
  target.unittests    = &lt;APP_NAME&gt;Test
  provisioningprofile = &lt;APP_NAME&gt;AdHoc.mobileprovision
  codesign            = iPhone Distribution: &lt;COMPANY_NAME&gt;
  icon.small          = Icon.png
  icon.large          = Icon@2x.png
  OTAURL              = http://&lt;COMPANY_NAME&gt;.com/OTA/&lt;APP_NAME&gt;
  </code></pre>
  
  <p>When I run</p>
  
  <pre><code>ant distribute
  </code></pre>
  
  <p>on my local machine (not even on the CI server), the following error occurs:</p>
  
  <pre><code>[exec] error: Specified application doesn't exist or isn't a bundle directory : '/Users/&lt;MY_USERNAME&gt;/Documents/&lt;COMPANY_NAME&gt;/projects/&lt;APP_NAME&gt;/build/Release-iphoneos/&lt;APP_NAME&gt;.app'
  </code></pre>
  
  <p>I did a lot of researching the last days. But now, I don't, what else to do ...</p>
  
  <p>What I got so far:</p>
  
  <ol>
  <li><p>Since Xcode 4, the build path is no longer your project directory, but instead a unique folder in the user library. The settings for this can be found under "Derived Data".
  "Legacy" is the project folder and "unique" (the new default setting) is the user library.</p></li>
  <li><p>The dependency of "distribute" is "devicebuild". That target uses the unique folder and correctly creates it under</p>
  
  <p>/Users//Library/Developer/Xcode/DerivedData</p></li>
  <li><p>On the other side (in the target "distribute") the only line I need to change is</p>
  
  <p>&lt; arg line="-v '${app.path}'" /></p></li>
  </ol>
  
  <p>which points to the local / project directory.</p>
  
  <p>Instead of the app.path I need to set the unique folder (user library).</p>
  
  <ol start="4">
  <li><p>In <a href="https://stackoverflow.com/questions/6910901/canonical-list-of-xcode-environment-variables">How do I print a list of &quot;Build Settings&quot; in Xcode project?</a> I found a list of Xcode environment variables. The </p>
  
  <p>BUILD_DIR</p></li>
  </ol>
  
  <p>variable is close to what I need. It's a bit deeper in the folder hierarchy, but ok.</p>
  
  <ol start="5">
  <li>I thought, perhaps is <a href="https://stackoverflow.com/questions/8536728/xcrun-packageapplication-failed-unable-to-copy-application">Xcrun PackageApplication, failed unable to copy application</a> a similar problems. But it's not really the same.</li>
  </ol>
  
  <p>Even though BUILD_DIR is not absolutely correct, I tried to use that one. But I did not succeed in that.</p>
  
  <p>How do I call that Xcode env variable in my ant script? Is that even possible?</p>
  
  <p>I tried:</p>
  
  <pre><code>&lt; arg line="-v '${BUILD_DIR}'" /&gt;
  &lt; arg line="-v '$BUILD_DIR'" /&gt;
  &lt; arg line="-v 'BUILD_DIR'" /&gt;
  </code></pre>
  
  <p>Please, tell me which stupid mistake I did without knowing it. :-)</p>
  
  <p>Really big thanks in advance!
  And if you need more information (even thought I don't think, there is much left I did not tell you), just ask.</p>
  
  <p>Greetings and have a nice day,
  Dominic</p>