Răsfoiți Sursa

cmLinkLineComputer: Move ComputeLinkLibs from cmLocalGenerator

Add a cmOutputConverter to the cmLinkLineComputer and factory methods to
facilitate shell escapes.

Add state to the cmLinkLineComputer to record whether outputting for
response files or for watcom, to satisfy the cmOutputConverter API.
These are constant for the lifetime of the cmLinkLineComputer, even when
its functionality is extended in the future.  This also keeps the
signatures of cmLinkLineComputer relatively simple.

Pass the cmComputeLinkInformation as a method parameter so that
cmLinkLineComputer is free from target-specific state.  An instance
should be usable for all targets in a directory.
Stephen Kelly 9 ani în urmă
părinte
comite
0c97806325

+ 1 - 0
Source/cmGhsMultiTargetGenerator.cxx

@@ -365,6 +365,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries(
       this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
       this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
       this->GetGlobalGenerator()->CreateLinkLineComputer(
       this->GetGlobalGenerator()->CreateLinkLineComputer(
+        this->LocalGenerator,
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
 
 
     this->LocalGenerator->GetTargetFlags(
     this->LocalGenerator->GetTargetFlags(

+ 4 - 4
Source/cmGlobalGenerator.cxx

@@ -1415,15 +1415,15 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
 }
 }
 
 
 cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer(
 cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer(
-  cmState::Directory stateDir) const
+  cmOutputConverter* outputConverter, cmState::Directory stateDir) const
 {
 {
-  return new cmLinkLineComputer(stateDir);
+  return new cmLinkLineComputer(outputConverter, stateDir);
 }
 }
 
 
 cmLinkLineComputer* cmGlobalGenerator::CreateMSVC60LinkLineComputer(
 cmLinkLineComputer* cmGlobalGenerator::CreateMSVC60LinkLineComputer(
-  cmState::Directory stateDir) const
+  cmOutputConverter* outputConverter, cmState::Directory stateDir) const
 {
 {
-  return new cmMSVC60LinkLineComputer(stateDir);
+  return new cmMSVC60LinkLineComputer(outputConverter, stateDir);
 }
 }
 
 
 void cmGlobalGenerator::FinalizeTargetCompileInfo()
 void cmGlobalGenerator::FinalizeTargetCompileInfo()

+ 3 - 2
Source/cmGlobalGenerator.h

@@ -36,6 +36,7 @@ class cmGeneratorTarget;
 class cmLocalGenerator;
 class cmLocalGenerator;
 class cmLinkLineComputer;
 class cmLinkLineComputer;
 class cmMakefile;
 class cmMakefile;
+class cmOutputConverter;
 class cmake;
 class cmake;
 
 
 /** \class cmGlobalGenerator
 /** \class cmGlobalGenerator
@@ -107,10 +108,10 @@ public:
   virtual void Generate();
   virtual void Generate();
 
 
   virtual cmLinkLineComputer* CreateLinkLineComputer(
   virtual cmLinkLineComputer* CreateLinkLineComputer(
-    cmState::Directory stateDir) const;
+    cmOutputConverter* outputConverter, cmState::Directory stateDir) const;
 
 
   cmLinkLineComputer* CreateMSVC60LinkLineComputer(
   cmLinkLineComputer* CreateMSVC60LinkLineComputer(
-    cmState::Directory stateDir) const;
+    cmOutputConverter* outputConverter, cmState::Directory stateDir) const;
 
 
   /**
   /**
    * Set/Get and Clear the enabled languages.
    * Set/Get and Clear the enabled languages.

+ 2 - 1
Source/cmGlobalNinjaGenerator.cxx

@@ -66,9 +66,10 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
 }
 }
 
 
 cmLinkLineComputer* cmGlobalNinjaGenerator::CreateLinkLineComputer(
 cmLinkLineComputer* cmGlobalNinjaGenerator::CreateLinkLineComputer(
-  cmState::Directory /* stateDir */) const
+  cmOutputConverter* outputConverter, cmState::Directory /* stateDir */) const
 {
 {
   return new cmNinjaLinkLineComputer(
   return new cmNinjaLinkLineComputer(
+    outputConverter,
     this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this);
     this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this);
 }
 }
 
 

+ 3 - 2
Source/cmGlobalNinjaGenerator.h

@@ -70,8 +70,9 @@ public:
   std::string EncodePath(const std::string& path);
   std::string EncodePath(const std::string& path);
   static std::string EncodeDepfileSpace(const std::string& path);
   static std::string EncodeDepfileSpace(const std::string& path);
 
 
-  cmLinkLineComputer* CreateLinkLineComputer(cmState::Directory stateDir) const
-    CM_OVERRIDE;
+  cmLinkLineComputer* CreateLinkLineComputer(
+    cmOutputConverter* outputConverter,
+    cmState::Directory stateDir) const CM_OVERRIDE;
 
 
   /**
   /**
    * Write the given @a comment to the output stream @a os. It
    * Write the given @a comment to the output stream @a os. It

+ 48 - 1
Source/cmLinkLineComputer.cxx

@@ -2,10 +2,16 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 
 
 #include "cmLinkLineComputer.h"
 #include "cmLinkLineComputer.h"
+#include "cmComputeLinkInformation.h"
+#include "cmGeneratorTarget.h"
 #include "cmOutputConverter.h"
 #include "cmOutputConverter.h"
 
 
-cmLinkLineComputer::cmLinkLineComputer(cmState::Directory stateDir)
+cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
+                                       cmState::Directory stateDir)
   : StateDir(stateDir)
   : StateDir(stateDir)
+  , OutputConverter(outputConverter)
+  , ForResponse(false)
+  , UseWatcomQuote(false)
 {
 {
 }
 }
 
 
@@ -13,6 +19,16 @@ cmLinkLineComputer::~cmLinkLineComputer()
 {
 {
 }
 }
 
 
+void cmLinkLineComputer::SetUseWatcomQuote(bool useWatcomQuote)
+{
+  this->UseWatcomQuote = useWatcomQuote;
+}
+
+void cmLinkLineComputer::SetForResponse(bool forResponse)
+{
+  this->ForResponse = forResponse;
+}
+
 std::string cmLinkLineComputer::ConvertToLinkReference(
 std::string cmLinkLineComputer::ConvertToLinkReference(
   std::string const& lib) const
   std::string const& lib) const
 {
 {
@@ -25,3 +41,34 @@ std::string cmLinkLineComputer::ConvertToLinkReference(
   }
   }
   return relLib;
   return relLib;
 }
 }
+
+std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli)
+{
+  std::string linkLibs;
+  typedef cmComputeLinkInformation::ItemVector ItemVector;
+  ItemVector const& items = cli.GetItems();
+  for (ItemVector::const_iterator li = items.begin(); li != items.end();
+       ++li) {
+    if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
+      continue;
+    }
+    if (li->IsPath) {
+      linkLibs +=
+        this->ConvertToOutputFormat(this->ConvertToLinkReference(li->Value));
+    } else {
+      linkLibs += li->Value;
+    }
+    linkLibs += " ";
+  }
+  return linkLibs;
+}
+
+std::string cmLinkLineComputer::ConvertToOutputFormat(std::string const& input)
+{
+  cmOutputConverter::OutputFormat shellFormat = (this->ForResponse)
+    ? cmOutputConverter::RESPONSE
+    : ((this->UseWatcomQuote) ? cmOutputConverter::WATCOMQUOTE
+                              : cmOutputConverter::SHELL);
+
+  return this->OutputConverter->ConvertToOutputFormat(input, shellFormat);
+}

+ 16 - 1
Source/cmLinkLineComputer.h

@@ -6,16 +6,31 @@
 
 
 #include "cmState.h"
 #include "cmState.h"
 
 
+class cmComputeLinkInformation;
+class cmOutputConverter;
+
 class cmLinkLineComputer
 class cmLinkLineComputer
 {
 {
 public:
 public:
-  cmLinkLineComputer(cmState::Directory stateDir);
+  cmLinkLineComputer(cmOutputConverter* outputConverter,
+                     cmState::Directory stateDir);
   virtual ~cmLinkLineComputer();
   virtual ~cmLinkLineComputer();
 
 
+  void SetUseWatcomQuote(bool useWatcomQuote);
+  void SetForResponse(bool forResponse);
+
   virtual std::string ConvertToLinkReference(std::string const& input) const;
   virtual std::string ConvertToLinkReference(std::string const& input) const;
 
 
+  std::string ComputeLinkLibs(cmComputeLinkInformation& cli);
+
 private:
 private:
+  std::string ConvertToOutputFormat(std::string const& input);
+
   cmState::Directory StateDir;
   cmState::Directory StateDir;
+  cmOutputConverter* OutputConverter;
+
+  bool ForResponse;
+  bool UseWatcomQuote;
 };
 };
 
 
 #endif
 #endif

+ 1 - 18
Source/cmLocalGenerator.cxx

@@ -1453,24 +1453,7 @@ void cmLocalGenerator::OutputLinkLibraries(
     linkPath += " ";
     linkPath += " ";
   }
   }
 
 
-  std::string linkLibs;
-
-  // Append the link items.
-  typedef cmComputeLinkInformation::ItemVector ItemVector;
-  ItemVector const& items = cli.GetItems();
-  for (ItemVector::const_iterator li = items.begin(); li != items.end();
-       ++li) {
-    if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
-      continue;
-    }
-    if (li->IsPath) {
-      linkLibs += this->ConvertToOutputFormat(
-        linkLineComputer->ConvertToLinkReference(li->Value), shellFormat);
-    } else {
-      linkLibs += li->Value;
-    }
-    linkLibs += " ";
-  }
+  std::string linkLibs = linkLineComputer->ComputeLinkLibs(cli);
 
 
   std::string rpath;
   std::string rpath;
 
 

+ 3 - 2
Source/cmMSVC60LinkLineComputer.cxx

@@ -5,8 +5,9 @@
 
 
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
-cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(cmState::Directory stateDir)
-  : cmLinkLineComputer(stateDir)
+cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(
+  cmOutputConverter* outputConverter, cmState::Directory stateDir)
+  : cmLinkLineComputer(outputConverter, stateDir)
 {
 {
 }
 }
 
 

+ 2 - 1
Source/cmMSVC60LinkLineComputer.h

@@ -9,7 +9,8 @@
 class cmMSVC60LinkLineComputer : public cmLinkLineComputer
 class cmMSVC60LinkLineComputer : public cmLinkLineComputer
 {
 {
 public:
 public:
-  cmMSVC60LinkLineComputer(cmState::Directory stateDir);
+  cmMSVC60LinkLineComputer(cmOutputConverter* outputConverter,
+                           cmState::Directory stateDir);
 
 
   std::string ConvertToLinkReference(std::string const& input) const
   std::string ConvertToLinkReference(std::string const& input) const
     CM_OVERRIDE;
     CM_OVERRIDE;

+ 4 - 0
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -219,6 +219,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   {
   {
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
       this->CreateLinkLineComputer(
       this->CreateLinkLineComputer(
+        this->LocalGenerator,
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
 
 
     this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags);
     this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags);
@@ -305,7 +306,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
 
 
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
       this->CreateLinkLineComputer(
       this->CreateLinkLineComputer(
+        this->LocalGenerator,
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
         this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+    linkLineComputer->SetForResponse(useResponseFileForLibs);
+    linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
 
 
     // Collect up flags to link in needed libraries.
     // Collect up flags to link in needed libraries.
     std::string linkLibs;
     std::string linkLibs;

+ 5 - 0
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -163,6 +163,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
 
 
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     this->CreateLinkLineComputer(
     this->CreateLinkLineComputer(
+      this->LocalGenerator,
       this->LocalGenerator->GetStateSnapshot().GetDirectory()));
       this->LocalGenerator->GetStateSnapshot().GetDirectory()));
 
 
   this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
   this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
@@ -193,6 +194,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
 
 
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     this->CreateLinkLineComputer(
     this->CreateLinkLineComputer(
+      this->LocalGenerator,
       this->LocalGenerator->GetStateSnapshot().GetDirectory()));
       this->LocalGenerator->GetStateSnapshot().GetDirectory()));
 
 
   this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
   this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
@@ -505,7 +507,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
 
 
       CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
       CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
         this->CreateLinkLineComputer(
         this->CreateLinkLineComputer(
+          this->LocalGenerator,
           this->LocalGenerator->GetStateSnapshot().GetDirectory()));
           this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+      linkLineComputer->SetForResponse(useResponseFileForLibs);
+      linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
 
 
       this->CreateLinkLibs(linkLineComputer.get(), linkLibs, relink,
       this->CreateLinkLibs(linkLineComputer.get(), linkLibs, relink,
                            useResponseFileForLibs, depends, useWatcomQuote);
                            useResponseFileForLibs, depends, useWatcomQuote);

+ 5 - 3
Source/cmMakefileTargetGenerator.cxx

@@ -1590,12 +1590,14 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
 }
 }
 
 
 cmLinkLineComputer* cmMakefileTargetGenerator::CreateLinkLineComputer(
 cmLinkLineComputer* cmMakefileTargetGenerator::CreateLinkLineComputer(
-  cmState::Directory stateDir)
+  cmOutputConverter* outputConverter, cmState::Directory stateDir)
 {
 {
   if (this->Makefile->IsOn("MSVC60")) {
   if (this->Makefile->IsOn("MSVC60")) {
-    return this->GlobalGenerator->CreateMSVC60LinkLineComputer(stateDir);
+    return this->GlobalGenerator->CreateMSVC60LinkLineComputer(outputConverter,
+                                                               stateDir);
   }
   }
-  return this->GlobalGenerator->CreateLinkLineComputer(stateDir);
+  return this->GlobalGenerator->CreateLinkLineComputer(outputConverter,
+                                                       stateDir);
 }
 }
 
 
 void cmMakefileTargetGenerator::CreateLinkLibs(
 void cmMakefileTargetGenerator::CreateLinkLibs(

+ 2 - 1
Source/cmMakefileTargetGenerator.h

@@ -140,7 +140,8 @@ protected:
                         std::vector<std::string>& makefile_commands,
                         std::vector<std::string>& makefile_commands,
                         std::vector<std::string>& makefile_depends);
                         std::vector<std::string>& makefile_depends);
 
 
-  cmLinkLineComputer* CreateLinkLineComputer(cmState::Directory stateDir);
+  cmLinkLineComputer* CreateLinkLineComputer(
+    cmOutputConverter* outputConverter, cmState::Directory stateDir);
 
 
   /** Create a response file with the given set of options.  Returns
   /** Create a response file with the given set of options.  Returns
       the relative path from the target build working directory to the
       the relative path from the target build working directory to the

+ 3 - 2
Source/cmNinjaLinkLineComputer.cxx

@@ -5,8 +5,9 @@
 #include "cmGlobalNinjaGenerator.h"
 #include "cmGlobalNinjaGenerator.h"
 
 
 cmNinjaLinkLineComputer::cmNinjaLinkLineComputer(
 cmNinjaLinkLineComputer::cmNinjaLinkLineComputer(
-  cmState::Directory stateDir, cmGlobalNinjaGenerator const* gg)
-  : cmLinkLineComputer(stateDir)
+  cmOutputConverter* outputConverter, cmState::Directory stateDir,
+  cmGlobalNinjaGenerator const* gg)
+  : cmLinkLineComputer(outputConverter, stateDir)
   , GG(gg)
   , GG(gg)
 {
 {
 }
 }

+ 2 - 1
Source/cmNinjaLinkLineComputer.h

@@ -12,7 +12,8 @@ class cmGlobalNinjaGenerator;
 class cmNinjaLinkLineComputer : public cmLinkLineComputer
 class cmNinjaLinkLineComputer : public cmLinkLineComputer
 {
 {
 public:
 public:
-  cmNinjaLinkLineComputer(cmState::Directory stateDir,
+  cmNinjaLinkLineComputer(cmOutputConverter* outputConverter,
+                          cmState::Directory stateDir,
                           cmGlobalNinjaGenerator const* gg);
                           cmGlobalNinjaGenerator const* gg);
 
 
   std::string ConvertToLinkReference(std::string const& input) const
   std::string ConvertToLinkReference(std::string const& input) const

+ 2 - 1
Source/cmNinjaNormalTargetGenerator.cxx

@@ -473,7 +473,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
 
 
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
   CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
     this->GetGlobalGenerator()->CreateLinkLineComputer(
     this->GetGlobalGenerator()->CreateLinkLineComputer(
-      localGen.GetStateSnapshot().GetDirectory()));
+      this->GetLocalGenerator(),
+      this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()));
 
 
   localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
   localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
                           vars["LINK_LIBRARIES"], vars["FLAGS"],
                           vars["LINK_LIBRARIES"], vars["FLAGS"],

+ 4 - 6
Source/cmServerProtocol.cxx

@@ -729,12 +729,10 @@ static Json::Value DumpTarget(cmGeneratorTarget* target,
     std::string linkLanguageFlags;
     std::string linkLanguageFlags;
     std::string frameworkPath;
     std::string frameworkPath;
     std::string linkPath;
     std::string linkPath;
-    CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
-      lg->GetGlobalGenerator()->CreateLinkLineComputer(
-        lg->GetStateSnapshot().GetDirectory()));
-    lg->GetTargetFlags(linkLineComputer.get(), config, linkLibs,
-                       linkLanguageFlags, linkFlags, frameworkPath, linkPath,
-                       target, false);
+    cmLinkLineComputer linkLineComputer(lg,
+                                        lg->GetStateSnapshot().GetDirectory());
+    lg->GetTargetFlags(&linkLineComputer, config, linkLibs, linkLanguageFlags,
+                       linkFlags, frameworkPath, linkPath, target, false);
 
 
     linkLibs = cmSystemTools::TrimWhitespace(linkLibs);
     linkLibs = cmSystemTools::TrimWhitespace(linkLibs);
     linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
     linkFlags = cmSystemTools::TrimWhitespace(linkFlags);

+ 3 - 3
Source/cmake.cxx

@@ -583,9 +583,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
     gg->CreateGenerationObjects();
     gg->CreateGenerationObjects();
     cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName());
     cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName());
     cmLocalGenerator* lg = gtgt->GetLocalGenerator();
     cmLocalGenerator* lg = gtgt->GetLocalGenerator();
-    CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
-      gg->CreateLinkLineComputer(lg->GetStateSnapshot().GetDirectory()));
-    lg->GetTargetFlags(linkLineComputer.get(), buildType, linkLibs, flags,
+    cmLinkLineComputer linkLineComputer(lg,
+                                        lg->GetStateSnapshot().GetDirectory());
+    lg->GetTargetFlags(&linkLineComputer, buildType, linkLibs, flags,
                        linkFlags, frameworkPath, linkPath, gtgt, false);
                        linkFlags, frameworkPath, linkPath, gtgt, false);
     linkLibs = frameworkPath + linkPath + linkLibs;
     linkLibs = frameworkPath + linkPath + linkLibs;