[Cmake-commits] [cmake-commits] king committed cmMakefile.cxx 1.478 1.479 cmMakefile.h 1.233 1.234 cmPolicies.cxx 1.31 1.32 cmPolicies.h 1.16 1.17
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Aug 18 16:29:02 EDT 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv17174/Source
Modified Files:
cmMakefile.cxx cmMakefile.h cmPolicies.cxx cmPolicies.h
Log Message:
ENH: Improve errors when a policy is REQUIRED
In the future some policies may be set to REQUIRED_IF_USED or
REQUIRED_ALWAYS. This change clarifies the error messages users receive
when violating the requirements.
Index: cmPolicies.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C 2 -d -r1.16 -r1.17
*** cmPolicies.h 23 Jul 2008 16:59:14 -0000 1.16
--- cmPolicies.h 18 Aug 2008 20:29:00 -0000 1.17
***************
*** 76,87 ****
bool ApplyPolicyVersion(cmMakefile *mf, const char *version);
- ///! test to see if setting a policy to a specific value is valid
- bool IsValidPolicyStatus(cmPolicies::PolicyID id,
- cmPolicies::PolicyStatus status);
-
- ///! test to see if setting a policy to a specific value is valid, when used
- bool IsValidUsedPolicyStatus(cmPolicies::PolicyID id,
- cmPolicies::PolicyStatus status);
-
///! return a warning string for a given policy
std::string GetPolicyWarning(cmPolicies::PolicyID id);
--- 76,79 ----
***************
*** 90,93 ****
--- 82,88 ----
std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
+ ///! return an error string for when a required policy is unspecified
+ std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
+
///! Get docs for policies
void GetDocumentation(std::vector<cmDocumentationEntry>& v);
***************
*** 97,101 ****
std::map<PolicyID,cmPolicy *> Policies;
std::map<std::string,PolicyID> PolicyStringMap;
!
};
--- 92,99 ----
std::map<PolicyID,cmPolicy *> Policies;
std::map<std::string,PolicyID> PolicyStringMap;
!
! void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
! unsigned int majorVer, unsigned int minorVer,
! unsigned int patchVer, cmMakefile* mf);
};
Index: cmPolicies.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.cxx,v
retrieving revision 1.31
retrieving revision 1.32
diff -C 2 -d -r1.31 -r1.32
*** cmPolicies.cxx 23 Jul 2008 16:59:14 -0000 1.31
--- cmPolicies.cxx 18 Aug 2008 20:29:00 -0000 1.32
***************
*** 348,351 ****
--- 348,352 ----
}
+ //----------------------------------------------------------------------------
bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
const char *version)
***************
*** 409,412 ****
--- 410,414 ----
// now loop over all the policies and set them as appropriate
+ std::vector<cmPolicies::PolicyID> ancientPolicies;
std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
= this->Policies.begin();
***************
*** 415,419 ****
if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
{
! if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
{
return false;
--- 417,425 ----
if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
{
! if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
! {
! ancientPolicies.push_back(i->first);
! }
! else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
{
return false;
***************
*** 428,530 ****
}
}
- return true;
- }
! // is this a valid status the listfile can set this policy to?
! bool cmPolicies::IsValidPolicyStatus(cmPolicies::PolicyID id,
! cmPolicies::PolicyStatus status)
! {
! // if they are setting a feature to anything other than OLD or WARN and the
! // feature is not known about then that is an error
! if (this->Policies.find(id) == this->Policies.end())
! {
! if (status == cmPolicies::WARN ||
! status == cmPolicies::OLD)
{
! return true;
! }
! cmOStringStream error;
! error <<
! "Error: an attempt was made to enable the new behavior for " <<
! "a new feature that is in a later version of CMake than "
! "what you are runing, please upgrade to a newer version "
! "of CMake.";
! cmSystemTools::Error(error.str().c_str());
! return false;
! }
!
! // now we know the feature is defined, so the only issue is if someone is
! // setting it to WARN or OLD when the feature is REQUIRED_ALWAYS
! if ((status == cmPolicies::WARN ||
! status == cmPolicies::OLD) &&
! this->Policies[id]->Status == cmPolicies::REQUIRED_ALWAYS)
! {
! cmOStringStream error;
! error <<
! "Error: an attempt was made to enable the old behavior for " <<
! "a feature that is no longer supported. The feature in " <<
! "question is feature " <<
! id <<
! " which had new behavior introduced in CMake version " <<
! this->Policies[id]->GetVersionString() <<
! " please either update your CMakeLists files to conform to " <<
! "the new behavior " <<
! "or use an older version of CMake that still supports " <<
! "the old behavior. Run cmake --help-policies " <<
! id << " for more information.";
! cmSystemTools::Error(error.str().c_str());
return false;
- }
-
- return true;
- }
-
- // is this a valid status the listfile can set this policy to?
- bool cmPolicies::IsValidUsedPolicyStatus(cmPolicies::PolicyID id,
- cmPolicies::PolicyStatus status)
- {
- // if they are setting a feature to anything other than OLD or WARN and the
- // feature is not known about then that is an error
- if (this->Policies.find(id) == this->Policies.end())
- {
- if (status == cmPolicies::WARN ||
- status == cmPolicies::OLD)
- {
- return true;
}
- cmOStringStream error;
- error <<
- "Error: an attempt was made to enable the new behavior for " <<
- "a new feature that is in a later version of CMake than "
- "what you are runing, please upgrade to a newer version "
- "of CMake.";
- cmSystemTools::Error(error.str().c_str());
- return false;
- }
- // now we know the feature is defined, so the only issue is if someone is
- // setting it to WARN or OLD when the feature is REQUIRED_ALWAYS
- if ((status == cmPolicies::WARN ||
- status == cmPolicies::OLD) &&
- (this->Policies[id]->Status == cmPolicies::REQUIRED_ALWAYS ||
- this->Policies[id]->Status == cmPolicies::REQUIRED_IF_USED))
- {
- cmOStringStream error;
- error <<
- "Error: an attempt was made to enable the old behavior for " <<
- "a feature that is no longer supported. The feature in " <<
- "question is feature " <<
- id <<
- " which had new behavior introduced in CMake version " <<
- this->Policies[id]->GetVersionString() <<
- " please either update your CMakeLists files to conform to " <<
- "the new behavior " <<
- "or use an older version of CMake that still supports " <<
- "the old behavior. Run cmake --help-policies " <<
- id << " for more information.";
- cmSystemTools::Error(error.str().c_str());
- return false;
- }
-
return true;
}
--- 434,447 ----
}
}
! // Make sure the project does not use any ancient policies.
! if(!ancientPolicies.empty())
{
! this->DiagnoseAncientPolicies(ancientPolicies,
! majorVer, minorVer, patchVer, mf);
! cmSystemTools::SetFatalErrorOccured();
return false;
}
return true;
}
***************
*** 672,673 ****
--- 589,635 ----
}
}
+
+ //----------------------------------------------------------------------------
+ std::string
+ cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
+ {
+ std::string pid = this->GetPolicyIDString(id);
+ cmOStringStream e;
+ e << "Policy " << pid << " may not be set to OLD behavior because this "
+ << "version of CMake no longer supports it. "
+ << "The policy was introduced in "
+ << "CMake version " << this->Policies[id]->GetVersionString()
+ << ", and use of NEW behavior is now required."
+ << "\n"
+ << "Please either update your CMakeLists.txt files to conform to "
+ << "the new behavior or use an older version of CMake that still "
+ << "supports the old behavior. "
+ << "Run cmake --help-policy " << pid << " for more information.";
+ return e.str();
+ }
+
+ //----------------------------------------------------------------------------
+ void
+ cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
+ unsigned int majorVer,
+ unsigned int minorVer,
+ unsigned int patchVer,
+ cmMakefile* mf)
+ {
+ cmOStringStream e;
+ e << "The project requests behavior compatible with CMake version \""
+ << majorVer << "." << minorVer << "." << patchVer
+ << "\", which requires OLD the behavior for some policies:\n";
+ for(std::vector<PolicyID>::const_iterator
+ i = ancient.begin(); i != ancient.end(); ++i)
+ {
+ cmPolicy const* policy = this->Policies[*i];
+ e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
+ }
+ e << "However, this version of CMake no longer supports the OLD "
+ << "behavior for these policies. "
+ << "Please either update your CMakeLists.txt files to conform to "
+ << "the new behavior or use an older version of CMake that still "
+ << "supports the old behavior.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ }
Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.233
retrieving revision 1.234
diff -C 2 -d -r1.233 -r1.234
*** cmMakefile.h 26 Jun 2008 17:30:10 -0000 1.233
--- cmMakefile.h 18 Aug 2008 20:29:00 -0000 1.234
***************
*** 901,904 ****
--- 901,905 ----
cmPolicies::PolicyStatus> PolicyMap;
std::vector<PolicyMap> PolicyStack;
+ cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
bool CheckCMP0000;
Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.478
retrieving revision 1.479
diff -C 2 -d -r1.478 -r1.479
*** cmMakefile.cxx 31 Jul 2008 14:33:25 -0000 1.478
--- cmMakefile.cxx 18 Aug 2008 20:29:00 -0000 1.479
***************
*** 3461,3508 ****
}
! cmPolicies::PolicyStatus cmMakefile
! ::GetPolicyStatus(cmPolicies::PolicyID id)
{
! cmPolicies::PolicyStatus status = cmPolicies::REQUIRED_IF_USED;
! PolicyMap::iterator mappos;
! int vecpos;
! bool done = false;
! // check our policy stack first
! for (vecpos = static_cast<int>(this->PolicyStack.size()) - 1;
! vecpos >= 0 && !done; vecpos--)
! {
! mappos = this->PolicyStack[vecpos].find(id);
! if (mappos != this->PolicyStack[vecpos].end())
{
! status = mappos->second;
! done = true;
}
! }
!
! // if not found then
! if (!done)
! {
! // pass the buck to our parent if we have one
! if (this->LocalGenerator->GetParent())
{
! cmMakefile *parent =
! this->LocalGenerator->GetParent()->GetMakefile();
! return parent->GetPolicyStatus(id);
}
! // otherwise use the default
! else
{
! status = this->GetPolicies()->GetPolicyStatus(id);
}
! }
!
! // warn if we see a REQUIRED_IF_USED above a OLD or WARN
! if (!this->GetPolicies()->IsValidUsedPolicyStatus(id,status))
! {
! return cmPolicies::REQUIRED_IF_USED;
! }
!
! return status;
}
--- 3461,3517 ----
}
! //----------------------------------------------------------------------------
! cmPolicies::PolicyStatus
! cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id)
{
! // Get the current setting of the policy.
! cmPolicies::PolicyStatus cur = this->GetPolicyStatusInternal(id);
! // If the policy is required to be set to NEW but is not, ignore the
! // current setting and tell the caller.
! if(cur != cmPolicies::NEW)
{
! if(cur == cmPolicies::REQUIRED_ALWAYS ||
! cur == cmPolicies::REQUIRED_IF_USED)
! {
! return cur;
! }
! cmPolicies::PolicyStatus def = this->GetPolicies()->GetPolicyStatus(id);
! if(def == cmPolicies::REQUIRED_ALWAYS ||
! def == cmPolicies::REQUIRED_IF_USED)
! {
! return def;
! }
}
!
! // The current setting is okay.
! return cur;
! }
!
! //----------------------------------------------------------------------------
! cmPolicies::PolicyStatus
! cmMakefile::GetPolicyStatusInternal(cmPolicies::PolicyID id)
! {
! // Is the policy set in our stack?
! for(std::vector<PolicyMap>::reverse_iterator
! psi = this->PolicyStack.rbegin();
! psi != this->PolicyStack.rend(); ++psi)
{
! PolicyMap::const_iterator pse = psi->find(id);
! if(pse != psi->end())
! {
! return pse->second;
! }
}
!
! // If we have a parent directory, recurse up to it.
! if(this->LocalGenerator->GetParent())
{
! cmMakefile* parent = this->LocalGenerator->GetParent()->GetMakefile();
! return parent->GetPolicyStatusInternal(id);
}
!
! // The policy is not set. Use the default for this CMake version.
! return this->GetPolicies()->GetPolicyStatus(id);
}
***************
*** 3521,3555 ****
}
! bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
cmPolicies::PolicyStatus status)
{
! // setting a REQUIRED_ALWAYS policy to WARN or OLD is an insta error
! if (this->GetPolicies()->
! IsValidPolicyStatus(id,status))
! {
! this->PolicyStack.back()[id] = status;
! // Special hook for presenting compatibility variable as soon as
! // the user requests it.
! if(id == cmPolicies::CMP0001 &&
! (status == cmPolicies::WARN || status == cmPolicies::OLD))
{
! if(!(this->GetCacheManager()
! ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
! {
! // Set it to 2.4 because that is the last version where the
! // variable had meaning.
! this->AddCacheDefinition
! ("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
! "For backwards compatibility, what version of CMake "
! "commands and "
! "syntax should this version of CMake try to support.",
! cmCacheManager::STRING);
! }
}
! return true;
! }
! return false;
}
--- 3530,3571 ----
}
! //----------------------------------------------------------------------------
! bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
cmPolicies::PolicyStatus status)
{
! // A REQUIRED_ALWAYS policy may be set only to NEW.
! if(status != cmPolicies::NEW &&
! this->GetPolicies()->GetPolicyStatus(id) ==
! cmPolicies::REQUIRED_ALWAYS)
! {
! std::string msg =
! this->GetPolicies()->GetRequiredAlwaysPolicyError(id);
! this->IssueMessage(cmake::FATAL_ERROR, msg.c_str());
! return false;
! }
! // Store the setting.
! this->PolicyStack.back()[id] = status;
!
! // Special hook for presenting compatibility variable as soon as
! // the user requests it.
! if(id == cmPolicies::CMP0001 &&
! (status == cmPolicies::WARN || status == cmPolicies::OLD))
! {
! if(!(this->GetCacheManager()
! ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
{
! // Set it to 2.4 because that is the last version where the
! // variable had meaning.
! this->AddCacheDefinition
! ("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
! "For backwards compatibility, what version of CMake "
! "commands and "
! "syntax should this version of CMake try to support.",
! cmCacheManager::STRING);
}
+ }
! return true;
}
More information about the Cmake-commits
mailing list