xcbuild: add compatibility support for exporting sdk info

"Real" xcodebuild allows using `xcodebuild -version -sdk` without
an sdk version argument, which will dump sdk info for all the
installed sdks.

Bazel"s "xcode cc toolchain setup on mac" process uses this
to determine which SDK version is actually installed.  This
change allows using a nix-supplied pinned compiler and build
system under bazel.
This commit is contained in:
Dave Nicponski 2020-04-22 18:58:45 -04:00 committed by Dave Nicponski
parent 7679b8edae
commit c3c3f68020

View File

@ -110,11 +110,15 @@ runCommand "xcodebuild-${xcbuild.version}" {
mkdir -p $out/Applications/Xcode.app/Contents
ln -s $out $out/Applications/Xcode.app/Contents/Developer
# The native xcodebuild command supports an invocation like "xcodebuild -version -sdk" without specifying the specific SDK, so we simulate this by
# detecting this case and simulating the output; printing the header and appending the normal output via appending the sdk version to the positional
# arguments we pass through to the wrapped xcodebuild.
makeWrapper ${xcbuild}/bin/xcodebuild $out/bin/xcodebuild \
--add-flags "-xcconfig ${xcconfig}" \
--add-flags "DERIVED_DATA_DIR=." \
--set DEVELOPER_DIR "$out" \
--set SDKROOT ${sdkName} \
--run '[ "$#" -eq 2 ] && [ "$1" = "-version" ] && [ "$2" = "-sdk" ] && echo ${sdkName}.sdk - macOS ${sdkVer} \(macosx${sdkVer}\) && set -- "$@" "${sdkName}"' \
--run '[ "$1" = "-version" ] && [ "$#" -eq 1 ] && (echo Xcode ${xcodeVer}; echo Build version ${sdkBuildVersion}) && exit 0' \
--run '[ "$1" = "-license" ] && exit 0'