Browse Source

cmLocalGenerator: Use a converter in rule replacement API

The rule replacement API should not really be in cmLocalGenerator, but
it was historically, and this coupled many other things together here
too, such as output conversion.  Make the output converter a parameter
so that rule replacement can be removed from cmLocalGenerator.
Stephen Kelly 9 years ago
parent
commit
46ad0d2183

+ 10 - 7
Source/cmLocalGenerator.cxx

@@ -561,7 +561,8 @@ cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
 }
 
 std::string cmLocalGenerator::ExpandRuleVariable(
-  std::string const& variable, const RuleVariables& replaceValues)
+  cmOutputConverter* outputConverter, std::string const& variable,
+  const RuleVariables& replaceValues)
 {
   if (replaceValues.LinkFlags) {
     if (variable == "LINK_FLAGS") {
@@ -737,7 +738,7 @@ std::string cmLocalGenerator::ExpandRuleVariable(
     }
   }
   if (variable == "CMAKE_COMMAND") {
-    return this->ConvertToOutputFormat(
+    return outputConverter->ConvertToOutputFormat(
       cmSystemTools::CollapseFullPath(cmSystemTools::GetCMakeCommand()),
       SHELL);
   }
@@ -780,12 +781,12 @@ std::string cmLocalGenerator::ExpandRuleVariable(
         !compilerOptionExternalToolchain.empty()) {
       ret += " ";
       ret += compilerOptionExternalToolchain;
-      ret += this->EscapeForShell(compilerExternalToolchain, true);
+      ret += outputConverter->EscapeForShell(compilerExternalToolchain, true);
     }
     if (!this->CompilerSysroot.empty() && !compilerOptionSysroot.empty()) {
       ret += " ";
       ret += compilerOptionSysroot;
-      ret += this->EscapeForShell(this->CompilerSysroot, true);
+      ret += outputConverter->EscapeForShell(this->CompilerSysroot, true);
     }
     return ret;
   }
@@ -794,14 +795,15 @@ std::string cmLocalGenerator::ExpandRuleVariable(
     this->VariableMappings.find(variable);
   if (mapIt != this->VariableMappings.end()) {
     if (variable.find("_FLAG") == variable.npos) {
-      return this->ConvertToOutputForExisting(mapIt->second);
+      return outputConverter->ConvertToOutputForExisting(mapIt->second);
     }
     return mapIt->second;
   }
   return variable;
 }
 
-void cmLocalGenerator::ExpandRuleVariables(std::string& s,
+void cmLocalGenerator::ExpandRuleVariables(cmOutputConverter* outputConverter,
+                                           std::string& s,
                                            const RuleVariables& replaceValues)
 {
   std::string::size_type start = s.find('<');
@@ -825,7 +827,8 @@ void cmLocalGenerator::ExpandRuleVariables(std::string& s,
     } else {
       // extract the var
       std::string var = s.substr(start + 1, end - start - 1);
-      std::string replace = this->ExpandRuleVariable(var, replaceValues);
+      std::string replace =
+        this->ExpandRuleVariable(outputConverter, var, replaceValues);
       expandedInput += s.substr(pos, start - pos);
       expandedInput += replace;
       // move to next one

+ 4 - 2
Source/cmLocalGenerator.h

@@ -347,7 +347,8 @@ public:
   void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
 
   // Expand rule variables in CMake of the type found in language rules
-  void ExpandRuleVariables(std::string& string,
+  void ExpandRuleVariables(cmOutputConverter* outputConverter,
+                           std::string& string,
                            const RuleVariables& replaceValues);
 
   const char* GetRuleLauncher(cmGeneratorTarget* target,
@@ -361,7 +362,8 @@ protected:
                            std::string& frameworkPath, std::string& linkPath);
 
   // Expand rule variables in a single string
-  std::string ExpandRuleVariable(std::string const& variable,
+  std::string ExpandRuleVariable(cmOutputConverter* outputConverter,
+                                 std::string const& variable,
                                  const RuleVariables& replaceValues);
 
   // Handle old-style install rules stored in the targets.

+ 1 - 1
Source/cmLocalNinjaGenerator.cxx

@@ -494,7 +494,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
   std::string launcher = property_value;
   launcher += " ";
 
-  this->ExpandRuleVariables(launcher, vars);
+  this->ExpandRuleVariables(this, launcher, vars);
   if (!launcher.empty()) {
     launcher += " ";
   }

+ 1 - 1
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1005,7 +1005,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
 
         launcher = val;
         launcher += " ";
-        this->ExpandRuleVariables(launcher, vars);
+        this->ExpandRuleVariables(this, launcher, vars);
         if (!launcher.empty()) {
           launcher += " ";
         }

+ 2 - 1
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -396,7 +396,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     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->ExpandRuleVariables(this->LocalGenerator, *i,
+                                                vars);
     }
     this->LocalGenerator->TargetImplib = "";
 

+ 8 - 4
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -619,7 +619,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
                archiveCreateCommands.begin();
              i != archiveCreateCommands.end(); ++i) {
           std::string cmd = launcher + *i;
-          this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+          this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, cmd,
+                                                    vars);
           real_link_commands.push_back(cmd);
         }
       }
@@ -630,7 +631,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
                archiveAppendCommands.begin();
              i != archiveAppendCommands.end(); ++i) {
           std::string cmd = launcher + *i;
-          this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+          this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, cmd,
+                                                    vars);
           real_link_commands.push_back(cmd);
         }
       }
@@ -640,7 +642,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
              archiveFinishCommands.begin();
            i != archiveFinishCommands.end(); ++i) {
         std::string cmd = launcher + *i;
-        this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+        this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, cmd,
+                                                  vars);
         // If there is no ranlib the command will be ":".  Skip it.
         if (!cmd.empty() && cmd[0] != ':') {
           real_link_commands.push_back(cmd);
@@ -663,7 +666,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
       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->ExpandRuleVariables(this->LocalGenerator, *i,
+                                                  vars);
       }
     }
     this->LocalGenerator->TargetImplib = "";

+ 8 - 4
Source/cmMakefileTargetGenerator.cxx

@@ -600,7 +600,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
     if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
         lang_can_export_cmds && compileCommands.size() == 1) {
       std::string compileCommand = compileCommands[0];
-      this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
+      this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator,
+                                                compileCommand, vars);
       std::string workingDirectory = cmSystemTools::CollapseFullPath(
         this->LocalGenerator->GetCurrentBinaryDirectory());
       compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
@@ -659,7 +660,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
     // Expand placeholders in the commands.
     for (std::vector<std::string>::iterator i = compileCommands.begin();
          i != compileCommands.end(); ++i) {
-      this->LocalGenerator->ExpandRuleVariables(*i, vars);
+      this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, *i,
+                                                vars);
     }
 
     // Change the command working directory to the local build tree.
@@ -722,7 +724,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
         // Expand placeholders in the commands.
         for (std::vector<std::string>::iterator i = preprocessCommands.begin();
              i != preprocessCommands.end(); ++i) {
-          this->LocalGenerator->ExpandRuleVariables(*i, vars);
+          this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, *i,
+                                                    vars);
         }
 
         this->LocalGenerator->CreateCDCommand(
@@ -769,7 +772,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
         // Expand placeholders in the commands.
         for (std::vector<std::string>::iterator i = assemblyCommands.begin();
              i != assemblyCommands.end(); ++i) {
-          this->LocalGenerator->ExpandRuleVariables(*i, vars);
+          this->LocalGenerator->ExpandRuleVariables(this->LocalGenerator, *i,
+                                                    vars);
         }
 
         this->LocalGenerator->CreateCDCommand(

+ 2 - 1
Source/cmNinjaNormalTargetGenerator.cxx

@@ -250,7 +250,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
     for (std::vector<std::string>::iterator i = linkCmds.begin();
          i != linkCmds.end(); ++i) {
       *i = launcher + *i;
-      this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
+      this->GetLocalGenerator()->ExpandRuleVariables(this->GetLocalGenerator(),
+                                                     *i, vars);
     }
     {
       // If there is no ranlib the command will be ":".  Skip it.

+ 6 - 3
Source/cmNinjaTargetGenerator.cxx

@@ -503,7 +503,8 @@ 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);
+      this->GetLocalGenerator()->ExpandRuleVariables(this->GetLocalGenerator(),
+                                                     *i, ppVars);
     }
 
     // Run CMake dependency scanner on preprocessed output.
@@ -616,7 +617,8 @@ 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);
+    this->GetLocalGenerator()->ExpandRuleVariables(this->GetLocalGenerator(),
+                                                   *i, vars);
   }
 
   std::string cmdLine =
@@ -1003,7 +1005,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
 
   for (std::vector<std::string>::iterator i = compileCmds.begin();
        i != compileCmds.end(); ++i) {
-    this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars);
+    this->GetLocalGenerator()->ExpandRuleVariables(this->GetLocalGenerator(),
+                                                   *i, compileObjectVars);
   }
 
   std::string cmdLine =