Merge topic 'file-set-name-requirements' into release-3.23

b357d334fc target_sources(): Enforce stricter requirements for FILE_SET name

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7037
This commit is contained in:
Brad King
2022-03-04 14:09:26 +00:00
committed by Kitware Robot
8 changed files with 30 additions and 4 deletions
+10
View File
@@ -7,6 +7,8 @@
#include <utility>
#include <vector>
#include "cmsys/RegularExpression.hxx"
#include "cmGeneratorExpression.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
@@ -149,3 +151,11 @@ void cmFileSet::EvaluateFileEntry(
filesPerDir[relDir].push_back(file);
}
}
bool cmFileSet::IsValidName(const std::string& name)
{
static const cmsys::RegularExpression regex("^[a-z0-9][a-zA-Z0-9_]*$");
cmsys::RegularExpressionMatch match;
return regex.find(name.c_str(), match);
}
+2
View File
@@ -56,6 +56,8 @@ public:
const cmGeneratorTarget* target,
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
static bool IsValidName(const std::string& name);
private:
std::string Name;
std::string Type;
+4 -3
View File
@@ -238,9 +238,10 @@ bool TargetSourcesImpl::HandleOneFileSet(
auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type);
if (fileSet.second) {
if (!isDefault) {
if (args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z') {
this->SetError(
"Non-default file set name must not start with a capital letter");
if (!cmFileSet::IsValidName(args.FileSet)) {
this->SetError("Non-default file set name must contain only letters, "
"numbers, and underscores, and must not start with a "
"capital letter or underscore");
return false;
}
}