void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine,
StringRef InvokedAs) {
- if (!CommandLine.empty() && !InvokedAs.empty()) {
- bool AlreadyHasTarget = false;
- bool AlreadyHasMode = false;
- // Skip CommandLine[0].
- for (auto Token = ++CommandLine.begin(); Token != CommandLine.end();
- ++Token) {
- StringRef TokenRef(*Token);
- AlreadyHasTarget |=
- (TokenRef == "-target" || TokenRef.startswith("-target="));
- AlreadyHasMode |= (TokenRef == "--driver-mode" ||
- TokenRef.startswith("--driver-mode="));
- }
- auto TargetMode =
- driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs);
- if (!AlreadyHasMode && TargetMode.DriverMode) {
- CommandLine.insert(++CommandLine.begin(), TargetMode.DriverMode);
- }
- if (!AlreadyHasTarget && TargetMode.TargetIsValid) {
- CommandLine.insert(++CommandLine.begin(), {"-target",
- TargetMode.TargetPrefix});
- }
+ if (CommandLine.empty() || InvokedAs.empty())
+ return;
+ const auto &Table = driver::getDriverOptTable();
+ // --target=X
+ const std::string TargetOPT =
+ Table.getOption(driver::options::OPT_target).getPrefixedName();
+ // -target X
+ const std::string TargetOPTLegacy =
+ Table.getOption(driver::options::OPT_target_legacy_spelling)
+ .getPrefixedName();
+ // --driver-mode=X
+ const std::string DriverModeOPT =
+ Table.getOption(driver::options::OPT_driver_mode).getPrefixedName();
+ bool AlreadyHasTarget = false;
+ bool AlreadyHasMode = false;
+ // Skip CommandLine[0].
+ for (auto Token = ++CommandLine.begin(); Token != CommandLine.end();
+ ++Token) {
+ StringRef TokenRef(*Token);
+ AlreadyHasTarget |=
+ TokenRef.startswith(TargetOPT) || TokenRef.equals(TargetOPTLegacy);
+ AlreadyHasMode |= TokenRef.startswith(DriverModeOPT);
+ }
+ auto TargetMode =
+ driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs);
+ if (!AlreadyHasMode && TargetMode.DriverMode) {
+ CommandLine.insert(++CommandLine.begin(), TargetMode.DriverMode);
+ }
+ if (!AlreadyHasTarget && TargetMode.TargetIsValid) {
+ CommandLine.insert(++CommandLine.begin(),
+ TargetOPT + TargetMode.TargetPrefix);
}
}
addTargetAndModeForProgramName(Args, "");
EXPECT_EQ((std::vector<std::string>{"clang", "-foo"}), Args);
addTargetAndModeForProgramName(Args, Target + "-g++");
- EXPECT_EQ((std::vector<std::string>{"clang", "-target", Target,
+ EXPECT_EQ((std::vector<std::string>{"clang", "--target=" + Target,
"--driver-mode=g++", "-foo"}),
Args);
}
std::vector<std::string> Args = {"clang", "-foo"};
addTargetAndModeForProgramName(Args, ToolPath);
- EXPECT_EQ((std::vector<std::string>{"clang", "-target", Target,
+ EXPECT_EQ((std::vector<std::string>{"clang", "--target=" + Target,
"--driver-mode=g++", "-foo"}),
Args);
}
"-target", "something"}),
Args);
- std::vector<std::string> ArgsAlt = {"clang", "-foo", "-target=something"};
+ std::vector<std::string> ArgsAlt = {"clang", "-foo", "--target=something"};
addTargetAndModeForProgramName(ArgsAlt, Target + "-g++");
EXPECT_EQ((std::vector<std::string>{"clang", "--driver-mode=g++", "-foo",
- "-target=something"}),
+ "--target=something"}),
ArgsAlt);
}
std::vector<std::string> Args = {"clang", "-foo", "--driver-mode=abc"};
addTargetAndModeForProgramName(Args, Target + "-g++");
- EXPECT_EQ((std::vector<std::string>{"clang", "-target", Target, "-foo",
+ EXPECT_EQ((std::vector<std::string>{"clang", "--target=" + Target, "-foo",
"--driver-mode=abc"}),
Args);
-
- std::vector<std::string> ArgsAlt = {"clang", "-foo", "--driver-mode", "abc"};
- addTargetAndModeForProgramName(ArgsAlt, Target + "-g++");
- EXPECT_EQ((std::vector<std::string>{"clang", "-target", Target, "-foo",
- "--driver-mode", "abc"}),
- ArgsAlt);
}
#ifndef _WIN32