[pkg-d-commits] [ldc] 51/95: Slightly refactor module driver/tool
Matthias Klumpp
mak at moszumanska.debian.org
Thu Jul 13 20:53:59 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.
commit 1c70b12e4cbb7fd7bab7444ba828df6e8a7b0021
Author: Martin <noone at nowhere.com>
Date: Mon Mar 13 23:51:13 2017 +0100
Slightly refactor module driver/tool
And get rid of redundant cmdline option -archiver.
---
driver/linker.cpp | 16 ++++++----------
driver/tool.cpp | 21 ++++++---------------
driver/tool.h | 7 ++++++-
3 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/driver/linker.cpp b/driver/linker.cpp
index 52fa84a..114023a 100644
--- a/driver/linker.cpp
+++ b/driver/linker.cpp
@@ -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
diff --git a/driver/tool.cpp b/driver/tool.cpp
index 9d4487f..f9075dd 100644
--- a/driver/tool.cpp
+++ b/driver/tool.cpp
@@ -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;
}
diff --git a/driver/tool.h b/driver/tool.h
index b966e40..4482621 100644
--- a/driver/tool.h
+++ b/driver/tool.h
@@ -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,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list