diff options
author | Deniz Bahadir <dbahadir@benocs.com> | 2020-11-09 00:06:51 (GMT) |
---|---|---|
committer | Deniz Bahadir <dbahadir@benocs.com> | 2020-11-24 17:16:51 (GMT) |
commit | 6624b65b3f478574512a23a7220abff4ed590011 (patch) | |
tree | 41a239c43b3a223ea8f27beac5b12d299d39c62c /Source | |
parent | b14fe704f8fad5785f10f0d56c5b49a8e0e0e94c (diff) | |
download | CMake-6624b65b3f478574512a23a7220abff4ed590011.zip CMake-6624b65b3f478574512a23a7220abff4ed590011.tar.gz CMake-6624b65b3f478574512a23a7220abff4ed590011.tar.bz2 |
GENERATED prop: Add implementation for policy CMP0118 being set to NEW
* Adding implementation for policy CMP0118 being set to `NEW`.
* Adding new tests for policy CMP0118 being set to `NEW`.
* Checking the `GENERATED` property with `get_source_file_property` or
`get_property` now always returns exactly `1` or `0`. No other values
will be returned. Note, that this is a backwards-incompatible change,
even when policy CMP0118 is unset or set to `OLD`.
* Additionally, as `get_source_file_property` and `get_property` now
always check if a source-file was marked globally visible, even when
CMP0118 is unset or set to `OLD`, they possibly return `1` where they
might have returned `0` before the changes introduced by this commit.
Note, that this is a backwards-incompatible change, even when policy
CMP0118 is unset or set to `OLD`.
* As a consequence, the tests for policy CMP0118 being unset or set to
`OLD` got slightly adjusted, too, to reflect these changes in
behavior.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCPluginAPI.cxx | 5 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 8 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 8 | ||||
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 2 | ||||
-rw-r--r-- | Source/cmSetPropertyCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 61 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 36 |
8 files changed, 102 insertions, 31 deletions
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 968fa54..9e3582c 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -550,6 +550,11 @@ void* CCONV cmAddSource(void* arg, void* arg2) // Create the real cmSourceFile instance and copy over saved information. cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath); rsf->SetProperties(osf->Properties); + // In case the properties contain the GENERATED property, + // mark the real cmSourceFile as generated. + if (rsf->GetIsGenerated()) { + rsf->MarkAsGenerated(); + } for (std::string const& d : osf->Depends) { rsf->AddDepend(d); } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 52f1d52..80b3775 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1814,6 +1814,7 @@ void cmGlobalGenerator::ClearGeneratorMembers() this->RuleHashes.clear(); this->DirectoryContentMap.clear(); this->BinaryDirectories.clear(); + this->GeneratedFiles.clear(); } void cmGlobalGenerator::ComputeTargetObjectDirectory( @@ -2139,6 +2140,16 @@ void cmGlobalGenerator::AddInstallComponent(const std::string& component) } } +void cmGlobalGenerator::MarkAsGeneratedFile(const std::string& filepath) +{ + this->GeneratedFiles.insert(filepath); +} + +bool cmGlobalGenerator::IsGeneratedFile(const std::string& filepath) +{ + return this->GeneratedFiles.find(filepath) != this->GeneratedFiles.end(); +} + void cmGlobalGenerator::EnableInstallTarget() { this->InstallTargetEnabled = true; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index afafba9..e933589 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -11,6 +11,7 @@ #include <set> #include <string> #include <unordered_map> +#include <unordered_set> #include <utility> #include <vector> @@ -290,6 +291,11 @@ public: void AddInstallComponent(const std::string& component); + /** Mark the (absolute path to a) file as generated. */ + void MarkAsGeneratedFile(const std::string& filepath); + /** Determine if the absolute filepath belongs to a generated file. */ + bool IsGeneratedFile(const std::string& filepath); + const std::set<std::string>* GetInstallComponents() const { return &this->InstallComponents; @@ -722,6 +728,8 @@ private: std::map<std::string, std::string> RealPaths; + std::unordered_set<std::string> GeneratedFiles; + #if !defined(CMAKE_BOOTSTRAP) // Pool of file locks cmFileLockPool FileLockPool; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 50a7d27..4e93785 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3406,11 +3406,7 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, bool generated, cmSourceFileLocationKind kind) { - auto sf = cm::make_unique<cmSourceFile>(this, sourceName, kind); - if (generated) { - sf->SetProperty("GENERATED", "1"); - } - + auto sf = cm::make_unique<cmSourceFile>(this, sourceName, generated, kind); auto name = this->GetCMakeInstance()->StripExtension(sf->GetLocation().GetName()); #if defined(_WIN32) || defined(__APPLE__) @@ -3442,7 +3438,7 @@ cmSourceFile* cmMakefile::GetOrCreateGeneratedSource( { cmSourceFile* sf = this->GetOrCreateSource(sourceName, true, cmSourceFileLocationKind::Known); - sf->SetProperty("GENERATED", "1"); + sf->MarkAsGenerated(); // In case we did not create the source file. return sf; } diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index f2696a6..f27b788 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1624,7 +1624,7 @@ cmSourceFile* cmQtAutoGenInitializer::RegisterGeneratedSource( std::string const& filename) { cmSourceFile* gFile = this->Makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); + gFile->MarkAsGenerated(); gFile->SetProperty("SKIP_AUTOGEN", "1"); return gFile; } diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index d3bcae9..970564d 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -298,7 +298,7 @@ bool HandleAndValidateSourceFilePropertyGENERATED( break; } } else { - // TODO: Mark source-file as generated! + sf->MarkAsGenerated(); } return true; } diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 517b570..9d9a7c3 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -16,9 +16,12 @@ #include "cmake.h" cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name, - cmSourceFileLocationKind kind) - : Location(mf, name, kind) + bool generated, cmSourceFileLocationKind kind) + : Location(mf, name, (!generated) ? kind : cmSourceFileLocationKind::Known) { + if (generated) { + this->MarkAsGenerated(); + } } std::string const& cmSourceFile::GetExtension() const @@ -26,6 +29,8 @@ std::string const& cmSourceFile::GetExtension() const return this->Extension; } +const std::string propTRUE = "1"; +const std::string propFALSE = "0"; const std::string cmSourceFile::propLANGUAGE = "LANGUAGE"; const std::string cmSourceFile::propLOCATION = "LOCATION"; const std::string cmSourceFile::propGENERATED = "GENERATED"; @@ -112,11 +117,14 @@ bool cmSourceFile::FindFullPath(std::string* error, std::string* cmp0115Warning) { // If the file is generated compute the location without checking on disk. - if (this->GetIsGenerated()) { + // Note: We also check for a locally set GENERATED property, because + // it might have been set before policy CMP0118 was set to NEW. + if (this->GetIsGenerated(CheckScope::GlobalAndLocal)) { // The file is either already a full path or is relative to the // build directory for the target. this->Location.DirectoryUseBinary(); this->FullPath = this->Location.GetFullPath(); + this->FindFullPathFailed = false; return true; } @@ -273,11 +281,6 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value) } else { this->Properties.SetProperty(prop, value); } - - // Update IsGenerated flag - if (prop == propGENERATED) { - this->IsGenerated = cmIsOn(value); - } } void cmSourceFile::AppendProperty(const std::string& prop, @@ -301,11 +304,6 @@ void cmSourceFile::AppendProperty(const std::string& prop, } else { this->Properties.AppendProperty(prop, value, asString); } - - // Update IsGenerated flag - if (prop == propGENERATED) { - this->IsGenerated = this->GetPropertyAsBool(propGENERATED); - } } cmProp cmSourceFile::GetPropertyForUser(const std::string& prop) @@ -336,6 +334,21 @@ cmProp cmSourceFile::GetPropertyForUser(const std::string& prop) return &this->GetOrDetermineLanguage(); } + // Special handling for GENERATED property. + if (prop == propGENERATED) { + // We need to check policy CMP0118 in order to determine if we need to + // possibly consider the value of a locally set GENERATED property, too. + auto policyStatus = + this->Location.GetMakefile()->GetPolicyStatus(cmPolicies::CMP0118); + if (this->GetIsGenerated( + (policyStatus == cmPolicies::WARN || policyStatus == cmPolicies::OLD) + ? CheckScope::GlobalAndLocal + : CheckScope::Global)) { + return &propTRUE; + } + return &propFALSE; + } + // Perform the normal property lookup. return this->GetProperty(prop); } @@ -411,11 +424,29 @@ bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const return cmIsOn(this->GetProperty(prop)); } +void cmSourceFile::MarkAsGenerated() +{ + this->IsGenerated = true; + auto& mf = *this->Location.GetMakefile(); + mf.GetGlobalGenerator()->MarkAsGeneratedFile(this->ResolveFullPath()); +} + +bool cmSourceFile::GetIsGenerated(CheckScope checkScope) const +{ + if (this->IsGenerated) { + // Globally marked as generated! + return true; + } + if (checkScope == CheckScope::GlobalAndLocal) { + // Check locally stored properties. + return this->GetPropertyAsBool(propGENERATED); + } + return false; +} + void cmSourceFile::SetProperties(cmPropertyMap properties) { this->Properties = std::move(properties); - - this->IsGenerated = this->GetPropertyAsBool(propGENERATED); } cmCustomCommand* cmSourceFile::GetCustomCommand() const diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 3ad2664..94b5cc8 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -20,18 +20,18 @@ class cmMakefile; /** \class cmSourceFile * \brief Represent a class loaded from a makefile. * - * cmSourceFile is represents a class loaded from - * a makefile. + * cmSourceFile represents a class loaded from a makefile. */ class cmSourceFile { public: /** - * Construct with the makefile storing the source and the initial - * name referencing it. + * Construct with the makefile storing the source and the initial name + * referencing it. If it shall be marked as generated, this source file's + * kind is assumed to be known, regardless of the given value. */ cmSourceFile( - cmMakefile* mf, const std::string& name, + cmMakefile* mf, const std::string& name, bool generated, cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); /** @@ -54,9 +54,29 @@ public: command like get_property or get_source_file_property. */ cmProp GetPropertyForUser(const std::string& prop); - //! Checks is the GENERATED property is set and true - /// @return Equivalent to GetPropertyAsBool("GENERATED") - bool GetIsGenerated() const { return this->IsGenerated; } + /// Marks this file as generated + /** + * This stores this file's path in the global table for all generated source + * files. + */ + void MarkAsGenerated(); + enum class CheckScope + { + Global, + GlobalAndLocal + }; + /// Determines if this source file is marked as generated. + /** + * This will check if this file's path is stored in the global table of all + * generated source files. If that is not the case and checkScope is set to + * GlobalAndLocal the value of the possibly existing local GENERATED property + * is returned instead. + * @param checkScope Determines if alternatively for backwards-compatibility + * a local GENERATED property should be considered, too. + * @return true if this source file is marked as generated, otherwise false. + */ + bool GetIsGenerated( + CheckScope checkScope = CheckScope::GlobalAndLocal) const; const std::vector<BT<std::string>>& GetCompileOptions() const { |