Slightly refactor module driver/tool

And get rid of redundant cmdline option -archiver.
This commit is contained in:
Martin 2017-03-13 23:51:13 +01:00
parent 95c1d38e2e
commit 1c70b12e4c
3 changed files with 18 additions and 26 deletions

View file

@ -45,10 +45,8 @@ static llvm::cl::opt<std::string>
"LLVMgold.so (Unixes) or libLTO.dylib (Darwin))"),
llvm::cl::value_desc("file"), llvm::cl::ZeroOrMore);
static llvm::cl::opt<std::string>
externalArchiver("archiver",
llvm::cl::desc("External static library archiver"),
llvm::cl::value_desc("file"), llvm::cl::ZeroOrMore);
static llvm::cl::opt<std::string> ar("ar", llvm::cl::desc("Archiver"),
llvm::cl::Hidden, llvm::cl::ZeroOrMore);
//////////////////////////////////////////////////////////////////////////////
@ -286,7 +284,7 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
Logger::println("*** Linking executable ***");
// find gcc for linking
std::string gcc(getGcc());
const std::string tool = getGcc();
// build arguments
std::vector<std::string> args;
@ -486,7 +484,7 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
logstr << "\n"; // FIXME where's flush ?
// try to call linker
return executeToolAndWait(gcc, args, global.params.verbose);
return executeToolAndWait(tool, args, global.params.verbose);
}
//////////////////////////////////////////////////////////////////////////////
@ -622,7 +620,7 @@ int createStaticLibrary() {
global.params.targetTriple->isWindowsMSVCEnvironment();
#if LDC_LLVM_VER >= 309
const bool useInternalArchiver = externalArchiver.empty();
const bool useInternalArchiver = ar.empty();
#else
const bool useInternalArchiver = false;
#endif
@ -631,10 +629,8 @@ int createStaticLibrary() {
std::string tool;
if (useInternalArchiver) {
tool = isTargetMSVC ? "llvm-lib.exe" : "llvm-ar";
} else if (!externalArchiver.empty()) {
tool = externalArchiver;
} else {
tool = isTargetMSVC ? "lib.exe" : getArchiver();
tool = getProgram(isTargetMSVC ? "lib.exe" : "ar", &ar);
}
// build arguments

View file

@ -10,7 +10,6 @@
#include "driver/tool.h"
#include "mars.h"
#include "driver/exe_path.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@ -25,14 +24,9 @@ static llvm::cl::opt<std::string>
gcc("gcc", llvm::cl::desc("GCC to use for assembling and linking"),
llvm::cl::Hidden, llvm::cl::ZeroOrMore);
static llvm::cl::opt<std::string> ar("ar", llvm::cl::desc("Archiver"),
llvm::cl::Hidden, llvm::cl::ZeroOrMore);
//////////////////////////////////////////////////////////////////////////////
namespace {
std::string findProgramByName(llvm::StringRef name) {
static std::string findProgramByName(llvm::StringRef name) {
#if LDC_LLVM_VER >= 306
llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name);
return res ? res.get() : std::string();
@ -41,9 +35,10 @@ std::string findProgramByName(llvm::StringRef name) {
#endif
}
std::string getProgram(const char *name,
const llvm::cl::opt<std::string> *opt = nullptr,
const char *envVar = nullptr) {
//////////////////////////////////////////////////////////////////////////////
std::string getProgram(const char *name, const llvm::cl::opt<std::string> *opt,
const char *envVar) {
std::string path;
const char *prog = nullptr;
@ -67,8 +62,6 @@ std::string getProgram(const char *name,
return path;
}
} // anonymous namespace
////////////////////////////////////////////////////////////////////////////////
std::string getGcc() {
@ -80,15 +73,13 @@ std::string getGcc() {
#endif
}
std::string getArchiver() { return getProgram("ar", &ar); }
////////////////////////////////////////////////////////////////////////////////
int executeToolAndWait(const std::string &tool_,
std::vector<std::string> const &args, bool verbose) {
const auto tool = findProgramByName(tool_);
if (tool.empty()) {
error(Loc(), "failed to locate binary %s", tool_.c_str());
error(Loc(), "failed to locate %s", tool_.c_str());
return -1;
}

View file

@ -18,8 +18,13 @@
#include <vector>
#include <string>
#include "llvm/Support/CommandLine.h"
std::string getGcc();
std::string getArchiver();
std::string getProgram(const char *name,
const llvm::cl::opt<std::string> *opt = nullptr,
const char *envVar = nullptr);
int executeToolAndWait(const std::string &tool,
std::vector<std::string> const &args,