summaryrefslogtreecommitdiff
path: root/Source/cmSetPropertyCommand.cxx
diff options
context:
space:
mode:
authorDeniz Bahadir <dbahadir@benocs.com>2020-09-30 21:11:14 +0200
committerDeniz Bahadir <dbahadir@benocs.com>2020-11-24 17:54:54 +0100
commitca4ce458a3a14889b1018198b6580ddddfb039a5 (patch)
treeb9317dd5ea89209ffbc1f9b2dfa0313e09a8b691 /Source/cmSetPropertyCommand.cxx
parent0eb30f175e61a013db301ab1be242dd497be4add (diff)
downloadcmake-ca4ce458a3a14889b1018198b6580ddddfb039a5.tar.gz
GENERATED prop: Check CMP0118 policy and warn in certain situations
* Adding tests for CMP0118 being unset (aka set to `WARN`). * Adjusting the (unrelated) RunCMake.CMP0026 test to set CMP0118 to `NEW`, * Adjusting the (unrelated) RunCMake.Ninja test to set CMP0118 to `OLD`. * Adjusting the (unrelated) RunCMake.FileAPI test to set CMP0118 to `OLD`. Note: Setting CMP0118 to `NEW` and modifying the `GENERATED` property with `set_property` or `set_source_files_properties` will currently NOT set that property because the implementation is still to come.
Diffstat (limited to 'Source/cmSetPropertyCommand.cxx')
-rw-r--r--Source/cmSetPropertyCommand.cxx101
1 files changed, 100 insertions, 1 deletions
diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx
index 45fd43d8a3..d3bcae967c 100644
--- a/Source/cmSetPropertyCommand.cxx
+++ b/Source/cmSetPropertyCommand.cxx
@@ -10,9 +10,12 @@
#include "cmGlobalGenerator.h"
#include "cmInstalledFile.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmRange.h"
#include "cmSourceFile.h"
+#include "cmSourceFileLocation.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -216,8 +219,92 @@ void MakeSourceFilePathsAbsoluteIfNeeded(
source_files_absolute_paths.push_back(absolute_file_path);
}
}
+
+bool HandleAndValidateSourceFilePropertyGENERATED(
+ cmSourceFile* sf, std::string const& propertyValue, PropertyOp op)
+{
+ auto& mf = *sf->GetLocation().GetMakefile();
+ auto policyStatus = mf.GetPolicyStatus(cmPolicies::CMP0118);
+
+ const bool policyWARN = policyStatus == cmPolicies::WARN;
+ const bool policyNEW = policyStatus != cmPolicies::OLD && !policyWARN;
+
+ if (policyWARN) {
+ if (!cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0118),
+ "\nAttempt to set property 'GENERATED' with the following "
+ "non-boolean value (which will be interpreted as \"0\"):\n",
+ propertyValue,
+ "\nThat exact value will not be retrievable. A value of "
+ "\"0\" will be returned instead.\n"
+ "This will be an error under policy CMP0118.\n"));
+ }
+ if (cmIsOff(propertyValue)) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0118),
+ "\nUnsetting property 'GENERATED' will not be allowed under "
+ "policy CMP0118!\n"));
+ }
+ if (op == PropertyOp::Append || op == PropertyOp::AppendAsString) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0118),
+ "\nAppending to property 'GENERATED' will not be allowed "
+ "under policy CMP0118!\n"));
+ }
+ } else if (policyNEW) {
+ if (!cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_ERROR,
+ cmStrCat(
+ "Policy CMP0118 is set to NEW and the following non-boolean value "
+ "given for property 'GENERATED' is therefore not allowed:\n",
+ propertyValue, "\nReplace it with a boolean value!\n"));
+ return true;
+ }
+ if (cmIsOff(propertyValue)) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_ERROR,
+ "Unsetting the 'GENERATED' property is not allowed under CMP0118!\n");
+ return true;
+ }
+ if (op == PropertyOp::Append || op == PropertyOp::AppendAsString) {
+ mf.IssueMessage(MessageType::AUTHOR_ERROR,
+ "Policy CMP0118 is set to NEW and appending to the "
+ "'GENERATED' property is therefore not allowed. Only "
+ "setting it to \"1\" is allowed!\n");
+ return true;
+ }
+ }
+
+ // Set property.
+ if (!policyNEW) {
+ // Do it the traditional way.
+ switch (op) {
+ case PropertyOp::Append:
+ sf->AppendProperty("GENERATED", propertyValue, false);
+ break;
+ case PropertyOp::AppendAsString:
+ sf->AppendProperty("GENERATED", propertyValue, true);
+ break;
+ case PropertyOp::Remove:
+ sf->SetProperty("GENERATED", nullptr);
+ break;
+ case PropertyOp::Set:
+ sf->SetProperty("GENERATED", propertyValue.c_str());
+ break;
+ }
+ } else {
+ // TODO: Mark source-file as generated!
+ }
+ return true;
}
+} // END: namespace SetPropertyCommand
+
bool cmSetPropertyCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -367,7 +454,7 @@ bool cmSetPropertyCommand(std::vector<std::string> const& args,
return true;
}
-namespace {
+namespace /* anonymous */ {
bool HandleGlobalMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
@@ -525,6 +612,18 @@ bool HandleSource(cmSourceFile* sf, const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove)
{
+ // Special validation and handling of GENERATED flag?
+ if (propertyName == "GENERATED") {
+ SetPropertyCommand::PropertyOp op = (remove)
+ ? SetPropertyCommand::PropertyOp::Remove
+ : (appendAsString)
+ ? SetPropertyCommand::PropertyOp::AppendAsString
+ : (appendMode) ? SetPropertyCommand::PropertyOp::Append
+ : SetPropertyCommand::PropertyOp::Set;
+ return SetPropertyCommand::HandleAndValidateSourceFilePropertyGENERATED(
+ sf, propertyValue, op);
+ }
+
// Set or append the property.
if (appendMode) {
sf->AppendProperty(propertyName, propertyValue, appendAsString);