[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
This revision was automatically updated to reflect the committed changes. Closed by commit rL305678: [driver][macOS] Pick the system version for the deployment target (authored by arphaman). Changed prior to commit: https://reviews.llvm.org/D34175?vs=102607=103009#toc Repository: rL LLVM https://reviews.llvm.org/D34175 Files: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp cfe/trunk/test/Driver/darwin-sdkroot.c Index: cfe/trunk/test/Driver/darwin-sdkroot.c === --- cfe/trunk/test/Driver/darwin-sdkroot.c +++ cfe/trunk/test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp === --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,25 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra)) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1229,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) WatchOSTarget = Version; Index: cfe/trunk/test/Driver/darwin-sdkroot.c === --- cfe/trunk/test/Driver/darwin-sdkroot.c +++ cfe/trunk/test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp === --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,25 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra)) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1229,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") ||
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
kubamracek added a comment. Nice! Repository: rL LLVM https://reviews.llvm.org/D34175 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
dexonsmith accepted this revision. dexonsmith added a comment. This revision is now accepted and ready to land. LGTM. Repository: rL LLVM https://reviews.llvm.org/D34175 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
arphaman updated this revision to Diff 102607. arphaman added a comment. Remove redundant driver version correctness checks. Repository: rL LLVM https://reviews.llvm.org/D34175 Files: lib/Driver/ToolChains/Darwin.cpp test/Driver/darwin-sdkroot.c Index: test/Driver/darwin-sdkroot.c === --- test/Driver/darwin-sdkroot.c +++ test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: lib/Driver/ToolChains/Darwin.cpp === --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,25 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra)) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1229,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) WatchOSTarget = Version; Index: test/Driver/darwin-sdkroot.c === --- test/Driver/darwin-sdkroot.c +++ test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: lib/Driver/ToolChains/Darwin.cpp === --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,25 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra)) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1229,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) WatchOSTarget = Version; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
arphaman added inline comments. Comment at: lib/Driver/ToolChains/Darwin.cpp:1133 + HadExtra) || + HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) +return MacOSSDKVersion; inouehrs wrote: > What these magic numbers mean (especially minor and micro versions)? > You may need some comments. I actually just took it from the function below which checks if the macOS version is valid (so we want 10.XX.XX). But looking at it again, I think that we don't really them here as the SDK version should will probably be valid. I'll update the patch and remove them from the code. Repository: rL LLVM https://reviews.llvm.org/D34175 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
inouehrs added inline comments. Comment at: lib/Driver/ToolChains/Darwin.cpp:1133 + HadExtra) || + HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) +return MacOSSDKVersion; What these magic numbers mean (especially minor and micro versions)? You may need some comments. Repository: rL LLVM https://reviews.llvm.org/D34175 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34175: [driver][macOS] Pick the system version for the deployment target if the SDK is newer than the system
arphaman created this revision. This patch improves the driver by making sure that it picks the system version for the deployment target when the version of the macOS SDK is newer than the system version. Repository: rL LLVM https://reviews.llvm.org/D34175 Files: lib/Driver/ToolChains/Darwin.cpp test/Driver/darwin-sdkroot.c Index: test/Driver/darwin-sdkroot.c === --- test/Driver/darwin-sdkroot.c +++ test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: lib/Driver/ToolChains/Darwin.cpp === --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,26 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra) || + HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1230,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) WatchOSTarget = Version; Index: test/Driver/darwin-sdkroot.c === --- test/Driver/darwin-sdkroot.c +++ test/Driver/darwin-sdkroot.c @@ -74,3 +74,12 @@ // CHECK-MACOSX: "-triple" "x86_64-apple-macosx10.10.0" // CHECK-MACOSX: ld // CHECK-MACOSX: "-macosx_version_min" "10.10.0" + +// Ensure that we never pick a version that's based on the SDK that's newer than +// the system version: +// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk +// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk +// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s + +// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99" Index: lib/Driver/ToolChains/Darwin.cpp === --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -1118,6 +1118,26 @@ } } +/// Returns the most appropriate macOS target version for the current process. +/// +/// If the macOS SDK version is the same or earlier than the system version, +/// then the SDK version is returned. Otherwise the system version is returned. +static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { + unsigned Major, Minor, Micro; + llvm::Triple(llvm::sys::getProcessTriple()) + .getMacOSXVersion(Major, Minor, Micro); + VersionTuple SystemVersion(Major, Minor, Micro); + bool HadExtra; + if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, + HadExtra) || + HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) +return MacOSSDKVersion; + VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) +return SystemVersion.getAsString(); + return MacOSSDKVersion; +} + void Darwin::AddDeploymentTarget(DerivedArgList ) const { const OptTable = getDriver().getOpts(); @@ -1210,7 +1230,7 @@ SDK.startswith("iPhoneSimulator")) iOSTarget = Version; else if (SDK.startswith("MacOSX")) - OSXTarget = Version; + OSXTarget = getSystemOrSDKMacOSVersion(Version); else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator"))