This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Set linkPath and MSVT version when cl.exe is detected.
AbandonedPublic

Authored by hintonda on Aug 17 2017, 12:18 PM.

Details

Reviewers
STL_MSFT
Summary

Set linkPath and MSVT version when cl.exe is found in PATH.

Event Timeline

hintonda created this revision.Aug 17 2017, 12:18 PM
hintonda updated this revision to Diff 111551.Aug 17 2017, 1:10 PM
  • Cleanup path variables and make sure loop exits.
STL_MSFT edited edge metadata.Aug 17 2017, 5:23 PM

If I deal with the include vs. inc problem (in the debugger, by manually controlling which branch is taken), MSVCToolChain::getSubDirectoryPath() is problematic (as I described in my emails). Now, IsVS2017OrNewer is set, which causes it to form C:\Temp\binaries\x86ret\bin\HostX86\x86, which isn't the correct C:\Temp\binaries\x86ret\bin\i386 (where cl.exe was found).

lib/Driver/ToolChains/MSVC.cpp
138

This doesn't work for my dev build's directory structure, because the bin and inc subdirectories are siblings - there's no include subdirectory.

I additionally observe that this loop is very aggressive about looking for include, going all the way out to C:\include. Maybe this isn't a problem in practice (it isn't a problem for me).

If I deal with the include vs. inc problem (in the debugger, by manually controlling which branch is taken), MSVCToolChain::getSubDirectoryPath() is problematic (as I described in my emails). Now, IsVS2017OrNewer is set, which causes it to form C:\Temp\binaries\x86ret\bin\HostX86\x86, which isn't the correct C:\Temp\binaries\x86ret\bin\i386 (where cl.exe was found).

When is getSubDirectoryPath() getting called? The goal was obviate the need by caching libPath. Which other cases are needed? Btw, I'm assuming you set the variables LIB, etc...

Can you suggest an alternative to the way I'm attempting to find the root directory -- looking for "include" is obviously not the best idea. Would the old way be better?

When is getSubDirectoryPath() getting called?

It's getting called after MSVCToolChain::findVCToolChainViaEnvironment(). The callstack is when clang::driver::tools::Clang::ConstructJob() calls clang::driver::toolchains::MSVCToolChain::computeMSVCVersion(). That contains the line MSVT = getMSVCVersionFromExe(getSubDirectoryPath(SubDirectoryType::Bin));.

I'm currently seeing whether MSVCToolChain::getSubDirectoryPath() can inspect this->MSVT and if it's non-empty (which is the case when I get past inc vs. include), just return that.

The goal was obviate the need by caching libPath. Which other cases are needed?

One problem seems to be that the linkPath caching is entirely unused.

Btw, I'm assuming you set the variables LIB, etc...

Yes, both INCLUDE and LIB are set in my repro.

Can you suggest an alternative to the way I'm attempting to find the root directory -- looking for "include" is obviously not the best idea. Would the old way be better?

I haven't carefully thought about it, but my first impulse would be to try all three forms: pre-2017, 2017+, and internal-dev.

I am currently building a hacky patch that just checks for either include or inc. That gets me past that point.

lib/Driver/ToolChains/MSVC.cpp
438

I think you intended for the new data member linkPath in MSVCToolChain to be used. However, we're in clang::driver::tools::visualstudio::Linker::ConstructJob() and these mentions of linkPath are referring to this local variable. I can't find any actual reads of the data member.

hintonda abandoned this revision.Aug 17 2017, 8:33 PM

This isn't really a good approach.