Author: steven_wu Date: Wed Jun 24 20:59:35 2015 New Revision: 240619 URL: http://llvm.org/viewvc/llvm-project?rev=240619&view=rev Log: Update darwin SDK version parsing to support OSX and simulator
This re-commits r226005 with a tweak. The origin attempt failed because Darwin bot sets up SDKROOT and clang can deduce SDK version from them after this patch. That broke many driver tests due to the change of deployment target version. Now the tests should not complain after r240574. Modified: cfe/trunk/lib/Driver/ToolChains.cpp cfe/trunk/test/Driver/darwin-sdkroot.c Modified: cfe/trunk/lib/Driver/ToolChains.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=240619&r1=240618&r2=240619&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Jun 24 20:59:35 2015 @@ -463,16 +463,31 @@ void Darwin::AddDeploymentTarget(Derived if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) iOSTarget = env; - // If no '-miphoneos-version-min' specified on the command line and - // IPHONEOS_DEPLOYMENT_TARGET is not defined, see if we can set the default - // based on -isysroot. - if (iOSTarget.empty()) { + // If there is no command-line argument to specify the Target version and + // no environment variable defined, see if we can set the default based + // on -isysroot. + if (iOSTarget.empty() && OSXTarget.empty() && + Args.hasArg(options::OPT_isysroot)) { if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { - StringRef first, second; StringRef isysroot = A->getValue(); - std::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS")); - if (second != "") - iOSTarget = second.substr(0,3); + // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk + size_t BeginSDK = isysroot.rfind("SDKs/"); + size_t EndSDK = isysroot.rfind(".sdk"); + if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { + StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); + // Slice the version number out. + // Version number is between the first and the last number. + size_t StartVer = SDK.find_first_of("0123456789"); + size_t EndVer = SDK.find_last_of("0123456789"); + if (StartVer != StringRef::npos && EndVer > StartVer) { + StringRef Version = SDK.slice(StartVer, EndVer + 1); + if (SDK.startswith("iPhoneOS") || + SDK.startswith("iPhoneSimulator")) + iOSTarget = Version; + else if (SDK.startswith("MacOSX")) + OSXTarget = Version; + } + } } } Modified: cfe/trunk/test/Driver/darwin-sdkroot.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-sdkroot.c?rev=240619&r1=240618&r2=240619&view=diff ============================================================================== --- cfe/trunk/test/Driver/darwin-sdkroot.c (original) +++ cfe/trunk/test/Driver/darwin-sdkroot.c Wed Jun 24 20:59:35 2015 @@ -40,3 +40,39 @@ // env SDKROOT=/ cmd //c echo %SDKROOT% // // This test passes using env.exe from GnuWin32. + +// Check if clang set the correct deployment target from -sysroot +// +// RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk +// RUN: mkdir -p %t/SDKs/iPhoneOS8.0.0.sdk +// RUN: env SDKROOT=%t/SDKs/iPhoneOS8.0.0.sdk %clang -target arm64-apple-darwin %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-IPHONE %s +// +// CHECK-IPHONE: clang +// CHECK-IPHONE: "-cc1" +// CHECK-IPHONE: "-triple" "arm64-apple-ios8.0.0" +// CHECK-IPHONE: ld +// CHECK-IPHONE: "-iphoneos_version_min" "8.0.0" +// +// +// RUN: rm -rf %t/SDKs/iPhoneSimulator8.0.sdk +// RUN: mkdir -p %t/SDKs/iPhoneSimulator8.0.sdk +// RUN: env SDKROOT=%t/SDKs/iPhoneSimulator8.0.sdk %clang -target x86_64-apple-darwin %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-SIMULATOR %s +// +// CHECK-SIMULATOR: clang +// CHECK-SIMULATOR: "-cc1" +// CHECK-SIMULATOR: "-triple" "x86_64-apple-ios8.0.0" +// CHECK-SIMULATOR: ld +// CHECK-SIMULATOR: "-ios_simulator_version_min" "8.0.0" +// +// RUN: rm -rf %t/SDKs/MacOSX10.10.0.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.10.0.sdk +// RUN: env SDKROOT=%t/SDKs/MacOSX10.10.0.sdk %clang -target x86_64-apple-darwin %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX %s +// +// CHECK-MACOSX: clang +// CHECK-MACOSX: "-cc1" +// CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" +// CHECK-MACOSX: ld +// CHECK-MACOSX: "-macosx_version_min" "10.10.0" _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits