Răsfoiți Sursa

Merge topic 'autogen_free_functions'

6bd40ccf84 Autogen: Make cmQtAutoMocUic a free function
e0e9be3d57 Autogen: Make cmQtAutoRcc a free function
820962edc9 Autogen: Refactor json info file reading interface

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3867
Brad King 6 ani în urmă
părinte
comite
b24e501bc2

+ 142 - 124
Source/cmQtAutoGenerator.cxx

@@ -210,79 +210,18 @@ cmQtAutoGenerator::cmQtAutoGenerator(GenT genType)
 
 cmQtAutoGenerator::~cmQtAutoGenerator() = default;
 
-bool cmQtAutoGenerator::Run(std::string const& infoFile,
-                            std::string const& config)
+bool cmQtAutoGenerator::InfoT::Read(std::istream& istr)
 {
-  // Info settings
-  InfoFile_ = infoFile;
-  cmSystemTools::CollapseFullPath(InfoFile_);
-  if (!InfoFileTime_.Load(InfoFile_)) {
-    cmSystemTools::Stderr(cmStrCat("AutoGen: The info file ",
-                                   Quoted(InfoFile_), " is not readable\n"));
-    return false;
-  }
-  InfoDir_ = cmSystemTools::GetFilenamePath(infoFile);
-  InfoConfig_ = config;
-
-  // Read info file
-  {
-    cmsys::ifstream ifs(InfoFile_.c_str(), (std::ios::in | std::ios::binary));
-    if (!ifs) {
-      Log().Error(GenType_,
-                  cmStrCat("Could not to open info file ", Quoted(InfoFile_)));
-      return false;
-    }
-    try {
-      ifs >> Info_;
-    } catch (...) {
-      Log().Error(GenType_,
-                  cmStrCat("Could not read info file ", Quoted(InfoFile_)));
-      return false;
-    }
-  }
-  // Info: setup logger
-  {
-    unsigned int value = 0;
-    if (!InfoUInt("VERBOSITY", value, false)) {
-      return false;
-    }
-    Logger_.RaiseVerbosity(value);
-  }
-  // Info: setup project directories
-  if (!InfoString("CMAKE_SOURCE_DIR", ProjectDirs_.Source, true) ||
-      !InfoString("CMAKE_BINARY_DIR", ProjectDirs_.Binary, true) ||
-      !InfoString("CMAKE_CURRENT_SOURCE_DIR", ProjectDirs_.CurrentSource,
-                  true) ||
-      !InfoString("CMAKE_CURRENT_BINARY_DIR", ProjectDirs_.CurrentBinary,
-                  true)) {
-    return false;
-  }
-
-  if (!this->InitFromInfo()) {
+  try {
+    istr >> Json_;
+  } catch (...) {
     return false;
   }
-  // Clear info
-  Info_ = Json::nullValue;
-
-  return this->Process();
-}
-
-bool cmQtAutoGenerator::LogInfoError(GenT genType,
-                                     cm::string_view message) const
-{
-  this->Log().Error(
-    genType,
-    cmStrCat("Info error in info file\n", Quoted(InfoFile()), ":\n", message));
-  return false;
-}
-
-bool cmQtAutoGenerator::LogInfoError(cm::string_view message) const
-{
-  return LogInfoError(GenType_, message);
+  return true;
 }
 
-bool cmQtAutoGenerator::JsonGetArray(std::vector<std::string>& list,
-                                     Json::Value const& jval)
+bool cmQtAutoGenerator::InfoT::GetJsonArray(std::vector<std::string>& list,
+                                            Json::Value const& jval)
 {
   Json::ArrayIndex const arraySize = jval.size();
   if (arraySize == 0) {
@@ -301,8 +240,8 @@ bool cmQtAutoGenerator::JsonGetArray(std::vector<std::string>& list,
   return picked;
 }
 
-bool cmQtAutoGenerator::JsonGetArray(std::unordered_set<std::string>& list,
-                                     Json::Value const& jval)
+bool cmQtAutoGenerator::InfoT::GetJsonArray(
+  std::unordered_set<std::string>& list, Json::Value const& jval)
 {
   Json::ArrayIndex const arraySize = jval.size();
   if (arraySize == 0) {
@@ -321,141 +260,157 @@ bool cmQtAutoGenerator::JsonGetArray(std::unordered_set<std::string>& list,
   return picked;
 }
 
-std::string cmQtAutoGenerator::InfoConfigKey(std::string const& key) const
+std::string cmQtAutoGenerator::InfoT::ConfigKey(cm::string_view key) const
 {
-  return cmStrCat(key, '_', InfoConfig());
+  return cmStrCat(key, '_', Gen_.InfoConfig());
 }
 
-bool cmQtAutoGenerator::InfoString(std::string const& key, std::string& value,
-                                   bool required) const
+bool cmQtAutoGenerator::InfoT::GetString(std::string const& key,
+                                         std::string& value,
+                                         bool required) const
 {
-  Json::Value const& jval = Info()[key];
+  Json::Value const& jval = Json_[key];
   if (!jval.isString()) {
     if (!jval.isNull() || required) {
-      return LogInfoError(cmStrCat(key, " is not a string."));
+      return LogError(cmStrCat(key, " is not a string."));
     }
   } else {
     value = jval.asString();
     if (value.empty() && required) {
-      return LogInfoError(cmStrCat(key, " is empty."));
+      return LogError(cmStrCat(key, " is empty."));
     }
   }
   return true;
 }
 
-bool cmQtAutoGenerator::InfoStringConfig(std::string const& key,
-                                         std::string& value,
-
-                                         bool required) const
+bool cmQtAutoGenerator::InfoT::GetStringConfig(std::string const& key,
+                                               std::string& value,
+                                               bool required) const
 {
   { // Try config
-    std::string const configKey = InfoConfigKey(key);
-    Json::Value const& jval = Info_[configKey];
+    std::string const configKey = ConfigKey(key);
+    Json::Value const& jval = Json_[configKey];
     if (!jval.isNull()) {
       if (!jval.isString()) {
-        return LogInfoError(cmStrCat(configKey, " is not a string."));
+        return LogError(cmStrCat(configKey, " is not a string."));
       }
       value = jval.asString();
       if (required && value.empty()) {
-        return LogInfoError(cmStrCat(configKey, " is empty."));
+        return LogError(cmStrCat(configKey, " is empty."));
       }
       return true;
     }
   }
   // Try plain
-  return InfoString(key, value, required);
+  return GetString(key, value, required);
 }
 
-bool cmQtAutoGenerator::InfoBool(std::string const& key, bool& value,
-                                 bool required) const
+bool cmQtAutoGenerator::InfoT::GetBool(std::string const& key, bool& value,
+                                       bool required) const
 {
-  Json::Value const& jval = Info()[key];
+  Json::Value const& jval = Json_[key];
   if (jval.isBool()) {
     value = jval.asBool();
   } else {
     if (!jval.isNull() || required) {
-      return LogInfoError(cmStrCat(key, " is not a boolean."));
+      return LogError(cmStrCat(key, " is not a boolean."));
     }
   }
   return true;
 }
 
-bool cmQtAutoGenerator::InfoUInt(std::string const& key, unsigned int& value,
-                                 bool required) const
+bool cmQtAutoGenerator::InfoT::GetUInt(std::string const& key,
+                                       unsigned int& value,
+                                       bool required) const
 {
-  Json::Value const& jval = Info()[key];
+  Json::Value const& jval = Json_[key];
   if (jval.isUInt()) {
     value = jval.asUInt();
   } else {
     if (!jval.isNull() || required) {
-      return LogInfoError(cmStrCat(key, " is not an unsigned integer."));
+      return LogError(cmStrCat(key, " is not an unsigned integer."));
     }
   }
   return true;
 }
 
-bool cmQtAutoGenerator::InfoArray(std::string const& key,
-                                  std::vector<std::string>& list,
-                                  bool required) const
+bool cmQtAutoGenerator::InfoT::GetArray(std::string const& key,
+                                        std::vector<std::string>& list,
+                                        bool required) const
 {
-  Json::Value const& jval = Info()[key];
+  Json::Value const& jval = Json_[key];
   if (!jval.isArray()) {
     if (!jval.isNull() || required) {
-      return LogInfoError(cmStrCat(key, " is not an array."));
+      return LogError(cmStrCat(key, " is not an array."));
     }
   }
-  return JsonGetArray(list, jval) || !required;
+  return GetJsonArray(list, jval) || !required;
 }
 
-bool cmQtAutoGenerator::InfoArray(std::string const& key,
-                                  std::unordered_set<std::string>& list,
-                                  bool required) const
+bool cmQtAutoGenerator::InfoT::GetArray(std::string const& key,
+                                        std::unordered_set<std::string>& list,
+                                        bool required) const
 {
-  Json::Value const& jval = Info()[key];
+  Json::Value const& jval = Json_[key];
   if (!jval.isArray()) {
     if (!jval.isNull() || required) {
-      return LogInfoError(cmStrCat(key, " is not an array."));
+      return LogError(cmStrCat(key, " is not an array."));
     }
   }
-  return JsonGetArray(list, jval) || !required;
+  return GetJsonArray(list, jval) || !required;
 }
 
-bool cmQtAutoGenerator::InfoArrayConfig(std::string const& key,
-                                        std::vector<std::string>& list,
-                                        bool required) const
+bool cmQtAutoGenerator::InfoT::GetArrayConfig(std::string const& key,
+                                              std::vector<std::string>& list,
+                                              bool required) const
 {
   { // Try config
-    std::string const configKey = InfoConfigKey(key);
-    Json::Value const& jval = Info()[configKey];
+    std::string const configKey = ConfigKey(key);
+    Json::Value const& jval = Json_[configKey];
     if (!jval.isNull()) {
       if (!jval.isArray()) {
-        return LogInfoError(cmStrCat(configKey, " is not an array string."));
+        return LogError(cmStrCat(configKey, " is not an array string."));
       }
-      if (!JsonGetArray(list, jval) && required) {
-        return LogInfoError(cmStrCat(configKey, " is empty."));
+      if (!GetJsonArray(list, jval) && required) {
+        return LogError(cmStrCat(configKey, " is empty."));
       }
       return true;
     }
   }
   // Try plain
-  return InfoArray(key, list, required);
+  return GetArray(key, list, required);
+}
+
+bool cmQtAutoGenerator::InfoT::LogError(GenT genType,
+                                        cm::string_view message) const
+{
+  Gen_.Log().Error(genType,
+                   cmStrCat("Info error in info file\n",
+                            Quoted(Gen_.InfoFile()), ":\n", message));
+  return false;
 }
 
-std::string cmQtAutoGenerator::SettingsFind(std::string const& content,
-                                            const char* key)
+bool cmQtAutoGenerator::InfoT::LogError(cm::string_view message) const
 {
-  std::string prefix = cmStrCat(key, ':');
-  std::string::size_type pos = content.find(prefix);
-  if (pos != std::string::npos) {
+  return LogError(Gen_.GenType_, message);
+}
+
+std::string cmQtAutoGenerator::SettingsFind(cm::string_view content,
+                                            cm::string_view key)
+{
+  cm::string_view res;
+  std::string const prefix = cmStrCat(key, ':');
+  cm::string_view::size_type pos = content.find(prefix);
+  if (pos != cm::string_view::npos) {
     pos += prefix.size();
     if (pos < content.size()) {
-      std::string::size_type posE = content.find('\n', pos);
-      if ((posE != std::string::npos) && (posE != pos)) {
-        return content.substr(pos, posE - pos);
+      cm::string_view::size_type posE = content.find('\n', pos);
+      if ((posE != cm::string_view::npos) && (posE != pos)) {
+        res = content.substr(pos, posE - pos);
       }
     }
   }
-  return std::string();
+  return std::string(res);
 }
 
 std::string cmQtAutoGenerator::MessagePath(cm::string_view path) const
@@ -470,3 +425,66 @@ std::string cmQtAutoGenerator::MessagePath(cm::string_view path) const
   }
   return cmQtAutoGen::Quoted(res);
 }
+
+bool cmQtAutoGenerator::Run(cm::string_view infoFile, cm::string_view config)
+{
+  // Info config
+  InfoConfig_ = std::string(config);
+
+  // Info file
+  InfoFile_ = std::string(infoFile);
+  cmSystemTools::CollapseFullPath(InfoFile_);
+  InfoDir_ = cmSystemTools::GetFilenamePath(InfoFile_);
+
+  // Load info file time
+  if (!InfoFileTime_.Load(InfoFile_)) {
+    cmSystemTools::Stderr(cmStrCat("AutoGen: The info file ",
+                                   Quoted(InfoFile_), " is not readable\n"));
+    return false;
+  }
+
+  {
+    InfoT info(*this);
+
+    // Read info file
+    {
+      cmsys::ifstream ifs(InfoFile_.c_str(),
+                          (std::ios::in | std::ios::binary));
+      if (!ifs) {
+        Log().Error(
+          GenType_,
+          cmStrCat("Could not to open info file ", Quoted(InfoFile_)));
+        return false;
+      }
+      if (!info.Read(ifs)) {
+        Log().Error(GenType_,
+                    cmStrCat("Could not read info file ", Quoted(InfoFile_)));
+        return false;
+      }
+    }
+
+    // -- Read common info settings
+    {
+      unsigned int verbosity = 0;
+      // Info: setup project directories
+      if (!info.GetUInt("VERBOSITY", verbosity, false) ||
+          !info.GetString("CMAKE_SOURCE_DIR", ProjectDirs_.Source, true) ||
+          !info.GetString("CMAKE_BINARY_DIR", ProjectDirs_.Binary, true) ||
+          !info.GetString("CMAKE_CURRENT_SOURCE_DIR",
+                          ProjectDirs_.CurrentSource, true) ||
+          !info.GetString("CMAKE_CURRENT_BINARY_DIR",
+                          ProjectDirs_.CurrentBinary, true)) {
+        return false;
+      }
+      Logger_.RaiseVerbosity(verbosity);
+    }
+
+    // -- Call virtual init from info method.
+    if (!this->InitFromInfo(info)) {
+      return false;
+    }
+  }
+
+  // Call virtual process method.
+  return this->Process();
+}

+ 60 - 36
Source/cmQtAutoGenerator.h

@@ -11,6 +11,7 @@
 
 #include <cm/string_view>
 
+#include <istream>
 #include <mutex>
 #include <string>
 #include <unordered_set>
@@ -86,54 +87,78 @@ public:
   cmQtAutoGenerator(cmQtAutoGenerator const&) = delete;
   cmQtAutoGenerator& operator=(cmQtAutoGenerator const&) = delete;
 
-  // -- Run
-  bool Run(std::string const& infoFile, std::string const& config);
-
-  // -- InfoFile
+  // -- Info options
   std::string const& InfoFile() const { return InfoFile_; }
-  Json::Value const& Info() const { return Info_; }
-  cmFileTime const& InfoFileTime() const { return InfoFileTime_; }
   std::string const& InfoDir() const { return InfoDir_; }
+  cmFileTime const& InfoFileTime() const { return InfoFileTime_; }
   std::string const& InfoConfig() const { return InfoConfig_; }
 
-  bool LogInfoError(GenT genType, cm::string_view message) const;
-  bool LogInfoError(cm::string_view message) const;
+  // -- Info file parsing
+  /** Info file reader class. */
+  class InfoT
+  {
+  public:
+    InfoT(cmQtAutoGenerator& gen)
+      : Gen_(gen)
+    {
+    }
+
+    /** Read json data from a stream.  */
+    bool Read(std::istream& istr);
+
+    /** Returns false if the JSON value isn't a string.  */
+    bool GetString(std::string const& key, std::string& value,
+                   bool required) const;
+    bool GetStringConfig(std::string const& key, std::string& value,
+                         bool required) const;
+    bool GetBool(std::string const& key, bool& value, bool required) const;
+    bool GetUInt(std::string const& key, unsigned int& value,
+                 bool required) const;
+    /** Returns false if the JSON value isn't an array.  */
+    bool GetArray(std::string const& key, std::vector<std::string>& list,
+                  bool required) const;
+    bool GetArray(std::string const& key,
+                  std::unordered_set<std::string>& list, bool required) const;
+    bool GetArrayConfig(std::string const& key, std::vector<std::string>& list,
+                        bool required) const;
 
-  /** Returns true if strings were appended to the list.  */
-  static bool JsonGetArray(std::vector<std::string>& list,
-                           Json::Value const& jval);
-  /** Returns true if strings were found in the JSON array.  */
-  static bool JsonGetArray(std::unordered_set<std::string>& list,
-                           Json::Value const& jval);
+    Json::Value const& GetValue(std::string const& key) const
+    {
+      return Json_[key];
+    }
 
-  std::string InfoConfigKey(std::string const& key) const;
+    /** Returns true if strings were appended to the list.  */
+    static bool GetJsonArray(std::vector<std::string>& list,
+                             Json::Value const& jval);
+    /** Returns true if strings were found in the JSON array.  */
+    static bool GetJsonArray(std::unordered_set<std::string>& list,
+                             Json::Value const& jval);
 
-  /** Returns false if the JSON value isn't a string.  */
-  bool InfoString(std::string const& key, std::string& value,
-                  bool required) const;
-  bool InfoStringConfig(std::string const& key, std::string& value,
-                        bool required) const;
-  bool InfoBool(std::string const& key, bool& value, bool required) const;
-  bool InfoUInt(std::string const& key, unsigned int& value,
-                bool required) const;
-  /** Returns false if the JSON value isn't an array.  */
-  bool InfoArray(std::string const& key, std::vector<std::string>& list,
-                 bool required) const;
-  bool InfoArray(std::string const& key, std::unordered_set<std::string>& list,
-                 bool required) const;
-  bool InfoArrayConfig(std::string const& key, std::vector<std::string>& list,
-                       bool required) const;
+    bool LogError(GenT genType, cm::string_view message) const;
+    bool LogError(cm::string_view message) const;
+
+  private:
+    std::string ConfigKey(cm::string_view key) const;
+
+  private:
+    Json::Value Json_;
+    cmQtAutoGenerator& Gen_;
+  };
+
+  // -- Settings file
+  static std::string SettingsFind(cm::string_view content,
+                                  cm::string_view key);
 
   // -- Directories
   ProjectDirsT const& ProjectDirs() const { return ProjectDirs_; }
-
-  // -- Utility
-  static std::string SettingsFind(std::string const& content, const char* key);
   std::string MessagePath(cm::string_view path) const;
 
+  // -- Run
+  bool Run(cm::string_view infoFile, cm::string_view config);
+
 protected:
   // -- Abstract processing interface
-  virtual bool InitFromInfo() = 0;
+  virtual bool InitFromInfo(InfoT const& info) = 0;
   virtual bool Process() = 0;
   // - Utility classes
   Logger const& Log() const { return Logger_; }
@@ -145,10 +170,9 @@ private:
   Logger Logger_;
   // -- Info file
   std::string InfoFile_;
-  cmFileTime InfoFileTime_;
   std::string InfoDir_;
+  cmFileTime InfoFileTime_;
   std::string InfoConfig_;
-  Json::Value Info_;
   // -- Directories
   ProjectDirsT ProjectDirs_;
 };

Fișier diff suprimat deoarece este prea mare
+ 604 - 83
Source/cmQtAutoMocUic.cxx


+ 4 - 547
Source/cmQtAutoMocUic.h

@@ -5,555 +5,12 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cmFileTime.h"
-#include "cmQtAutoGen.h"
-#include "cmQtAutoGenerator.h"
-#include "cmWorkerPool.h"
-#include "cmsys/RegularExpression.hxx"
-
 #include <cm/string_view>
 
-#include <atomic>
-#include <cstddef>
-#include <map>
-#include <memory>
-#include <mutex>
-#include <set>
-#include <string>
-#include <unordered_map>
-#include <unordered_set>
-#include <utility>
-#include <vector>
-
-/** \class cmQtAutoMocUic
- * \brief AUTOMOC and AUTOUIC generator
+/**
+ * Process AUTOMOC and AUTOUIC
+ * @return true on success
  */
-class cmQtAutoMocUic : public cmQtAutoGenerator
-{
-public:
-  cmQtAutoMocUic();
-  ~cmQtAutoMocUic() override;
-
-  cmQtAutoMocUic(cmQtAutoMocUic const&) = delete;
-  cmQtAutoMocUic& operator=(cmQtAutoMocUic const&) = delete;
-
-public:
-  // -- Types
-
-  /** Include string with sub parts.  */
-  struct IncludeKeyT
-  {
-    IncludeKeyT(std::string const& key, std::size_t basePrefixLength);
-
-    std::string Key;  // Full include string
-    std::string Dir;  // Include directory
-    std::string Base; // Base part of the include file name
-  };
-
-  /** Search key plus regular expression pair.  */
-  struct KeyExpT
-  {
-    KeyExpT() = default;
-
-    KeyExpT(std::string key, std::string const& exp)
-      : Key(std::move(key))
-      , Exp(exp)
-    {
-    }
-
-    std::string Key;
-    cmsys::RegularExpression Exp;
-  };
-
-  /** Source file parsing cache.  */
-  class ParseCacheT
-  {
-  public:
-    // -- Types
-
-    /** Entry of the file parsing cache.  */
-    struct FileT
-    {
-      void Clear();
-
-      struct MocT
-      {
-        std::string Macro;
-        struct IncludeT
-        {
-          std::vector<IncludeKeyT> Underscore;
-          std::vector<IncludeKeyT> Dot;
-        } Include;
-        std::vector<std::string> Depends;
-      } Moc;
-
-      struct UicT
-      {
-        std::vector<IncludeKeyT> Include;
-        std::vector<std::string> Depends;
-      } Uic;
-    };
-    using FileHandleT = std::shared_ptr<FileT>;
-    using GetOrInsertT = std::pair<FileHandleT, bool>;
-
-  public:
-    ParseCacheT();
-    ~ParseCacheT();
-
-    void Clear();
-
-    bool ReadFromFile(std::string const& fileName);
-    bool WriteToFile(std::string const& fileName);
-
-    //! Might return an invalid handle
-    FileHandleT Get(std::string const& fileName) const;
-    //! Always returns a valid handle
-    GetOrInsertT GetOrInsert(std::string const& fileName);
-
-  private:
-    std::unordered_map<std::string, FileHandleT> Map_;
-  };
-
-  /** Source file data.  */
-  class SourceFileT
-  {
-  public:
-    SourceFileT(std::string fileName)
-      : FileName(std::move(fileName))
-    {
-    }
-
-  public:
-    std::string FileName;
-    cmFileTime FileTime;
-    ParseCacheT::FileHandleT ParseData;
-    std::string BuildPath;
-    bool IsHeader = false;
-    bool Moc = false;
-    bool Uic = false;
-  };
-  using SourceFileHandleT = std::shared_ptr<SourceFileT>;
-  using SourceFileMapT = std::map<std::string, SourceFileHandleT>;
-
-  /** Meta compiler file mapping information.  */
-  struct MappingT
-  {
-    SourceFileHandleT SourceFile;
-    std::string OutputFile;
-    std::string IncludeString;
-    std::vector<SourceFileHandleT> IncluderFiles;
-  };
-  using MappingHandleT = std::shared_ptr<MappingT>;
-  using MappingMapT = std::map<std::string, MappingHandleT>;
-
-  /** Common settings.  */
-  class BaseSettingsT
-  {
-  public:
-    // -- Constructors
-    BaseSettingsT();
-    ~BaseSettingsT();
-
-    BaseSettingsT(BaseSettingsT const&) = delete;
-    BaseSettingsT& operator=(BaseSettingsT const&) = delete;
-
-    // -- Attributes
-    // - Config
-    bool MultiConfig = false;
-    unsigned int QtVersionMajor = 4;
-    unsigned int ThreadCount = 0;
-    // - Directories
-    std::string AutogenBuildDir;
-    std::string AutogenIncludeDir;
-    // - Files
-    std::string CMakeExecutable;
-    cmFileTime CMakeExecutableTime;
-    std::string ParseCacheFile;
-    std::vector<std::string> HeaderExtensions;
-  };
-
-  /** Shared common variables.  */
-  class BaseEvalT
-  {
-  public:
-    // -- Parse Cache
-    bool ParseCacheChanged = false;
-    cmFileTime ParseCacheTime;
-    ParseCacheT ParseCache;
-
-    // -- Sources
-    SourceFileMapT Headers;
-    SourceFileMapT Sources;
-  };
-
-  /** Moc settings.  */
-  class MocSettingsT
-  {
-  public:
-    // -- Constructors
-    MocSettingsT();
-    ~MocSettingsT();
-
-    MocSettingsT(MocSettingsT const&) = delete;
-    MocSettingsT& operator=(MocSettingsT const&) = delete;
-
-    // -- Const methods
-    bool skipped(std::string const& fileName) const;
-    std::string MacrosString() const;
-
-    // -- Attributes
-    bool Enabled = false;
-    bool SettingsChanged = false;
-    bool RelaxedMode = false;
-    bool PathPrefix = false;
-    cmFileTime ExecutableTime;
-    std::string Executable;
-    std::string CompFileAbs;
-    std::string PredefsFileAbs;
-    std::unordered_set<std::string> SkipList;
-    std::vector<std::string> IncludePaths;
-    std::vector<std::string> Definitions;
-    std::vector<std::string> OptionsIncludes;
-    std::vector<std::string> OptionsDefinitions;
-    std::vector<std::string> OptionsExtra;
-    std::vector<std::string> PredefsCmd;
-    std::vector<KeyExpT> DependFilters;
-    std::vector<KeyExpT> MacroFilters;
-    cmsys::RegularExpression RegExpInclude;
-  };
-
-  /** Moc shared variables.  */
-  class MocEvalT
-  {
-  public:
-    // -- predefines file
-    cmFileTime PredefsTime;
-    // -- Mappings
-    MappingMapT HeaderMappings;
-    MappingMapT SourceMappings;
-    MappingMapT Includes;
-    // -- Discovered files
-    SourceFileMapT HeadersDiscovered;
-    // -- Output directories
-    std::unordered_set<std::string> OutputDirs;
-    // -- Mocs compilation
-    bool CompUpdated = false;
-    std::vector<std::string> CompFiles;
-  };
-
-  /** Uic settings.  */
-  class UicSettingsT
-  {
-  public:
-    struct UiFile
-    {
-      std::vector<std::string> Options;
-    };
-
-  public:
-    UicSettingsT();
-    ~UicSettingsT();
-
-    UicSettingsT(UicSettingsT const&) = delete;
-    UicSettingsT& operator=(UicSettingsT const&) = delete;
-
-    // -- Const methods
-    bool skipped(std::string const& fileName) const;
-
-    // -- Attributes
-    bool Enabled = false;
-    bool SettingsChanged = false;
-    cmFileTime ExecutableTime;
-    std::string Executable;
-    std::unordered_set<std::string> SkipList;
-    std::vector<std::string> Options;
-    std::unordered_map<std::string, UiFile> UiFiles;
-    std::vector<std::string> SearchPaths;
-    cmsys::RegularExpression RegExpInclude;
-  };
-
-  /** Uic shared variables.  */
-  class UicEvalT
-  {
-  public:
-    // -- Discovered files
-    SourceFileMapT UiFiles;
-    // -- Mappings
-    MappingMapT Includes;
-    // -- Output directories
-    std::unordered_set<std::string> OutputDirs;
-  };
-
-  /** Abstract job class for concurrent job processing.  */
-  class JobT : public cmWorkerPool::JobT
-  {
-  protected:
-    /** Protected default constructor.  */
-    JobT(bool fence = false)
-      : cmWorkerPool::JobT(fence)
-    {
-    }
-
-    //! Get the generator. Only valid during Process() call!
-    cmQtAutoMocUic* Gen() const
-    {
-      return static_cast<cmQtAutoMocUic*>(UserData());
-    };
-
-    // -- Accessors. Only valid during Process() call!
-    Logger const& Log() const { return Gen()->Log(); }
-    BaseSettingsT const& BaseConst() const { return Gen()->BaseConst(); }
-    BaseEvalT& BaseEval() const { return Gen()->BaseEval(); }
-    MocSettingsT const& MocConst() const { return Gen()->MocConst(); }
-    MocEvalT& MocEval() const { return Gen()->MocEval(); }
-    UicSettingsT const& UicConst() const { return Gen()->UicConst(); }
-    UicEvalT& UicEval() const { return Gen()->UicEval(); }
-
-    // -- Logging
-    std::string MessagePath(cm::string_view path) const
-    {
-      return Gen()->MessagePath(path);
-    }
-    // - Error logging with automatic abort
-    void LogError(GenT genType, cm::string_view message) const;
-    void LogCommandError(GenT genType, cm::string_view message,
-                         std::vector<std::string> const& command,
-                         std::string const& output) const;
-
-    /** @brief Run an external process. Use only during Process() call!  */
-    bool RunProcess(GenT genType, cmWorkerPool::ProcessResultT& result,
-                    std::vector<std::string> const& command,
-                    std::string* infoMessage = nullptr);
-  };
-
-  /** Fence job utility class.  */
-  class JobFenceT : public JobT
-  {
-  public:
-    JobFenceT()
-      : JobT(true)
-    {
-    }
-    void Process() override{};
-  };
-
-  /** Generate moc_predefs.h.  */
-  class JobMocPredefsT : public JobFenceT
-  {
-    void Process() override;
-    bool Update(std::string* reason) const;
-  };
-
-  /** File parse job base class.  */
-  class JobParseT : public JobT
-  {
-  public:
-    JobParseT(SourceFileHandleT fileHandle)
-      : FileHandle(std::move(fileHandle))
-    {
-    }
-
-  protected:
-    bool ReadFile();
-    void CreateKeys(std::vector<IncludeKeyT>& container,
-                    std::set<std::string> const& source,
-                    std::size_t basePrefixLength);
-    void MocMacro();
-    void MocDependecies();
-    void MocIncludes();
-    void UicIncludes();
-
-  protected:
-    SourceFileHandleT FileHandle;
-    std::string Content;
-  };
-
-  /** Header file parse job.  */
-  class JobParseHeaderT : public JobParseT
-  {
-  public:
-    using JobParseT::JobParseT;
-    void Process() override;
-  };
-
-  /** Source file parse job.  */
-  class JobParseSourceT : public JobParseT
-  {
-  public:
-    using JobParseT::JobParseT;
-    void Process() override;
-  };
-
-  /** Evaluate cached file parse data - moc.  */
-  class JobEvalCacheT : public JobT
-  {
-  protected:
-    std::string MessageSearchLocations() const;
-    std::vector<std::string> SearchLocations;
-  };
-
-  /** Evaluate cached file parse data - moc.  */
-  class JobEvalCacheMocT : public JobEvalCacheT
-  {
-    void Process() override;
-    bool EvalHeader(SourceFileHandleT source);
-    bool EvalSource(SourceFileHandleT const& source);
-    bool FindIncludedHeader(SourceFileHandleT& headerHandle,
-                            cm::string_view includerDir,
-                            cm::string_view includeBase);
-    bool RegisterIncluded(std::string const& includeString,
-                          SourceFileHandleT includerFileHandle,
-                          SourceFileHandleT sourceFileHandle) const;
-    void RegisterMapping(MappingHandleT mappingHandle) const;
-    std::string MessageHeader(cm::string_view headerBase) const;
-  };
-
-  /** Evaluate cached file parse data - uic.  */
-  class JobEvalCacheUicT : public JobEvalCacheT
-  {
-    void Process() override;
-    bool EvalFile(SourceFileHandleT const& sourceFileHandle);
-    bool FindIncludedUi(cm::string_view sourceDirPrefix,
-                        cm::string_view includePrefix);
-    bool RegisterMapping(std::string const& includeString,
-                         SourceFileHandleT includerFileHandle);
-
-    std::string UiName;
-    SourceFileHandleT UiFileHandle;
-  };
-
-  /** Evaluate cached file parse data - finish  */
-  class JobEvalCacheFinishT : public JobFenceT
-  {
-    void Process() override;
-  };
-
-  /** Dependency probing base job.  */
-  class JobProbeDepsT : public JobT
-  {
-  };
-
-  /** Probes file dependencies and generates moc compile jobs.  */
-  class JobProbeDepsMocT : public JobProbeDepsT
-  {
-    void Process() override;
-    bool Generate(MappingHandleT const& mapping, bool compFile) const;
-    bool Probe(MappingT const& mapping, std::string* reason) const;
-    std::pair<std::string, cmFileTime> FindDependency(
-      std::string const& sourceDir, std::string const& includeString) const;
-  };
-
-  /** Probes file dependencies and generates uic compile jobs.  */
-  class JobProbeDepsUicT : public JobProbeDepsT
-  {
-    void Process() override;
-    bool Probe(MappingT const& mapping, std::string* reason) const;
-  };
-
-  /** Dependency probing finish job.  */
-  class JobProbeDepsFinishT : public JobFenceT
-  {
-    void Process() override;
-  };
-
-  /** Meta compiler base job.  */
-  class JobCompileT : public JobT
-  {
-  public:
-    JobCompileT(MappingHandleT uicMapping, std::unique_ptr<std::string> reason)
-      : Mapping(std::move(uicMapping))
-      , Reason(std::move(reason))
-    {
-    }
-
-  protected:
-    MappingHandleT Mapping;
-    std::unique_ptr<std::string> Reason;
-  };
-
-  /** moc compiles a file.  */
-  class JobCompileMocT : public JobCompileT
-  {
-  public:
-    using JobCompileT::JobCompileT;
-    void Process() override;
-  };
-
-  /** uic compiles a file.  */
-  class JobCompileUicT : public JobCompileT
-  {
-  public:
-    using JobCompileT::JobCompileT;
-    void Process() override;
-  };
-
-  /** Generate mocs_compilation.cpp.  */
-  class JobMocsCompilationT : public JobFenceT
-  {
-  private:
-    void Process() override;
-  };
-
-  /** @brief The last job.  */
-  class JobFinishT : public JobFenceT
-  {
-  private:
-    void Process() override;
-  };
-
-  // -- Const settings interface
-  BaseSettingsT const& BaseConst() const { return this->BaseConst_; }
-  BaseEvalT& BaseEval() { return this->BaseEval_; }
-  MocSettingsT const& MocConst() const { return this->MocConst_; }
-  MocEvalT& MocEval() { return this->MocEval_; }
-  UicSettingsT const& UicConst() const { return this->UicConst_; }
-  UicEvalT& UicEval() { return this->UicEval_; }
-
-  // -- Parallel job processing interface
-  cmWorkerPool& WorkerPool() { return WorkerPool_; }
-  void AbortError() { Abort(true); }
-  void AbortSuccess() { Abort(false); }
-
-  // -- Utility
-  std::string AbsoluteBuildPath(cm::string_view relativePath) const;
-  std::string AbsoluteIncludePath(cm::string_view relativePath) const;
-  template <class JOBTYPE>
-  void CreateParseJobs(SourceFileMapT const& sourceMap);
-  std::string CollapseFullPathTS(std::string const& path) const;
-
-private:
-  // -- Abstract processing interface
-  bool InitFromInfo() override;
-  void InitJobs();
-  bool Process() override;
-  // -- Settings file
-  void SettingsFileRead();
-  bool SettingsFileWrite();
-  // -- Parse cache
-  void ParseCacheRead();
-  bool ParseCacheWrite();
-  // -- Thread processing
-  void Abort(bool error);
-  // -- Generation
-  bool CreateDirectories();
-
-private:
-  // -- Settings
-  BaseSettingsT BaseConst_;
-  BaseEvalT BaseEval_;
-  MocSettingsT MocConst_;
-  MocEvalT MocEval_;
-  UicSettingsT UicConst_;
-  UicEvalT UicEval_;
-  // -- Settings file
-  std::string SettingsFile_;
-  std::string SettingsStringMoc_;
-  std::string SettingsStringUic_;
-  // -- Worker thread pool
-  std::atomic<bool> JobError_ = ATOMIC_VAR_INIT(false);
-  cmWorkerPool WorkerPool_;
-  // -- Concurrent processing
-  mutable std::mutex CMakeLibMutex_;
-};
+bool cmQtAutoMocUic(cm::string_view infoFile, cm::string_view config);
 
 #endif

+ 102 - 27
Source/cmQtAutoRcc.cxx

@@ -5,37 +5,105 @@
 #include "cmAlgorithms.h"
 #include "cmCryptoHash.h"
 #include "cmDuration.h"
+#include "cmFileLock.h"
 #include "cmFileLockResult.h"
+#include "cmFileTime.h"
 #include "cmProcessOutput.h"
 #include "cmQtAutoGen.h"
+#include "cmQtAutoGenerator.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-#include <cm/string_view>
-
 #include <algorithm>
+#include <string>
+#include <vector>
+
+namespace {
 
-cmQtAutoRcc::cmQtAutoRcc()
+/** \class cmQtAutoRccT
+ * \brief AUTORCC generator
+ */
+class cmQtAutoRccT : public cmQtAutoGenerator
+{
+public:
+  cmQtAutoRccT();
+  ~cmQtAutoRccT() override;
+
+  cmQtAutoRccT(cmQtAutoRccT const&) = delete;
+  cmQtAutoRccT& operator=(cmQtAutoRccT const&) = delete;
+
+private:
+  // -- Utility
+  bool IsMultiConfig() const { return MultiConfig_; }
+  std::string MultiConfigOutput() const;
+
+  // -- Abstract processing interface
+  bool InitFromInfo(InfoT const& info) override;
+  bool Process() override;
+  // -- Settings file
+  bool SettingsFileRead();
+  bool SettingsFileWrite();
+  // -- Tests
+  bool TestQrcRccFiles(bool& generate);
+  bool TestResources(bool& generate);
+  bool TestInfoFile();
+  // -- Generation
+  bool GenerateRcc();
+  bool GenerateWrapper();
+
+private:
+  // -- Config settings
+  bool MultiConfig_ = false;
+  // -- Directories
+  std::string AutogenBuildDir_;
+  std::string IncludeDir_;
+  // -- Qt environment
+  std::string RccExecutable_;
+  cmFileTime RccExecutableTime_;
+  std::vector<std::string> RccListOptions_;
+  // -- Job
+  std::string LockFile_;
+  cmFileLock LockFileLock_;
+  std::string QrcFile_;
+  std::string QrcFileName_;
+  std::string QrcFileDir_;
+  cmFileTime QrcFileTime_;
+  std::string RccPathChecksum_;
+  std::string RccFileName_;
+  std::string RccFileOutput_;
+  std::string RccFilePublic_;
+  cmFileTime RccFileTime_;
+  std::string Reason;
+  std::vector<std::string> Options_;
+  std::vector<std::string> Inputs_;
+  // -- Settings file
+  std::string SettingsFile_;
+  std::string SettingsString_;
+  bool SettingsChanged_ = false;
+  bool BuildFileChanged_ = false;
+};
+
+cmQtAutoRccT::cmQtAutoRccT()
   : cmQtAutoGenerator(GenT::RCC)
 {
 }
-cmQtAutoRcc::~cmQtAutoRcc() = default;
+cmQtAutoRccT::~cmQtAutoRccT() = default;
 
-bool cmQtAutoRcc::InitFromInfo()
+bool cmQtAutoRccT::InitFromInfo(InfoT const& info)
 {
   // -- Required settings
-  if (!InfoBool("MULTI_CONFIG", MultiConfig_, true) ||
-      !InfoString("BUILD_DIR", AutogenBuildDir_, true) ||
-      !InfoStringConfig("INCLUDE_DIR", IncludeDir_, true) ||
-      !InfoString("RCC_EXECUTABLE", RccExecutable_, true) ||
-      !InfoArray("RCC_LIST_OPTIONS", RccListOptions_, false) ||
-      !InfoString("LOCK_FILE", LockFile_, true) ||
-      !InfoStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
-      !InfoString("SOURCE", QrcFile_, true) ||
-      !InfoString("OUTPUT_CHECKSUM", RccPathChecksum_, true) ||
-      !InfoString("OUTPUT_NAME", RccFileName_, true) ||
-      !InfoArray("OPTIONS", Options_, false) ||
-      !InfoArray("INPUTS", Inputs_, false)) {
+  if (!info.GetBool("MULTI_CONFIG", MultiConfig_, true) ||
+      !info.GetString("BUILD_DIR", AutogenBuildDir_, true) ||
+      !info.GetStringConfig("INCLUDE_DIR", IncludeDir_, true) ||
+      !info.GetString("RCC_EXECUTABLE", RccExecutable_, true) ||
+      !info.GetArray("RCC_LIST_OPTIONS", RccListOptions_, false) ||
+      !info.GetString("LOCK_FILE", LockFile_, true) ||
+      !info.GetStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
+      !info.GetString("SOURCE", QrcFile_, true) ||
+      !info.GetString("OUTPUT_CHECKSUM", RccPathChecksum_, true) ||
+      !info.GetString("OUTPUT_NAME", RccFileName_, true) ||
+      !info.GetArray("OPTIONS", Options_, false) ||
+      !info.GetArray("INPUTS", Inputs_, false)) {
     return false;
   }
 
@@ -54,14 +122,14 @@ bool cmQtAutoRcc::InitFromInfo()
 
   // -- Checks
   if (!RccExecutableTime_.Load(RccExecutable_)) {
-    return LogInfoError(cmStrCat(
+    return info.LogError(cmStrCat(
       "The rcc executable ", MessagePath(RccExecutable_), " does not exist."));
   }
 
   return true;
 }
 
-bool cmQtAutoRcc::Process()
+bool cmQtAutoRccT::Process()
 {
   if (!SettingsFileRead()) {
     return false;
@@ -94,13 +162,13 @@ bool cmQtAutoRcc::Process()
   return SettingsFileWrite();
 }
 
-std::string cmQtAutoRcc::MultiConfigOutput() const
+std::string cmQtAutoRccT::MultiConfigOutput() const
 {
   return cmStrCat(RccPathChecksum_, '/',
                   AppendFilenameSuffix(RccFileName_, "_CMAKE_"));
 }
 
-bool cmQtAutoRcc::SettingsFileRead()
+bool cmQtAutoRccT::SettingsFileRead()
 {
   // Compose current settings strings
   {
@@ -178,7 +246,7 @@ bool cmQtAutoRcc::SettingsFileRead()
   return true;
 }
 
-bool cmQtAutoRcc::SettingsFileWrite()
+bool cmQtAutoRccT::SettingsFileWrite()
 {
   // Only write if any setting changed
   if (SettingsChanged_) {
@@ -205,7 +273,7 @@ bool cmQtAutoRcc::SettingsFileWrite()
 }
 
 /// Do basic checks if rcc generation is required
-bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
+bool cmQtAutoRccT::TestQrcRccFiles(bool& generate)
 {
   // Test if the rcc input file exists
   if (!QrcFileTime_.Load(QrcFile_)) {
@@ -262,7 +330,7 @@ bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
   return true;
 }
 
-bool cmQtAutoRcc::TestResources(bool& generate)
+bool cmQtAutoRccT::TestResources(bool& generate)
 {
   // Read resource files list
   if (Inputs_.empty()) {
@@ -301,7 +369,7 @@ bool cmQtAutoRcc::TestResources(bool& generate)
   return true;
 }
 
-bool cmQtAutoRcc::TestInfoFile()
+bool cmQtAutoRccT::TestInfoFile()
 {
   // Test if the rcc output file is older than the info file
   if (RccFileTime_.Older(InfoFileTime())) {
@@ -324,7 +392,7 @@ bool cmQtAutoRcc::TestInfoFile()
   return true;
 }
 
-bool cmQtAutoRcc::GenerateRcc()
+bool cmQtAutoRccT::GenerateRcc()
 {
   // Make parent directory
   if (!MakeParentDirectory(RccFileOutput_)) {
@@ -376,7 +444,7 @@ bool cmQtAutoRcc::GenerateRcc()
   return true;
 }
 
-bool cmQtAutoRcc::GenerateWrapper()
+bool cmQtAutoRccT::GenerateWrapper()
 {
   // Generate a wrapper source file on demand
   if (IsMultiConfig()) {
@@ -426,3 +494,10 @@ bool cmQtAutoRcc::GenerateWrapper()
   }
   return true;
 }
+
+} // End of unnamed namespace
+
+bool cmQtAutoRcc(cm::string_view infoFile, cm::string_view config)
+{
+  return cmQtAutoRccT().Run(infoFile, config);
+}

+ 5 - 67
Source/cmQtAutoRcc.h

@@ -5,74 +5,12 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cmFileLock.h"
-#include "cmFileTime.h"
-#include "cmQtAutoGenerator.h"
+#include <cm/string_view>
 
-#include <string>
-#include <vector>
-
-/** \class cmQtAutoRcc
- * \brief AUTORCC generator
+/**
+ * Process AUTORCC
+ * @return true on success
  */
-class cmQtAutoRcc : public cmQtAutoGenerator
-{
-public:
-  cmQtAutoRcc();
-  ~cmQtAutoRcc() override;
-
-  cmQtAutoRcc(cmQtAutoRcc const&) = delete;
-  cmQtAutoRcc& operator=(cmQtAutoRcc const&) = delete;
-
-private:
-  // -- Utility
-  bool IsMultiConfig() const { return MultiConfig_; }
-  std::string MultiConfigOutput() const;
-
-  // -- Abstract processing interface
-  bool InitFromInfo() override;
-  bool Process() override;
-  // -- Settings file
-  bool SettingsFileRead();
-  bool SettingsFileWrite();
-  // -- Tests
-  bool TestQrcRccFiles(bool& generate);
-  bool TestResources(bool& generate);
-  bool TestInfoFile();
-  // -- Generation
-  bool GenerateRcc();
-  bool GenerateWrapper();
-
-private:
-  // -- Config settings
-  bool MultiConfig_ = false;
-  // -- Directories
-  std::string AutogenBuildDir_;
-  std::string IncludeDir_;
-  // -- Qt environment
-  std::string RccExecutable_;
-  cmFileTime RccExecutableTime_;
-  std::vector<std::string> RccListOptions_;
-  // -- Job
-  std::string LockFile_;
-  cmFileLock LockFileLock_;
-  std::string QrcFile_;
-  std::string QrcFileName_;
-  std::string QrcFileDir_;
-  cmFileTime QrcFileTime_;
-  std::string RccPathChecksum_;
-  std::string RccFileName_;
-  std::string RccFileOutput_;
-  std::string RccFilePublic_;
-  cmFileTime RccFileTime_;
-  std::string Reason;
-  std::vector<std::string> Options_;
-  std::vector<std::string> Inputs_;
-  // -- Settings file
-  std::string SettingsFile_;
-  std::string SettingsString_;
-  bool SettingsChanged_ = false;
-  bool BuildFileChanged_ = false;
-};
+bool cmQtAutoRcc(cm::string_view infoFile, cm::string_view config);
 
 #endif

+ 10 - 11
Source/cmcmd.cxx

@@ -27,6 +27,7 @@
 
 #if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32)
 #  include "bindexplib.h"
+#  include "cmFileTime.h"
 #  include "cmsys/ConsoleBuf.hxx"
 #endif
 
@@ -48,6 +49,8 @@
 #include <sstream>
 #include <utility>
 
+#include <cm/string_view>
+
 class cmConnection;
 
 int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
@@ -1057,19 +1060,15 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
 
 #ifndef CMAKE_BOOTSTRAP
     if ((args[1] == "cmake_autogen") && (args.size() >= 4)) {
-      cmQtAutoMocUic autoGen;
-      std::string const& infoFile = args[2];
-      std::string const& config = args[3];
-      return autoGen.Run(infoFile, config) ? 0 : 1;
+      cm::string_view const infoFile = args[2];
+      cm::string_view const config = args[3];
+      return cmQtAutoMocUic(infoFile, config) ? 0 : 1;
     }
     if ((args[1] == "cmake_autorcc") && (args.size() >= 3)) {
-      cmQtAutoRcc autoRcc;
-      std::string const& infoFile = args[2];
-      std::string config;
-      if (args.size() > 3) {
-        config = args[3];
-      }
-      return autoRcc.Run(infoFile, config) ? 0 : 1;
+      cm::string_view const infoFile = args[2];
+      cm::string_view const config =
+        (args.size() > 3) ? cm::string_view(args[3]) : cm::string_view();
+      return cmQtAutoRcc(infoFile, config) ? 0 : 1;
     }
 #endif
 

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff