De-duplicate validation of genex target names.
This commit is contained in:
parent
92e98dd909
commit
7c0ec75cfa
|
@ -375,6 +375,16 @@ std::string::size_type cmGeneratorExpression::Find(const std::string &input)
|
||||||
{
|
{
|
||||||
return openpos;
|
return openpos;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return std::string::npos;
|
return std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
|
||||||
|
{
|
||||||
|
cmsys::RegularExpression targetNameValidator;
|
||||||
|
// The ':' is supported to allow use with IMPORTED targets. At least
|
||||||
|
// Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
|
||||||
|
targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
|
||||||
|
|
||||||
|
return targetNameValidator.find(input.c_str());
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
|
|
||||||
static std::string::size_type Find(const std::string &input);
|
static std::string::size_type Find(const std::string &input);
|
||||||
|
|
||||||
|
static bool IsValidTargetName(const std::string &input);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmGeneratorExpression(const cmGeneratorExpression &);
|
cmGeneratorExpression(const cmGeneratorExpression &);
|
||||||
void operator=(const cmGeneratorExpression &);
|
void operator=(const cmGeneratorExpression &);
|
||||||
|
|
|
@ -333,10 +333,6 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
|
||||||
"$<TARGET_PROPERTY:...> expression requires one or two parameters");
|
"$<TARGET_PROPERTY:...> expression requires one or two parameters");
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
cmsys::RegularExpression targetNameValidator;
|
|
||||||
// The ':' is supported to allow use with IMPORTED targets. At least
|
|
||||||
// Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
|
|
||||||
targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
|
|
||||||
cmsys::RegularExpression propertyNameValidator;
|
cmsys::RegularExpression propertyNameValidator;
|
||||||
propertyNameValidator.compile("^[A-Za-z0-9_]+$");
|
propertyNameValidator.compile("^[A-Za-z0-9_]+$");
|
||||||
|
|
||||||
|
@ -372,7 +368,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
|
||||||
|
|
||||||
std::string targetName = parameters.front();
|
std::string targetName = parameters.front();
|
||||||
propertyName = parameters[1];
|
propertyName = parameters[1];
|
||||||
if (!targetNameValidator.find(targetName.c_str()))
|
if (!cmGeneratorExpression::IsValidTargetName(targetName))
|
||||||
{
|
{
|
||||||
if (!propertyNameValidator.find(propertyName.c_str()))
|
if (!propertyNameValidator.find(propertyName.c_str()))
|
||||||
{
|
{
|
||||||
|
@ -867,10 +863,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
|
||||||
// Lookup the referenced target.
|
// Lookup the referenced target.
|
||||||
std::string name = *parameters.begin();
|
std::string name = *parameters.begin();
|
||||||
|
|
||||||
cmsys::RegularExpression targetValidator;
|
if (!cmGeneratorExpression::IsValidTargetName(name))
|
||||||
// The ':' is supported to allow use with IMPORTED targets.
|
|
||||||
targetValidator.compile("^[A-Za-z0-9_.:-]+$");
|
|
||||||
if (!targetValidator.find(name.c_str()))
|
|
||||||
{
|
{
|
||||||
::reportError(context, content->GetOriginalExpression(),
|
::reportError(context, content->GetOriginalExpression(),
|
||||||
"Expression syntax not recognized.");
|
"Expression syntax not recognized.");
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
============================================================================*/
|
============================================================================*/
|
||||||
#include "cmTargetLinkLibrariesCommand.h"
|
#include "cmTargetLinkLibrariesCommand.h"
|
||||||
|
|
||||||
|
#include "cmGeneratorExpression.h"
|
||||||
|
|
||||||
const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
|
const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
|
||||||
{
|
{
|
||||||
"general",
|
"general",
|
||||||
|
@ -271,9 +273,8 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
|
||||||
{
|
{
|
||||||
const bool isGenex = cmGeneratorExpression::Find(lib) != std::string::npos;
|
const bool isGenex = cmGeneratorExpression::Find(lib) != std::string::npos;
|
||||||
|
|
||||||
cmsys::RegularExpression targetNameValidator;
|
const bool potentialTargetName
|
||||||
targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
|
= cmGeneratorExpression::IsValidTargetName(lib);
|
||||||
const bool potentialTargetName = targetNameValidator.find(lib);
|
|
||||||
|
|
||||||
if (potentialTargetName || isGenex)
|
if (potentialTargetName || isGenex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue