]> granicus.if.org Git - clang/commitdiff
Driver/Darwin: Honor IPHONEOS_DEPLOYMENT_TARGET.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 26 Jan 2010 01:45:19 +0000 (01:45 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 26 Jan 2010 01:45:19 +0000 (01:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94488 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticDriverKinds.td
lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h
test/Driver/darwin-version.c

index 8cdf85082b1629e7e17a930cad346c4318dc2dc3..aa1d95e424648e384d7edd4293a07fdfb3f75625 100644 (file)
@@ -62,6 +62,8 @@ def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_remap_file : Error<
     "invalid option '%0' not of the form <from-file>;<to-file>">;
+def err_drv_conflicting_deployment_targets : Error<
+    "conflicting deployment targets, both MACOSX_DEPLOYMENT_TARGET '%0' and IPHONEOS_DEPLOYMENT_TARGET '%1' are present in environment">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused when '%2' is present">;
index a9c6a68ceb8a9b2a6380467dbf2727c4b9adfe8f..355dbe4052d31b912bceee760f79ef4609e96d15 100644 (file)
@@ -403,22 +403,38 @@ DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
           << OSXVersion->getAsString(Args)
           << iPhoneVersion->getAsString(Args);
   } else if (!OSXVersion && !iPhoneVersion) {
-    // Chose the default version based on the arch.
-    //
-    // FIXME: Are there iPhone overrides for this?
-
-    if (!isIPhoneOS()) {
-      // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
-      // from the host.
-      const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
-      if (!Version)
-        Version = MacosxVersionMin.c_str();
+    // If neither OS X nor iPhoneOS targets were specified, check for
+    // environment defines.
+    const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
+    const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
+
+    // Ignore empty strings.
+    if (OSXTarget && OSXTarget[0] == '\0')
+      OSXTarget = 0;
+    if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
+      iPhoneOSTarget = 0;
+
+    if (OSXTarget && iPhoneOSTarget) {
+      getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
+        << OSXTarget << iPhoneOSTarget;
+    } else if (OSXTarget) {
       const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
-      DAL->append(DAL->MakeJoinedArg(0, O, Version));
-    } else {
-      const char *Version = IPhoneOSVersionMin.c_str();
+      DAL->append(DAL->MakeJoinedArg(0, O, OSXTarget));
+    } else if (iPhoneOSTarget) {
       const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
-      DAL->append(DAL->MakeJoinedArg(0, O, Version));
+      DAL->append(DAL->MakeJoinedArg(0, O, iPhoneOSTarget));
+    } else {
+      // Otherwise, choose the default version based on the toolchain.
+
+      // FIXME: This is confusing it should be more explicit what the default
+      // target is.
+      if (isIPhoneOS()) {
+        const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
+        DAL->append(DAL->MakeJoinedArg(0, O, IPhoneOSVersionMin));
+      } else {
+        const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
+        DAL->append(DAL->MakeJoinedArg(0, O, MacosxVersionMin));
+      }
     }
   }
 
index 3ca6ad88972ceb6ec6f2cef5b52d5385a7c52e24..89478d5f157a0ef7c67af4aaafef6db0edfe9dcf 100644 (file)
@@ -54,11 +54,15 @@ class VISIBILITY_HIDDEN Darwin : public ToolChain {
   //
   // FIXME: This should go away, such differences should be completely
   // determined by the target triple.
+  //
+  // FIXME: It is also broken, we need to distinguish the "default target" from
+  // the actual target. The -m...-version-min strings and deployment targets can
+  // change this.
   bool IsIPhoneOS;
 
   /// The default macosx-version-min of this tool chain; empty until
   /// initialized.
-  mutable std::string MacosxVersionMin;
+  std::string MacosxVersionMin;
 
   /// The default iphoneos-version-min of this tool chain.
   std::string IPhoneOSVersionMin;
index e69a8447c4a7c252e5df486479136e2405e7c75b..84533a62524652fbf0033cdd9ed77c6f5c8ba960 100644 (file)
@@ -1,6 +1,23 @@
-// RUN: env MACOSX_DEPLOYMENT_TARGET=10.1 %clang -ccc-host-triple i386-apple-darwin9 -E %s
-
+// RUN: env MACOSX_DEPLOYMENT_TARGET=10.1 \
+// RUN:   %clang -ccc-host-triple i386-apple-darwin9 -DTEST0 -E %s
+#ifdef TEST0
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010
 #error Invalid version
 #endif
+#endif
 
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=2.0 \
+// RUN:   %clang -ccc-host-triple i386-apple-darwin9 -DTEST1 -E %s
+#ifdef TEST1
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ != 20000
+#error Invalid version
+#endif
+#endif
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=2.3.1 \
+// RUN:   %clang -ccc-host-triple i386-apple-darwin9 -DTEST2 -E %s
+#ifdef TEST2
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ != 20301
+#error Invalid version
+#endif
+#endif