diff options
author | Reid Kleckner <rnk@google.com> | 2017-02-02 19:29:46 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-02-02 19:29:46 +0000 |
commit | 723fabfcdf08968ea3534ca5993afa38b749925b (patch) | |
tree | 46dbe3f29f436bd40ae180b649deff0c0a179eec /clang/lib/Driver/Tools.cpp | |
parent | b89f2d3d92477049c3b3d7a79752860b2ed4d59c (diff) | |
download | llvm-723fabfcdf08968ea3534ca5993afa38b749925b.zip llvm-723fabfcdf08968ea3534ca5993afa38b749925b.tar.gz llvm-723fabfcdf08968ea3534ca5993afa38b749925b.tar.bz2 |
[Driver] Updated for Visual Studio 2017
Summary:
The patch updates the MSVC ToolChain for the changes made in Visual
Studio 2017[1].
Other notable changes:
- Path handling code has been centralised to make potential future
changes less painful.
- A compiler error is emitted if the driver is unable to locate a
usable MSVC toolchain. (Previously it'd fail with a cryptic error
such as "link.exe is not executable")
- Support for the new Setup Config Server API[2] has been added,
albeit block commented out with a preprocessor conditional. This can
probably be re-evaluated when the API is officially released (it's
currently at the RC stage), but it's left in to make it easy for
anyone familiar with the API to give it a go with Clang.
Patch by Hamza Sood.
[1] https://blogs.msdn.microsoft.com/vcblog/2016/10/07/compiler-tools-layout-in-visual-studio-15/
[2] https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/
Reviewers: ruiu, hans, rnk
Reviewed By: rnk
Subscribers: awson, RKSimon, amccarth, cfe-commits
Differential Revision: https://reviews.llvm.org/D28365
llvm-svn: 293923
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 63 |
1 files changed, 18 insertions, 45 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 910b510..29eb9a2 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -10888,19 +10888,12 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, // making sure that whatever executable that's found is not a same-named exe // from clang itself to prevent clang from falling back to itself. static std::string FindVisualStudioExecutable(const ToolChain &TC, - const char *Exe, - const char *ClangProgramPath) { + const char *Exe) { const auto &MSVC = static_cast<const toolchains::MSVCToolChain &>(TC); - std::string visualStudioBinDir; - if (MSVC.getVisualStudioBinariesFolder(ClangProgramPath, - visualStudioBinDir)) { - SmallString<128> FilePath(visualStudioBinDir); - llvm::sys::path::append(FilePath, Exe); - if (llvm::sys::fs::can_execute(FilePath.c_str())) - return FilePath.str(); - } - - return Exe; + SmallString<128> FilePath(MSVC.getSubDirectoryPath(toolchains::MSVCToolChain + ::SubDirectoryType::Bin)); + llvm::sys::path::append(FilePath, Exe); + return (llvm::sys::fs::can_execute(FilePath) ? FilePath.str() : Exe); } void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -10909,7 +10902,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, const ArgList &Args, const char *LinkingOutput) const { ArgStringList CmdArgs; - const ToolChain &TC = getToolChain(); + auto &TC = static_cast<const toolchains::MSVCToolChain &>(getToolChain()); assert((Output.isFilename() || Output.isNothing()) && "invalid output"); if (Output.isFilename()) @@ -10925,37 +10918,20 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, // did not run vcvarsall), try to build a consistent link environment. If // the environment variable is set however, assume the user knows what // they're doing. - std::string VisualStudioDir; - const auto &MSVC = static_cast<const toolchains::MSVCToolChain &>(TC); - if (MSVC.getVisualStudioInstallDir(VisualStudioDir)) { - SmallString<128> LibDir(VisualStudioDir); - llvm::sys::path::append(LibDir, "VC", "lib"); - switch (MSVC.getArch()) { - case llvm::Triple::x86: - // x86 just puts the libraries directly in lib - break; - case llvm::Triple::x86_64: - llvm::sys::path::append(LibDir, "amd64"); - break; - case llvm::Triple::arm: - llvm::sys::path::append(LibDir, "arm"); - break; - default: - break; - } - CmdArgs.push_back( - Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); + CmdArgs.push_back(Args.MakeArgString( + std::string("-libpath:") + + TC.getSubDirectoryPath(toolchains::MSVCToolChain + ::SubDirectoryType::Lib))); - if (MSVC.useUniversalCRT(VisualStudioDir)) { - std::string UniversalCRTLibPath; - if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) - CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + - UniversalCRTLibPath)); - } + if (TC.useUniversalCRT()) { + std::string UniversalCRTLibPath; + if (TC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) + CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath)); } std::string WindowsSdkLibPath; - if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) + if (TC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) CmdArgs.push_back( Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath)); } @@ -11079,8 +11055,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, // If we're using the MSVC linker, it's not sufficient to just use link // from the program PATH, because other environments like GnuWin32 install // their own link.exe which may come first. - linkPath = FindVisualStudioExecutable(TC, "link.exe", - C.getDriver().getClangProgramPath()); + linkPath = FindVisualStudioExecutable(TC, "link.exe"); } else { linkPath = Linker; llvm::sys::path::replace_extension(linkPath, "exe"); @@ -11213,9 +11188,7 @@ std::unique_ptr<Command> visualstudio::Compiler::GetCommand( Args.MakeArgString(std::string("/Fo") + Output.getFilename()); CmdArgs.push_back(Fo); - const Driver &D = getToolChain().getDriver(); - std::string Exec = FindVisualStudioExecutable(getToolChain(), "cl.exe", - D.getClangProgramPath()); + std::string Exec = FindVisualStudioExecutable(getToolChain(), "cl.exe"); return llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), CmdArgs, Inputs); } |