Prefer cmHasSuffix for specific extension checks

This commit is contained in:
John Franklin Rickard
2026-02-06 12:27:23 -05:00
committed by Brad King
parent 35af170961
commit d932b6fb8d
5 changed files with 8 additions and 11 deletions
+2 -4
View File
@@ -131,8 +131,7 @@ static bool HandleTargetsMode(std::vector<std::string> const& args,
fname = arguments.ExportSetName + ".cmake";
} else {
// Make sure the file has a .cmake extension.
if (cmSystemTools::GetFilenameLastExtensionView(arguments.Filename) !=
".cmake") {
if (!cmHasSuffix(arguments.Filename, ".cmake"_s)) {
std::ostringstream e;
e << "FILE option given filename \"" << arguments.Filename
<< "\" which does not have an extension of \".cmake\".\n";
@@ -296,8 +295,7 @@ static bool HandleExportMode(std::vector<std::string> const& args,
if (arguments.Filename.empty()) {
fname = arguments.ExportSetName + ".cmake";
} else {
if (cmSystemTools::GetFilenameLastExtensionView(arguments.Filename) !=
".cmake") {
if (!cmHasSuffix(arguments.Filename, ".cmake"_s)) {
std::ostringstream e;
e << "FILE option given filename \"" << arguments.Filename
<< "\" which does not have an extension of \".cmake\".\n";
+1 -1
View File
@@ -881,7 +881,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
this->AddPathSuffix(args[i]);
} else if (doing == DoingConfigs) {
if (args[i].find_first_of(":/\\") != std::string::npos ||
cmSystemTools::GetFilenameLastExtensionView(args[i]) != ".cmake") {
!cmHasSuffix(args[i], ".cmake"_s)) {
this->SetError(cmStrCat(
"given CONFIGS option followed by invalid file name \"", args[i],
"\". The names given must be file names without "
+2 -4
View File
@@ -1990,8 +1990,7 @@ bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
}
// Check the file extension.
if (!fname.empty() &&
cmSystemTools::GetFilenameLastExtensionView(fname) != ".mk") {
if (!fname.empty() && !cmHasSuffix(fname, ".mk"_s)) {
status.SetError(cmStrCat(
args[0], " given invalid export file name \"", fname,
R"(". The FILE argument must specify a name ending in ".mk".)"));
@@ -2249,8 +2248,7 @@ bool HandleExportMode(std::vector<std::string> const& args,
}
// Check the file extension.
if (!fname.empty() &&
cmSystemTools::GetFilenameLastExtensionView(fname) != ".cmake") {
if (!fname.empty() && !cmHasSuffix(fname, ".cmake"_s)) {
status.SetError(
cmStrCat(args[0], " given invalid export file name \"", fname,
"\". "
+1 -1
View File
@@ -2321,7 +2321,7 @@ bool cmLocalGenerator::GetRealDependency(std::string const& inName,
if (name.empty()) {
return false;
}
if (cmSystemTools::GetFilenameLastExtensionView(name) == ".exe") {
if (cmHasSuffix(name, ".exe"_s)) {
name = cmSystemTools::GetFilenameWithoutLastExtension(name);
}
+2 -1
View File
@@ -6,6 +6,7 @@
#include <utility>
#include <cmext/algorithm>
#include <cmext/string_view>
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
@@ -168,7 +169,7 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
// that case the target name will be the file basename of the
// dependency.
std::string util;
if (cmSystemTools::GetFilenameLastExtensionView(dep) == ".exe") {
if (cmHasSuffix(dep, ".exe"_s)) {
util = cmSystemTools::GetFilenameWithoutLastExtension(dep);
} else {
util = cmSystemTools::GetFilenameName(dep);