Do not push empty string as a command argument, it breaks on Linux. (#174)

This commit is contained in:
Tian Jin 2020-06-18 21:04:55 +08:00 committed by GitHub
parent 82d2caa542
commit b28fcbc745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -56,6 +56,13 @@ struct Command {
return *this; return *this;
} }
// Append a single optional string argument.
Command &appendStrOpt(const llvm::Optional<std::string> &arg) {
if (arg.hasValue())
_args.emplace_back(arg.getValue());
return *this;
}
// Append a list of string arguments. // Append a list of string arguments.
Command &appendList(const std::vector<std::string> &args) { Command &appendList(const std::vector<std::string> &args) {
_args.insert(_args.end(), args.begin(), args.end()); _args.insert(_args.end(), args.begin(), args.end());
@ -218,7 +225,7 @@ void compileModuleToSharedLibrary(
std::string modelObjPath = outputBaseName + ".o"; std::string modelObjPath = outputBaseName + ".o";
llvm::FileRemover modelObjRemover(modelObjPath); llvm::FileRemover modelObjRemover(modelObjPath);
std::string runtimeDirInclFlag; llvm::Optional<std::string> runtimeDirInclFlag;
if (getEnvVar("RUNTIME_DIR").hasValue()) if (getEnvVar("RUNTIME_DIR").hasValue())
runtimeDirInclFlag = "-L" + getEnvVar("RUNTIME_DIR").getValue(); runtimeDirInclFlag = "-L" + getEnvVar("RUNTIME_DIR").getValue();
@ -228,7 +235,7 @@ void compileModuleToSharedLibrary(
.appendStr(modelObjPath) .appendStr(modelObjPath)
.appendStr(constPackObjPath.getValueOr("")) .appendStr(constPackObjPath.getValueOr(""))
.appendList({"-o", outputBaseName + ".so"}) .appendList({"-o", outputBaseName + ".so"})
.appendStr(runtimeDirInclFlag) .appendStrOpt(runtimeDirInclFlag)
.appendList({"-lEmbeddedDataLoader", "-lcruntime"}) .appendList({"-lEmbeddedDataLoader", "-lcruntime"})
.exec(); .exec();
} }