Autogen: Refactor json info file reading interface

This commit is contained in:
Sebastian Holtermann
2019-09-27 14:47:05 +02:00
parent 9cd47ff3c8
commit 820962edc9
7 changed files with 299 additions and 259 deletions

View File

@@ -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"));
try {
istr >> Json_;
} catch (...) {
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()) {
return false;
}
// Clear info
Info_ = Json::nullValue;
return this->Process();
return true;
}
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);
}
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
{
Json::Value const& jval = Info()[key];
if (!jval.isArray()) {
if (!jval.isNull() || required) {
return LogInfoError(cmStrCat(key, " is not an array."));
}
}
return JsonGetArray(list, jval) || !required;
}
bool cmQtAutoGenerator::InfoArray(std::string const& key,
std::unordered_set<std::string>& list,
bool required) const
{
Json::Value const& jval = Info()[key];
if (!jval.isArray()) {
if (!jval.isNull() || required) {
return LogInfoError(cmStrCat(key, " is not an array."));
}
}
return JsonGetArray(list, jval) || !required;
}
bool cmQtAutoGenerator::InfoArrayConfig(std::string const& key,
bool cmQtAutoGenerator::InfoT::GetArray(std::string const& key,
std::vector<std::string>& list,
bool required) const
{
Json::Value const& jval = Json_[key];
if (!jval.isArray()) {
if (!jval.isNull() || required) {
return LogError(cmStrCat(key, " is not an array."));
}
}
return GetJsonArray(list, jval) || !required;
}
bool cmQtAutoGenerator::InfoT::GetArray(std::string const& key,
std::unordered_set<std::string>& list,
bool required) const
{
Json::Value const& jval = Json_[key];
if (!jval.isArray()) {
if (!jval.isNull() || required) {
return LogError(cmStrCat(key, " is not an array."));
}
}
return GetJsonArray(list, jval) || !required;
}
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);
}
std::string cmQtAutoGenerator::SettingsFind(std::string const& content,
const char* key)
bool cmQtAutoGenerator::InfoT::LogError(GenT genType,
cm::string_view message) const
{
std::string prefix = cmStrCat(key, ':');
std::string::size_type pos = content.find(prefix);
if (pos != std::string::npos) {
Gen_.Log().Error(genType,
cmStrCat("Info error in info file\n",
Quoted(Gen_.InfoFile()), ":\n", message));
return false;
}
bool cmQtAutoGenerator::InfoT::LogError(cm::string_view message) const
{
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();
}

View File

@@ -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)
{
}
/** 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);
/** Read json data from a stream. */
bool Read(std::istream& istr);
std::string InfoConfigKey(std::string const& key) const;
/** Returns false if the JSON value isn't a string. */
bool InfoString(std::string const& key, std::string& value,
/** 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 InfoStringConfig(std::string const& key, std::string& value,
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;
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;
Json::Value const& GetValue(std::string const& key) const
{
return Json_[key];
}
/** 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);
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_;
};

View File

@@ -1557,28 +1557,30 @@ cmQtAutoMocUic::cmQtAutoMocUic()
}
cmQtAutoMocUic::~cmQtAutoMocUic() = default;
bool cmQtAutoMocUic::InitFromInfo()
bool cmQtAutoMocUic::InitFromInfo(InfoT const& info)
{
// -- Required settings
if (!InfoBool("MULTI_CONFIG", BaseConst_.MultiConfig, true) ||
!InfoUInt("QT_VERSION_MAJOR", BaseConst_.QtVersionMajor, true) ||
!InfoUInt("PARALLEL", BaseConst_.ThreadCount, false) ||
!InfoString("BUILD_DIR", BaseConst_.AutogenBuildDir, true) ||
!InfoStringConfig("INCLUDE_DIR", BaseConst_.AutogenIncludeDir, true) ||
!InfoString("CMAKE_EXECUTABLE", BaseConst_.CMakeExecutable, true) ||
!InfoStringConfig("PARSE_CACHE_FILE", BaseConst_.ParseCacheFile, true) ||
!InfoStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
!InfoArray("HEADER_EXTENSIONS", BaseConst_.HeaderExtensions, true) ||
!InfoString("QT_MOC_EXECUTABLE", MocConst_.Executable, false) ||
!InfoString("QT_UIC_EXECUTABLE", UicConst_.Executable, false)) {
if (!info.GetBool("MULTI_CONFIG", BaseConst_.MultiConfig, true) ||
!info.GetUInt("QT_VERSION_MAJOR", BaseConst_.QtVersionMajor, true) ||
!info.GetUInt("PARALLEL", BaseConst_.ThreadCount, false) ||
!info.GetString("BUILD_DIR", BaseConst_.AutogenBuildDir, true) ||
!info.GetStringConfig("INCLUDE_DIR", BaseConst_.AutogenIncludeDir,
true) ||
!info.GetString("CMAKE_EXECUTABLE", BaseConst_.CMakeExecutable, true) ||
!info.GetStringConfig("PARSE_CACHE_FILE", BaseConst_.ParseCacheFile,
true) ||
!info.GetStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
!info.GetArray("HEADER_EXTENSIONS", BaseConst_.HeaderExtensions, true) ||
!info.GetString("QT_MOC_EXECUTABLE", MocConst_.Executable, false) ||
!info.GetString("QT_UIC_EXECUTABLE", UicConst_.Executable, false)) {
return false;
}
// -- Checks
if (!BaseConst_.CMakeExecutableTime.Load(BaseConst_.CMakeExecutable)) {
return LogInfoError(cmStrCat("The CMake executable ",
MessagePath(BaseConst_.CMakeExecutable),
" does not exist."));
return info.LogError(cmStrCat("The CMake executable ",
MessagePath(BaseConst_.CMakeExecutable),
" does not exist."));
}
// -- Evaluate values
@@ -1598,19 +1600,20 @@ bool cmQtAutoMocUic::InitFromInfo()
} tmp;
// -- Required settings
if (!InfoBool("MOC_RELAXED_MODE", MocConst_.RelaxedMode, false) ||
!InfoBool("MOC_PATH_PREFIX", MocConst_.PathPrefix, true) ||
!InfoArray("MOC_SKIP", MocConst_.SkipList, false) ||
!InfoArrayConfig("MOC_DEFINITIONS", MocConst_.Definitions, false) ||
!InfoArrayConfig("MOC_INCLUDES", MocConst_.IncludePaths, false) ||
!InfoArray("MOC_OPTIONS", MocConst_.OptionsExtra, false) ||
!InfoStringConfig("MOC_COMPILATION_FILE", MocConst_.CompFileAbs,
true) ||
!InfoArray("MOC_PREDEFS_CMD", MocConst_.PredefsCmd, false) ||
!InfoStringConfig("MOC_PREDEFS_FILE", MocConst_.PredefsFileAbs,
!MocConst_.PredefsCmd.empty()) ||
!InfoArray("MOC_MACRO_NAMES", tmp.MacroNames, true) ||
!InfoArray("MOC_DEPEND_FILTERS", tmp.DependFilters, false)) {
if (!info.GetBool("MOC_RELAXED_MODE", MocConst_.RelaxedMode, false) ||
!info.GetBool("MOC_PATH_PREFIX", MocConst_.PathPrefix, true) ||
!info.GetArray("MOC_SKIP", MocConst_.SkipList, false) ||
!info.GetArrayConfig("MOC_DEFINITIONS", MocConst_.Definitions,
false) ||
!info.GetArrayConfig("MOC_INCLUDES", MocConst_.IncludePaths, false) ||
!info.GetArray("MOC_OPTIONS", MocConst_.OptionsExtra, false) ||
!info.GetStringConfig("MOC_COMPILATION_FILE", MocConst_.CompFileAbs,
true) ||
!info.GetArray("MOC_PREDEFS_CMD", MocConst_.PredefsCmd, false) ||
!info.GetStringConfig("MOC_PREDEFS_FILE", MocConst_.PredefsFileAbs,
!MocConst_.PredefsCmd.empty()) ||
!info.GetArray("MOC_MACRO_NAMES", tmp.MacroNames, true) ||
!info.GetArray("MOC_DEPEND_FILTERS", tmp.DependFilters, false)) {
return false;
}
@@ -1621,18 +1624,17 @@ bool cmQtAutoMocUic::InitFromInfo()
}
// Dependency filters
{
Json::Value const& val = Info()["MOC_DEPEND_FILTERS"];
Json::Value const& val = info.GetValue("MOC_DEPEND_FILTERS");
if (!val.isArray()) {
return LogInfoError("MOC_DEPEND_FILTERS JSON value is not an array.");
return info.LogError("MOC_DEPEND_FILTERS JSON value is not an array.");
}
Json::ArrayIndex const arraySize = val.size();
for (Json::ArrayIndex ii = 0; ii != arraySize; ++ii) {
// Test entry closure
auto testEntry = [this, ii](bool test,
cm::string_view message) -> bool {
auto testEntry = [&info, ii](bool test, cm::string_view msg) -> bool {
if (!test) {
this->LogInfoError(
cmStrCat("MOC_DEPEND_FILTERS filter ", ii, ": ", message));
info.LogError(
cmStrCat("MOC_DEPEND_FILTERS filter ", ii, ": ", msg));
}
return !test;
};
@@ -1671,9 +1673,9 @@ bool cmQtAutoMocUic::InitFromInfo()
}
// Check if moc executable exists (by reading the file time)
if (!MocConst_.ExecutableTime.Load(MocConst_.Executable)) {
return LogInfoError(cmStrCat("The moc executable ",
MessagePath(MocConst_.Executable),
" does not exist."));
return info.LogError(cmStrCat("The moc executable ",
MessagePath(MocConst_.Executable),
" does not exist."));
}
}
@@ -1683,25 +1685,23 @@ bool cmQtAutoMocUic::InitFromInfo()
UicConst_.Enabled = true;
// -- Required settings
if (!InfoArray("UIC_SKIP", UicConst_.SkipList, false) ||
!InfoArray("UIC_SEARCH_PATHS", UicConst_.SearchPaths, false) ||
!InfoArrayConfig("UIC_OPTIONS", UicConst_.Options, false)) {
if (!info.GetArray("UIC_SKIP", UicConst_.SkipList, false) ||
!info.GetArray("UIC_SEARCH_PATHS", UicConst_.SearchPaths, false) ||
!info.GetArrayConfig("UIC_OPTIONS", UicConst_.Options, false)) {
return false;
}
// .ui files
{
Json::Value const& val = Info()["UIC_UI_FILES"];
Json::Value const& val = info.GetValue("UIC_UI_FILES");
if (!val.isArray()) {
return LogInfoError("UIC_UI_FILES JSON value is not an array.");
return info.LogError("UIC_UI_FILES JSON value is not an array.");
}
Json::ArrayIndex const arraySize = val.size();
for (Json::ArrayIndex ii = 0; ii != arraySize; ++ii) {
// Test entry closure
auto testEntry = [this, ii](bool test,
cm::string_view message) -> bool {
auto testEntry = [&info, ii](bool test, cm::string_view msg) -> bool {
if (!test) {
this->LogInfoError(
cmStrCat("UIC_UI_FILES entry ", ii, ": ", message));
info.LogError(cmStrCat("UIC_UI_FILES entry ", ii, ": ", msg));
}
return !test;
};
@@ -1722,31 +1722,31 @@ bool cmQtAutoMocUic::InitFromInfo()
}
auto& uiFile = UicConst_.UiFiles[entryName.asString()];
JsonGetArray(uiFile.Options, entryOptions);
InfoT::GetJsonArray(uiFile.Options, entryOptions);
}
}
// -- Evaluate settings
// Check if uic executable exists (by reading the file time)
if (!UicConst_.ExecutableTime.Load(UicConst_.Executable)) {
return LogInfoError(cmStrCat("The uic executable ",
MessagePath(UicConst_.Executable),
" does not exist."));
return info.LogError(cmStrCat("The uic executable ",
MessagePath(UicConst_.Executable),
" does not exist."));
}
}
// -- Headers
{
Json::Value const& val = Info()["HEADERS"];
Json::Value const& val = info.GetValue("HEADERS");
if (!val.isArray()) {
return LogInfoError("HEADERS JSON value is not an array.");
return info.LogError("HEADERS JSON value is not an array.");
}
Json::ArrayIndex const arraySize = val.size();
for (Json::ArrayIndex ii = 0; ii != arraySize; ++ii) {
// Test entry closure
auto testEntry = [this, ii](bool test, cm::string_view message) -> bool {
auto testEntry = [&info, ii](bool test, cm::string_view msg) -> bool {
if (!test) {
this->LogInfoError(cmStrCat("HEADERS entry ", ii, ": ", message));
info.LogError(cmStrCat("HEADERS entry ", ii, ": ", msg));
}
return !test;
};
@@ -1778,9 +1778,8 @@ bool cmQtAutoMocUic::InitFromInfo()
cmFileTime fileTime;
if (!fileTime.Load(name)) {
LogInfoError(cmStrCat("The header file ", this->MessagePath(name),
" does not exist."));
return false;
return info.LogError(cmStrCat(
"The header file ", this->MessagePath(name), " does not exist."));
}
SourceFileHandleT sourceHandle = std::make_shared<SourceFileT>(name);
@@ -1790,7 +1789,7 @@ bool cmQtAutoMocUic::InitFromInfo()
sourceHandle->Uic = (flags[1] == 'U');
if (sourceHandle->Moc && MocConst().Enabled) {
if (build.empty()) {
return LogInfoError(
return info.LogError(
cmStrCat("Header file ", ii, " build path is empty"));
}
sourceHandle->BuildPath = std::move(build);
@@ -1801,16 +1800,16 @@ bool cmQtAutoMocUic::InitFromInfo()
// -- Sources
{
Json::Value const& val = Info()["SOURCES"];
Json::Value const& val = info.GetValue("SOURCES");
if (!val.isArray()) {
return LogInfoError("SOURCES JSON value is not an array.");
return info.LogError("SOURCES JSON value is not an array.");
}
Json::ArrayIndex const arraySize = val.size();
for (Json::ArrayIndex ii = 0; ii != arraySize; ++ii) {
// Test entry closure
auto testEntry = [this, ii](bool test, cm::string_view message) -> bool {
auto testEntry = [&info, ii](bool test, cm::string_view msg) -> bool {
if (!test) {
this->LogInfoError(cmStrCat("SOURCES entry ", ii, ": ", message));
info.LogError(cmStrCat("SOURCES entry ", ii, ": ", msg));
}
return !test;
};
@@ -1838,9 +1837,8 @@ bool cmQtAutoMocUic::InitFromInfo()
cmFileTime fileTime;
if (!fileTime.Load(name)) {
LogInfoError(cmStrCat("The source file ", this->MessagePath(name),
" does not exist."));
return false;
return info.LogError(cmStrCat(
"The source file ", this->MessagePath(name), " does not exist."));
}
SourceFileHandleT sourceHandle = std::make_shared<SourceFileT>(name);

View File

@@ -523,7 +523,7 @@ public:
private:
// -- Abstract processing interface
bool InitFromInfo() override;
bool InitFromInfo(InfoT const& info) override;
void InitJobs();
bool Process() override;
// -- Settings file

View File

@@ -21,21 +21,21 @@ cmQtAutoRcc::cmQtAutoRcc()
}
cmQtAutoRcc::~cmQtAutoRcc() = default;
bool cmQtAutoRcc::InitFromInfo()
bool cmQtAutoRcc::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,7 +54,7 @@ bool cmQtAutoRcc::InitFromInfo()
// -- Checks
if (!RccExecutableTime_.Load(RccExecutable_)) {
return LogInfoError(cmStrCat(
return info.LogError(cmStrCat(
"The rcc executable ", MessagePath(RccExecutable_), " does not exist."));
}

View File

@@ -30,7 +30,7 @@ private:
std::string MultiConfigOutput() const;
// -- Abstract processing interface
bool InitFromInfo() override;
bool InitFromInfo(InfoT const& info) override;
bool Process() override;
// -- Settings file
bool SettingsFileRead();

View File

@@ -48,6 +48,8 @@
#include <sstream>
#include <utility>
#include <cm/string_view>
class cmConnection;
int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
@@ -1058,17 +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];
cm::string_view const infoFile = args[2];
cm::string_view const config = args[3];
return autoGen.Run(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];
}
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;
}
#endif