aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-ml/llvm-ml.cpp
diff options
context:
space:
mode:
authorEric Astor <epastor@google.com>2021-06-09 16:05:12 -0400
committerEric Astor <epastor@google.com>2021-06-09 17:54:40 -0400
commit4b5317e937ac5c87c30a67bc76a4e253c2c3516c (patch)
tree51f204c36e666a9ccdf39f77a54975277a7c579b /llvm/tools/llvm-ml/llvm-ml.cpp
parent1b21e9c1fa990a303fa5a543c17a5f470a32e112 (diff)
downloadllvm-4b5317e937ac5c87c30a67bc76a4e253c2c3516c.zip
llvm-4b5317e937ac5c87c30a67bc76a4e253c2c3516c.tar.gz
llvm-4b5317e937ac5c87c30a67bc76a4e253c2c3516c.tar.bz2
[ms] [llvm-ml] Add support for INCLUDE environment variable
Also adds support for the ML.exe command-line flag /X, which ignores the INCLUDE environment variable. This relands commit c43f413b01b021a8f7b6fce013296114fa92a245 using lit's cross-platform `env` support. Differential Revision: https://reviews.llvm.org/D103989
Diffstat (limited to 'llvm/tools/llvm-ml/llvm-ml.cpp')
-rw-r--r--llvm/tools/llvm-ml/llvm-ml.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index 14f75d0..1a66862 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -36,6 +36,7 @@
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
@@ -263,8 +264,21 @@ int main(int Argc, char **Argv) {
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
// Record the location of the include directories so that the lexer can find
- // it later.
- SrcMgr.setIncludeDirs(InputArgs.getAllArgValues(OPT_include_path));
+ // included files later.
+ std::vector<std::string> IncludeDirs =
+ InputArgs.getAllArgValues(OPT_include_path);
+ if (!InputArgs.hasArg(OPT_ignore_include_envvar)) {
+ if (llvm::Optional<std::string> IncludeEnvVar =
+ llvm::sys::Process::GetEnv("INCLUDE")) {
+ SmallVector<StringRef, 8> Dirs;
+ StringRef(*IncludeEnvVar)
+ .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+ IncludeDirs.reserve(IncludeDirs.size() + Dirs.size());
+ for (StringRef Dir : Dirs)
+ IncludeDirs.push_back(Dir.str());
+ }
+ }
+ SrcMgr.setIncludeDirs(IncludeDirs);
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
assert(MRI && "Unable to create target register info!");