Commit 425cd167 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmLocalGenerator: Remove the launcher from RuleVariables

This one is not like the others as it doesn't participate in
substitutions.  Keep ExpandRuleVariables doing only one thing and make
callers responsible for inserting a launcher prefix, simplifying the
code all-around.

Remove now-obsolete InsertRuleLauncher method.
parent 0d818632
......@@ -767,10 +767,6 @@ std::string cmLocalGenerator::ExpandRuleVariable(
void cmLocalGenerator::ExpandRuleVariables(std::string& s,
const RuleVariables& replaceValues)
{
if (replaceValues.RuleLauncher) {
this->InsertRuleLauncher(s, replaceValues.CMTarget,
replaceValues.RuleLauncher);
}
std::string::size_type start = s.find('<');
// no variables to expand
if (start == s.npos) {
......@@ -814,17 +810,6 @@ const char* cmLocalGenerator::GetRuleLauncher(cmGeneratorTarget* target,
return this->Makefile->GetProperty(prop);
}
void cmLocalGenerator::InsertRuleLauncher(std::string& s,
cmGeneratorTarget* target,
const std::string& prop)
{
if (const char* val = this->GetRuleLauncher(target, prop)) {
std::ostringstream wrapped;
wrapped << val << " " << s;
s = wrapped.str();
}
}
std::string cmLocalGenerator::ConvertToIncludeReference(
std::string const& path, OutputFormat format, bool forceFullPaths)
{
......
......@@ -346,6 +346,13 @@ public:
void CreateEvaluationFileOutputs(const std::string& config);
void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
// Expand rule variables in CMake of the type found in language rules
void ExpandRuleVariables(std::string& string,
const RuleVariables& replaceValues);
const char* GetRuleLauncher(cmGeneratorTarget* target,
const std::string& prop);
protected:
///! put all the libraries for a target on into the given stream
void OutputLinkLibraries(cmComputeLinkInformation* pcli,
......@@ -353,18 +360,10 @@ protected:
std::string& linkLibraries,
std::string& frameworkPath, std::string& linkPath);
// Expand rule variables in CMake of the type found in language rules
void ExpandRuleVariables(std::string& string,
const RuleVariables& replaceValues);
// Expand rule variables in a single string
std::string ExpandRuleVariable(std::string const& variable,
const RuleVariables& replaceValues);
const char* GetRuleLauncher(cmGeneratorTarget* target,
const std::string& prop);
void InsertRuleLauncher(std::string& s, cmGeneratorTarget* target,
const std::string& prop);
// Handle old-style install rules stored in the targets.
void GenerateTargetInstallRules(
std::ostream& os, const std::string& config,
......
......@@ -468,8 +468,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
std::string cmLocalNinjaGenerator::MakeCustomLauncher(
cmCustomCommandGenerator const& ccg)
{
const char* property = "RULE_LAUNCH_CUSTOM";
const char* property_value = this->Makefile->GetProperty(property);
const char* property_value =
this->Makefile->GetProperty("RULE_LAUNCH_CUSTOM");
if (!property_value || !*property_value) {
return std::string();
......@@ -478,7 +478,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
// Expand rules in the empty string. It may insert the launcher and
// perform replacements.
RuleVariables vars;
vars.RuleLauncher = property;
std::string output;
const std::vector<std::string>& outputs = ccg.GetOutputs();
if (!outputs.empty()) {
......@@ -491,7 +491,9 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
}
vars.Output = output.c_str();
std::string launcher;
std::string launcher = property_value;
launcher += " ";
this->ExpandRuleVariables(launcher, vars);
if (!launcher.empty()) {
launcher += " ";
......
......@@ -58,12 +58,6 @@ public:
return this->HomeRelativeOutputPath;
}
void ExpandRuleVariables(std::string& string,
const RuleVariables& replaceValues)
{
cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
}
std::string BuildCommandLine(const std::vector<std::string>& cmdLines);
void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
......
......@@ -984,13 +984,11 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
std::string launcher;
// Short-circuit if there is no launcher.
const char* prop = "RULE_LAUNCH_CUSTOM";
const char* val = this->GetRuleLauncher(target, prop);
const char* val = this->GetRuleLauncher(target, "RULE_LAUNCH_CUSTOM");
if (val && *val) {
// Expand rules in the empty string. It may insert the launcher and
// perform replacements.
RuleVariables vars;
vars.RuleLauncher = prop;
vars.CMTarget = target;
std::string output;
const std::vector<std::string>& outputs = ccg.GetOutputs();
......@@ -1005,6 +1003,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
}
vars.Output = output.c_str();
launcher = val;
launcher += " ";
this->ExpandRuleVariables(launcher, vars);
if (!launcher.empty()) {
launcher += " ";
......
......@@ -332,7 +332,6 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
std::string manifests = this->GetManifests();
cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->GeneratorTarget;
vars.Language = linkLanguage.c_str();
vars.Objects = buildObjs.c_str();
......@@ -383,10 +382,20 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
real_link_commands.push_back(cmakeCommand);
}
std::string launcher;
const char* val = this->LocalGenerator->GetRuleLauncher(
this->GeneratorTarget, "RULE_LAUNCH_LINK");
if (val && *val) {
launcher = val;
launcher += " ";
}
// Expand placeholders in the commands.
this->LocalGenerator->TargetImplib = targetOutPathImport;
for (std::vector<std::string>::iterator i = real_link_commands.begin();
i != real_link_commands.end(); ++i) {
*i = launcher + *i;
this->LocalGenerator->ExpandRuleVariables(*i, vars);
}
this->LocalGenerator->TargetImplib = "";
......
......@@ -540,7 +540,6 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.TargetVersionMajor = targetVersionMajor.c_str();
vars.TargetVersionMinor = targetVersionMinor.c_str();
vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->GeneratorTarget;
vars.Language = linkLanguage.c_str();
vars.Objects = buildObjs.c_str();
......@@ -597,6 +596,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.LanguageCompileFlags = langFlags.c_str();
std::string launcher;
const char* val = this->LocalGenerator->GetRuleLauncher(
this->GeneratorTarget, "RULE_LAUNCH_LINK");
if (val && *val) {
launcher = val;
launcher += " ";
}
// Construct the main link rule and expand placeholders.
this->LocalGenerator->TargetImplib = targetOutPathImport;
if (useArchiveRules) {
......@@ -611,7 +618,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveCreateCommands.begin();
i != archiveCreateCommands.end(); ++i) {
std::string cmd = *i;
std::string cmd = launcher + *i;
this->LocalGenerator->ExpandRuleVariables(cmd, vars);
real_link_commands.push_back(cmd);
}
......@@ -622,7 +629,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveAppendCommands.begin();
i != archiveAppendCommands.end(); ++i) {
std::string cmd = *i;
std::string cmd = launcher + *i;
this->LocalGenerator->ExpandRuleVariables(cmd, vars);
real_link_commands.push_back(cmd);
}
......@@ -632,7 +639,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveFinishCommands.begin();
i != archiveFinishCommands.end(); ++i) {
std::string cmd = *i;
std::string cmd = launcher + *i;
this->LocalGenerator->ExpandRuleVariables(cmd, vars);
// If there is no ranlib the command will be ":". Skip it.
if (!cmd.empty() && cmd[0] != ':') {
......@@ -655,6 +662,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Expand placeholders.
for (std::vector<std::string>::iterator i = real_link_commands.begin();
i != real_link_commands.end(); ++i) {
*i = launcher + *i;
this->LocalGenerator->ExpandRuleVariables(*i, vars);
}
}
......
......@@ -168,7 +168,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->GetGeneratorTarget();
vars.Language = this->TargetLinkLanguage.c_str();
......@@ -238,10 +237,19 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
vars.LanguageCompileFlags = langFlags.c_str();
}
std::string launcher;
const char* val = this->GetLocalGenerator()->GetRuleLauncher(
this->GetGeneratorTarget(), "RULE_LAUNCH_LINK");
if (val && *val) {
launcher = val;
launcher += " ";
}
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeLinkCmd();
for (std::vector<std::string>::iterator i = linkCmds.begin();
i != linkCmds.end(); ++i) {
*i = launcher + *i;
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
}
{
......
......@@ -374,7 +374,6 @@ void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language)
void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
{
cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
vars.CMTarget = this->GetGeneratorTarget();
vars.Language = lang.c_str();
vars.Source = "$IN_ABS";
......@@ -456,6 +455,14 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
ConvertToNinjaPath(this->GetTargetDependInfoPath(lang)),
cmLocalGenerator::SHELL);
std::string launcher;
const char* val = this->GetLocalGenerator()->GetRuleLauncher(
this->GetGeneratorTarget(), "RULE_LAUNCH_COMPILE");
if (val && *val) {
launcher = val;
launcher += " ";
}
if (explicitPP) {
// Lookup the explicit preprocessing rule.
std::string const ppVar = "CMAKE_" + lang + "_PREPROCESS_SOURCE";
......@@ -467,7 +474,6 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
std::string const ppDepfile = "$DEP_FILE";
cmLocalGenerator::RuleVariables ppVars;
ppVars.RuleLauncher = vars.RuleLauncher;
ppVars.CMTarget = vars.CMTarget;
ppVars.Language = vars.Language;
ppVars.Object = "$out"; // for RULE_LAUNCH_COMPILE
......@@ -496,6 +502,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
for (std::vector<std::string>::iterator i = ppCmds.begin();
i != ppCmds.end(); ++i) {
*i = launcher + *i;
this->GetLocalGenerator()->ExpandRuleVariables(*i, ppVars);
}
......@@ -608,6 +615,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
for (std::vector<std::string>::iterator i = compileCmds.begin();
i != compileCmds.end(); ++i) {
*i = launcher + *i;
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment