mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Prefer cmHasSuffix for specific extension checks
This commit is contained in:
committed by
Brad King
parent
35af170961
commit
d932b6fb8d
@@ -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";
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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,
|
||||
"\". "
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user