From 70e73a3d60b77a1001c97ba2f640f828a695bbfe Mon Sep 17 00:00:00 2001 From: Dylan Noblesmith Date: Sat, 9 Apr 2011 13:31:59 +0000 Subject: [PATCH] refactor -ccc-gcc-name code Put the logic for deciding the default name for gcc/g++ in the only place that actually cares about it. This also pushes an ifdef out of the generic driver code to a little further down, when the target is actually known. Hopefully it can be changed into just a runtime check in the future. llvm-svn: 129212 --- clang/include/clang/Driver/Driver.h | 4 ++-- clang/lib/Driver/Driver.cpp | 16 +--------------- clang/lib/Driver/Tools.cpp | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 56afa02b30db..5a7d830b069d 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -135,7 +135,7 @@ public: unsigned CCLogDiagnostics : 1; private: - /// Name to use when calling the generic gcc. + /// Name to use when invoking gcc/g++. std::string CCCGenericGCCName; /// Whether to check that input files exist when constructing compilation @@ -183,7 +183,7 @@ public: /// @name Accessors /// @{ - /// Name to use when calling the generic gcc. + /// Name to use when invoking gcc/g++. const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 78720ed0b3cc..a3c93bd88c9d 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -43,13 +43,6 @@ #include -#ifdef __CYGWIN__ -#include -#if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007 -#define IS_CYGWIN15 1 -#endif -#endif - using namespace clang::driver; using namespace clang; @@ -67,7 +60,7 @@ Driver::Driver(llvm::StringRef _ClangExecutable, CCLogDiagnosticsFilename(0), CCCIsCXX(false), CCCIsCPP(false),CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), - CCCGenericGCCName("gcc"), CheckInputsExist(true), CCCUseClang(true), + CCCGenericGCCName(""), CheckInputsExist(true), CCCUseClang(true), CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true), SuppressMissingInputWarning(false) { if (IsProduction) { @@ -238,13 +231,6 @@ Compilation *Driver::BuildCompilation(llvm::ArrayRef ArgList) { CCCPrintActions = Args->hasArg(options::OPT_ccc_print_phases); CCCPrintBindings = Args->hasArg(options::OPT_ccc_print_bindings); CCCIsCXX = Args->hasArg(options::OPT_ccc_cxx) || CCCIsCXX; - if (CCCIsCXX) { -#ifdef IS_CYGWIN15 - CCCGenericGCCName = "g++-4"; -#else - CCCGenericGCCName = "g++"; -#endif - } CCCEcho = Args->hasArg(options::OPT_ccc_echo); if (const Arg *A = Args->getLastArg(options::OPT_ccc_gcc_name)) CCCGenericGCCName = A->getValue(*Args); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index fa7896766d40..20120372974e 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -34,6 +34,13 @@ #include "InputInfo.h" #include "ToolChains.h" +#ifdef __CYGWIN__ +#include +#if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007 +#define IS_CYGWIN15 1 +#endif +#endif + using namespace clang::driver; using namespace clang::driver::tools; @@ -2065,7 +2072,20 @@ void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, } } - const char *GCCName = getToolChain().getDriver().getCCCGenericGCCName().c_str(); + const std::string customGCCName = D.getCCCGenericGCCName(); + const char *GCCName; + if (!customGCCName.empty()) + GCCName = customGCCName.c_str(); + else if (D.CCCIsCXX) { +#ifdef IS_CYGWIN15 + // FIXME: Detect the version of Cygwin at runtime? + GCCName = "g++-4"; +#else + GCCName = "g++"; +#endif + } else + GCCName = "gcc"; + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); C.addCommand(new Command(JA, *this, Exec, CmdArgs));