Xcodebuild Ignoring -derivedDataPath

Xcodebuild Ignoring -derivedDataPath

Am I misunderstanding what -derivedDataPath does, or is this a bug? You can clearly see in the output that xcodebuild is ignoring the command-line value, and defaulting to Library/Developer/Xcode/DerivedData.

Command line invocation:
/Applications/ -project MyProj.xcodeproj -scheme “MyProj (iOS)" -destination "name=iPhone 12" -derivedDataPath=/Users/alpe77/myproj/MyProj/Build build

User defaults from command line:
    derivedDataPath = /Users/alpe77/myproj/MyProj/Build
    IDEPackageSupportUseBuiltinSCM = YES

note: Using new build system
note: Building targets in parallel
note: Planning build
note: Analyzing workspace
note: Using build description from disk
note: Build preparation complete
CodeSign /Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app (in target 'MyProj (iOS)' from project 'MyProj')
cd /Users/alpe77/myproj/MyProj
export CODESIGN_ALLOCATE\=/Applications/

Signing Identity:     "-"

/usr/bin/codesign --force --sign - --entitlements 
/Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/ \(iOS\).build/MyProj.app.xcent --timestamp\=none 
/Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app
/Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app: replacing existing signature

** BUILD SUCCEEDED ** [0.771 sec]

% xcrun xcodebuild -version 
Xcode 12.5.1
Build version 12E507

2 Answers

Had the same problem (Xcode 12.4) and found out that the build environment configuration variable CONFIGURATION_BUILD_DIR overrides the path given in -derivedDataPath

I opened "Xcode Preferences > Locations > Derived Data > Advanced" and changed the build location setting from my custom setting to "Unique" which solved the problem.

Would be interested in how to prevent CONFIGURATION_BUILD_DIR from overriding -derivedDataPath on the command line, though...

Edit

See for a solution.

1

From what I could figure out, at least for Xcode 13, xcodebuild ignores -derivedDataPath for build products/intermediates, if they're overridden in Xcode defaults, in e.g. Xcode Preferences > Locations > Derived Data > Advanced - they're derived from Derived Data set in Xcode defaults, not from the one passed to xcodebuild. As a workaround, we can "clear" those defaults as well, when invoking xcodebuild like below (luckily they're clearly visible in the list of defaults for com.apple.dt.Xcode, as IDECustomBuildProductsPath and IDECustomBuildIntermediatesPath, and xcodebuild supports overriding the custom defaults in general by passing -userdefault=value):

xcodebuild -derivedDataPath /custom/path -IDECustomBuildProductsPath="" -IDECustomBuildIntermediatesPath="" ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.