2

How do I get the URL or url string to the build directory of a workspace or a project? I don't want to set it myself to know what it is instead I want to know the default set by Xcode.

How to get the directory programmatically?

naz
  • 1,478
  • 2
  • 21
  • 32

3 Answers3

5

If you need the build directory path for use within an Xcode build script (Build Phases > Run Script), then use the following variable:

$TARGET_BUILD_DIR

For an exhaustive list of all variables exposed by Xcode in build scripts, follow this answer:

$ xcodebuild -project myProject.xcodeproj -target "myTarget" -showBuildSettings

Daniel Jones
  • 615
  • 5
  • 17
2

Building up on Daniel Jones answer above, to get the BUILD_DIR of a workspace, you should run:

xcodebuild -workspace ios/myApp.xcworkspace -scheme myApp -showBuildSettings | grep BUILD_DIR

example of response:

BUILD_DIR = /Users/Olivier/Library/Developer/Xcode/DerivedData/myApp-ceetrcnutlegngflgvvfjaaaycrc/Build/Products

Olivier
  • 769
  • 7
  • 10
0

Select you project in the Xcode. On the right side select "Build Settings". Select desired target and under "Build Locations" you will find paths for debug, release and distribution configurations. These paths are relative to your "Deriver Data" directory. To open that directory in Finder, do the following. Xcode menu: Window->Organizer. When you get "Organizer" window, on the left side select you project and on the right side you will get "Derive Data" path. Clicking on the arrow at the end of the "Derived Data" path you will open that directory in the Finder.

If you want a build directory path to use in some Pre-actions or Post-actions scripts, then variable name for it can be found in Quick Help Inspector, once you clicked on desired build directory in "Build Locations".

enter image description here

enter image description here

Sergio
  • 1,702
  • 1
  • 20
  • 24
  • What is the purpose of programmatically accessing build dir for mobile app? It is more probably that you need info about some path inside bundle app. – Sergio Mar 08 '15 at 20:21
  • To access compiled resources. Anyway i figured out a better solution. I created a bundle target and shared it with the main app. – naz Mar 08 '15 at 21:30
  • That is not better solution, that is the only solution. Getting build directory path programmatically to access compiled resources is not something that can work. It only makes sense to use it in the build scripts. – Sergio Mar 09 '15 at 10:41
  • Not a solution to my question I agree. I have several projects in a workspace and I want to access the resources of another project/framework. I now can do that. I know your answer the clue was when I said I don't want to set the build path which means I know where to get it manually. Thanks for the help. – naz Mar 09 '15 at 10:48