forked from OSchip/llvm-project
Use llvm::sys::Process::GetEnv() instead of ::getenv().
Process::GetEnv() uses GetEnvironmentVariableW, which is a Windows API to get an environment variable and is preferable over getenv(). llvm-svn: 190431
This commit is contained in:
parent
77d55f8abd
commit
5c532370d5
|
@ -13,7 +13,6 @@
|
||||||
///
|
///
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@ -21,11 +20,13 @@
|
||||||
#include "lld/Driver/WinLinkInputGraph.h"
|
#include "lld/Driver/WinLinkInputGraph.h"
|
||||||
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
|
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
|
||||||
|
|
||||||
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
#include "llvm/Option/Arg.h"
|
#include "llvm/Option/Arg.h"
|
||||||
#include "llvm/Option/Option.h"
|
#include "llvm/Option/Option.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/Process.h"
|
||||||
|
|
||||||
namespace lld {
|
namespace lld {
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Split the given string with spaces.
|
// Split the given string with spaces.
|
||||||
std::vector<std::string> splitArgList(std::string str) {
|
std::vector<std::string> splitArgList(const std::string &str) {
|
||||||
std::stringstream stream(str);
|
std::stringstream stream(str);
|
||||||
std::istream_iterator<std::string> begin(stream);
|
std::istream_iterator<std::string> begin(stream);
|
||||||
std::istream_iterator<std::string> end;
|
std::istream_iterator<std::string> end;
|
||||||
|
@ -146,8 +147,9 @@ std::vector<const char *> processLinkEnv(PECOFFLinkingContext &context,
|
||||||
ret.push_back(argv[0]);
|
ret.push_back(argv[0]);
|
||||||
|
|
||||||
// Add arguments specified by the LINK environment variable.
|
// Add arguments specified by the LINK environment variable.
|
||||||
if (char *envp = ::getenv("LINK"))
|
llvm::Optional<std::string> env = llvm::sys::Process::GetEnv("LINK");
|
||||||
for (std::string &arg : splitArgList(envp))
|
if (env.hasValue())
|
||||||
|
for (std::string &arg : splitArgList(*env))
|
||||||
ret.push_back(context.allocateString(arg).data());
|
ret.push_back(context.allocateString(arg).data());
|
||||||
|
|
||||||
// Add the rest of arguments passed via the command line.
|
// Add the rest of arguments passed via the command line.
|
||||||
|
@ -160,8 +162,9 @@ std::vector<const char *> processLinkEnv(PECOFFLinkingContext &context,
|
||||||
// Process "LIB" environment variable. The variable contains a list of search
|
// Process "LIB" environment variable. The variable contains a list of search
|
||||||
// paths separated by semicolons.
|
// paths separated by semicolons.
|
||||||
void processLibEnv(PECOFFLinkingContext &context) {
|
void processLibEnv(PECOFFLinkingContext &context) {
|
||||||
if (char *envp = ::getenv("LIB"))
|
llvm::Optional<std::string> env = llvm::sys::Process::GetEnv("LIB");
|
||||||
for (StringRef path : splitPathList(envp))
|
if (env.hasValue())
|
||||||
|
for (StringRef path : splitPathList(*env))
|
||||||
context.appendInputSearchPath(context.allocateString(path));
|
context.appendInputSearchPath(context.allocateString(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue