Autogen: Make cmQtAutoRcc a free function

This commit is contained in:
Sebastian Holtermann
2019-09-27 15:49:13 +02:00
parent 820962edc9
commit e0e9be3d57
3 changed files with 95 additions and 83 deletions

View File

@@ -5,23 +5,91 @@
#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>
cmQtAutoRcc::cmQtAutoRcc()
namespace {
/** \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(InfoT const& info)
bool cmQtAutoRccT::InitFromInfo(InfoT const& info)
{
// -- Required settings
if (!info.GetBool("MULTI_CONFIG", MultiConfig_, true) ||
@@ -61,7 +129,7 @@ bool cmQtAutoRcc::InitFromInfo(InfoT const& info)
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);
}

View File

@@ -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(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;
};
bool cmQtAutoRcc(cm::string_view infoFile, cm::string_view config);
#endif

View File

@@ -1065,11 +1065,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
return autoGen.Run(infoFile, config) ? 0 : 1;
}
if ((args[1] == "cmake_autorcc") && (args.size() >= 3)) {
cmQtAutoRcc autoRcc;
cm::string_view const infoFile = args[2];
cm::string_view const config =
(args.size() > 3) ? cm::string_view(args[3]) : cm::string_view();
return autoRcc.Run(infoFile, config) ? 0 : 1;
return cmQtAutoRcc(infoFile, config) ? 0 : 1;
}
#endif