Commit ba00de65 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r243098, r243101, r243105, r243144, and r243153.

------------------------------------------------------------------------
r243098 | yrnkrn | 2015-07-24 01:50:15 -0700 (Fri, 24 Jul 2015) | 7 lines

Add extensive tests for the mingw toolchain and remove trailing slash from Arch.

Address Richard Smith comments: remove the trailing seperator from the Arch
variable, implement six mingw_* trees under tools/clangtest/Driver/Inputs
and merge linux and Windows tests into a universal test that uses these trees.
------------------------------------------------------------------------

------------------------------------------------------------------------
r243101 | yrnkrn | 2015-07-24 02:31:57 -0700 (Fri, 24 Jul 2015) | 3 lines

Try to appease clang buildbot by forcing libstdc++ in mingw.cpp test.
------------------------------------------------------------------------

------------------------------------------------------------------------
r243105 | yrnkrn | 2015-07-24 04:01:45 -0700 (Fri, 24 Jul 2015) | 4 lines

Apparently some of the bots add .svn dirs inside the test/Driver/Inputs 
directory structure. Try to make mingw toolchain resilient to such surprises.
------------------------------------------------------------------------

------------------------------------------------------------------------
r243144 | yrnkrn | 2015-07-24 12:18:17 -0700 (Fri, 24 Jul 2015) | 5 lines

Base the sys-root/mingw/include path on sysroot and not on /usr.

Thanks to Richard Smith for pointing this out!
------------------------------------------------------------------------

------------------------------------------------------------------------
r243153 | yrnkrn | 2015-07-24 13:18:27 -0700 (Fri, 24 Jul 2015) | 4 lines

Select the highest version of the mingw toolchain found using Generic_GCC::GCCVersion
similar to the way Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple works.
------------------------------------------------------------------------

llvm-svn: 243325
parent dc75a9da
Loading
Loading
Loading
Loading
+79 −71
Original line number Diff line number Diff line
@@ -20,28 +20,44 @@ using namespace clang::driver::toolchains;
using namespace clang;
using namespace llvm::opt;

namespace {
// Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple.
bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
                    std::string &Ver) {
  Generic_GCC::GCCVersion Version = Generic_GCC::GCCVersion::Parse("0.0.0");
  std::error_code EC;
  for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && LI != LE;
       LI = LI.increment(EC)) {
    StringRef VersionText = llvm::sys::path::filename(LI->path());
    Generic_GCC::GCCVersion CandidateVersion =
        Generic_GCC::GCCVersion::Parse(VersionText);
    if (CandidateVersion.Major == -1)
      continue;
    if (CandidateVersion <= Version)
      continue;
    Ver = VersionText;
    GccLibDir = LI->path();
  }
  return Ver.size();
}
}

void MinGW::findGccLibDir() {
  llvm::SmallVector<llvm::SmallString<32>, 2> Archs;
  Archs.emplace_back(getTriple().getArchName());
  Archs[0] += "-w64-mingw32";
  Archs.emplace_back("mingw32");
  Arch = "unknown";
  // lib: Arch Linux, Ubuntu, Windows
  // lib64: openSUSE Linux
  llvm::SmallString<1024> LibDir;
  for (StringRef Lib : {"lib", "lib64"}) {
    LibDir = Base;
    llvm::sys::path::append(LibDir, Lib, "gcc");
    LibDir += llvm::sys::path::get_separator();
    std::error_code EC;
    // First look for mingw-w64.
    llvm::sys::fs::directory_iterator MingW64Entry(LibDir + Arch, EC);
    if (!EC) {
      GccLibDir = MingW64Entry->path();
      break;
  for (StringRef CandidateLib : {"lib", "lib64"}) {
    for (StringRef CandidateArch : Archs) {
      llvm::SmallString<1024> LibDir(Base);
      llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
      if (findGccVersion(LibDir, GccLibDir, Ver)) {
        Arch = CandidateArch;
        return;
      }
    // If mingw-w64 not found, try looking for mingw.org.
    llvm::sys::fs::directory_iterator MingwOrgEntry(LibDir + "mingw32", EC);
    if (!EC) {
      GccLibDir = MingwOrgEntry->path();
      // Replace Arch with mingw32 arch.
      Arch = "mingw32//";
      break;
    }
  }
}
@@ -50,10 +66,6 @@ MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
    : ToolChain(D, Triple, Args) {
  getProgramPaths().push_back(getDriver().getInstalledDir());

  // Default Arch is mingw-w64.
  Arch = (getTriple().getArchName() + "-w64-mingw32" +
          llvm::sys::path::get_separator()).str();

// In Windows there aren't any standard install locations, we search
// for gcc on the PATH. In Linux the base is always /usr.
#ifdef LLVM_ON_WIN32
@@ -66,25 +78,22 @@ MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
  else
    Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
#else
  if (getDriver().SysRoot.size())
    Base = getDriver().SysRoot;
  else
    Base = "/usr";
#endif

  Base += llvm::sys::path::get_separator();
  if (getDriver().SysRoot.size())
    GccLibDir = getDriver().SysRoot;
  else
  findGccLibDir();
  Ver = llvm::sys::path::filename(GccLibDir);
  // GccLibDir must precede Base/lib so that the
  // correct crtbegin.o ,cetend.o would be found.
  getFilePaths().push_back(GccLibDir);
  getFilePaths().push_back(Base + Arch + "lib");
#ifdef LLVM_ON_WIN32
  getFilePaths().push_back(
      (Base + Arch + llvm::sys::path::get_separator() + "lib").str());
  getFilePaths().push_back(Base + "lib");
#else
  // openSUSE
  getFilePaths().push_back(Base + Arch + "sys-root/mingw/lib");
#endif
  getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
}

bool MinGW::IsIntegratedAssemblerDefault() const { return true; }
@@ -197,14 +206,13 @@ void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
    llvm::sys::path::append(IncludeDir, "include");
    addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
    IncludeDir += "-fixed";
#ifdef LLVM_ON_UNIX
    // openSUSE
    addSystemInclude(DriverArgs, CC1Args,
                     "/usr/x86_64-w64-mingw32/sys-root/mingw/include");
#endif
                     Base + Arch + "/sys-root/mingw/include");
    addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
  }
  addSystemInclude(DriverArgs, CC1Args, Base + Arch + "include");
  addSystemInclude(DriverArgs, CC1Args,
                   Base + Arch + llvm::sys::path::get_separator() + "include");
  addSystemInclude(DriverArgs, CC1Args, Base + "include");
}

@@ -216,9 +224,9 @@ void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,

  switch (GetCXXStdlibType(DriverArgs)) {
  case ToolChain::CST_Libcxx:
    addSystemInclude(DriverArgs, CC1Args, Base        + "include" +
                     llvm::sys::path::get_separator() + "c++"     +
                     llvm::sys::path::get_separator() + "v1");
    addSystemInclude(DriverArgs, CC1Args,
                     Base + "include" + llvm::sys::path::get_separator() +
                         "c++" + llvm::sys::path::get_separator() + "v1");
    break;

  case ToolChain::CST_Libstdcxx:
@@ -232,8 +240,8 @@ void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
    CppIncludeBases.emplace_back(GccLibDir);
    llvm::sys::path::append(CppIncludeBases[3], "include", "c++");
    for (auto &CppIncludeBase : CppIncludeBases) {
      CppIncludeBase += llvm::sys::path::get_separator();
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
      CppIncludeBase += llvm::sys::path::get_separator();
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
    }
+2 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ namespace toolchains {
/// all subcommands; this relies on gcc translating the majority of
/// command line options.
class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
protected:
public:
  /// \brief Struct to store and manipulate GCC versions.
  ///
  /// We rely on assumptions about the form and structure of GCC version
@@ -147,6 +147,7 @@ protected:
                                bool NeedsBiarchSuffix = false);
  };

protected:
  GCCInstallationDetector GCCInstallation;

public:
Loading