From 816bc31ed45002de2547d6679b44f31eb85ec491 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 26 Jan 2010 01:45:19 +0000 Subject: [PATCH] Driver/Darwin: Honor IPHONEOS_DEPLOYMENT_TARGET. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94488 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 + lib/Driver/ToolChains.cpp | 42 ++++++++++++++------ lib/Driver/ToolChains.h | 6 ++- test/Driver/darwin-version.c | 21 +++++++++- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 8cdf85082b..aa1d95e424 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -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 ;">; +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">; diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index a9c6a68ceb..355dbe4052 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -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 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"); - 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(); + // 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)); + } } } diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 3ca6ad8897..89478d5f15 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -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; diff --git a/test/Driver/darwin-version.c b/test/Driver/darwin-version.c index e69a8447c4..84533a6252 100644 --- a/test/Driver/darwin-version.c +++ b/test/Driver/darwin-version.c @@ -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