mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-11 16:50:50 -05:00
cmCMakePathCommand: Report keyword errors via argument parser results
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmCMakePathCommand.h"
|
#include "cmCMakePathCommand.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -44,14 +43,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <int Advance = 2>
|
template <int Advance = 2>
|
||||||
Result Parse(
|
Result Parse(std::vector<std::string> const& args) const
|
||||||
std::vector<std::string> const& args,
|
|
||||||
std::vector<cm::string_view>* keywordsMissingValue = nullptr) const
|
|
||||||
{
|
{
|
||||||
this->Inputs.clear();
|
this->Inputs.clear();
|
||||||
|
|
||||||
return this->cmArgumentParser<Result>::Parse(
|
return this->cmArgumentParser<Result>::Parse(
|
||||||
cmMakeRange(args).advance(Advance), &this->Inputs, keywordsMissingValue);
|
cmMakeRange(args).advance(Advance), &this->Inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& GetInputs() const { return this->Inputs; }
|
const std::vector<std::string>& GetInputs() const { return this->Inputs; }
|
||||||
@@ -82,28 +79,13 @@ public:
|
|||||||
template <int Advance = 2>
|
template <int Advance = 2>
|
||||||
Result Parse(std::vector<std::string> const& args) const
|
Result Parse(std::vector<std::string> const& args) const
|
||||||
{
|
{
|
||||||
this->KeywordsMissingValue.clear();
|
|
||||||
|
|
||||||
return this->CMakePathArgumentParser<Result>::template Parse<Advance>(
|
return this->CMakePathArgumentParser<Result>::template Parse<Advance>(
|
||||||
args, &this->KeywordsMissingValue);
|
args);
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<cm::string_view>& GetKeywordsMissingValue() const
|
|
||||||
{
|
|
||||||
return this->KeywordsMissingValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkOutputVariable(const Result& arguments,
|
bool checkOutputVariable(const Result& arguments,
|
||||||
cmExecutionStatus& status) const
|
cmExecutionStatus& status) const
|
||||||
{
|
{
|
||||||
if (std::find(this->GetKeywordsMissingValue().begin(),
|
|
||||||
this->GetKeywordsMissingValue().end(),
|
|
||||||
"OUTPUT_VARIABLE"_s) !=
|
|
||||||
this->GetKeywordsMissingValue().end()) {
|
|
||||||
status.SetError("OUTPUT_VARIABLE requires an argument.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.Output && arguments.Output->empty()) {
|
if (arguments.Output && arguments.Output->empty()) {
|
||||||
status.SetError("Invalid name for output variable.");
|
status.SetError("Invalid name for output variable.");
|
||||||
return false;
|
return false;
|
||||||
@@ -111,12 +93,9 @@ public:
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
mutable std::vector<cm::string_view> KeywordsMissingValue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OutputVariable
|
struct OutputVariable : public ArgumentParser::ParseResult
|
||||||
{
|
{
|
||||||
cm::optional<std::string> Output;
|
cm::optional<std::string> Output;
|
||||||
};
|
};
|
||||||
@@ -288,6 +267,9 @@ bool HandleAppendCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
const auto arguments = parser.Parse(args);
|
const auto arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -310,6 +292,9 @@ bool HandleAppendStringCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
const auto arguments = parser.Parse(args);
|
const auto arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -337,6 +322,9 @@ bool HandleRemoveFilenameCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
const auto arguments = parser.Parse(args);
|
const auto arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -367,6 +355,9 @@ bool HandleReplaceFilenameCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
const auto arguments = parser.Parse(args);
|
const auto arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -394,7 +385,7 @@ bool HandleReplaceFilenameCommand(std::vector<std::string> const& args,
|
|||||||
bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
|
bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
struct Arguments
|
struct Arguments : public ArgumentParser::ParseResult
|
||||||
{
|
{
|
||||||
cm::optional<std::string> Output;
|
cm::optional<std::string> Output;
|
||||||
bool LastOnly = false;
|
bool LastOnly = false;
|
||||||
@@ -406,6 +397,9 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
Arguments const arguments = parser.Parse(args);
|
Arguments const arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -437,7 +431,7 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
|
|||||||
bool HandleReplaceExtensionCommand(std::vector<std::string> const& args,
|
bool HandleReplaceExtensionCommand(std::vector<std::string> const& args,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
struct Arguments
|
struct Arguments : public ArgumentParser::ParseResult
|
||||||
{
|
{
|
||||||
cm::optional<std::string> Output;
|
cm::optional<std::string> Output;
|
||||||
bool LastOnly = false;
|
bool LastOnly = false;
|
||||||
@@ -449,6 +443,9 @@ bool HandleReplaceExtensionCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
Arguments const arguments = parser.Parse(args);
|
Arguments const arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -486,6 +483,9 @@ bool HandleNormalPathCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
const auto arguments = parser.Parse(args);
|
const auto arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -514,7 +514,7 @@ bool HandleTransformPathCommand(
|
|||||||
const std::string& base)>& transform,
|
const std::string& base)>& transform,
|
||||||
bool normalizeOption = false)
|
bool normalizeOption = false)
|
||||||
{
|
{
|
||||||
struct Arguments
|
struct Arguments : public ArgumentParser::ParseResult
|
||||||
{
|
{
|
||||||
cm::optional<std::string> Output;
|
cm::optional<std::string> Output;
|
||||||
cm::optional<std::string> BaseDirectory;
|
cm::optional<std::string> BaseDirectory;
|
||||||
@@ -529,6 +529,9 @@ bool HandleTransformPathCommand(
|
|||||||
|
|
||||||
Arguments arguments = parser.Parse(args);
|
Arguments arguments = parser.Parse(args);
|
||||||
|
|
||||||
|
if (arguments.MaybeReportError(status.GetMakefile())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!parser.checkOutputVariable(arguments, status)) {
|
if (!parser.checkOutputVariable(arguments, status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -538,13 +541,6 @@ bool HandleTransformPathCommand(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::find(parser.GetKeywordsMissingValue().begin(),
|
|
||||||
parser.GetKeywordsMissingValue().end(), "BASE_DIRECTORY"_s) !=
|
|
||||||
parser.GetKeywordsMissingValue().end()) {
|
|
||||||
status.SetError("BASE_DIRECTORY requires an argument.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string baseDirectory;
|
std::string baseDirectory;
|
||||||
if (arguments.BaseDirectory) {
|
if (arguments.BaseDirectory) {
|
||||||
baseDirectory = *arguments.BaseDirectory;
|
baseDirectory = *arguments.BaseDirectory;
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
CMake Error at .+/cmake_path/call-cmake_path.cmake:[0-9]+ \(cmake_path\):
|
CMake Error at .+/cmake_path/call-cmake_path.cmake:[0-9]+ \(cmake_path\):
|
||||||
cmake_path BASE_DIRECTORY requires an argument.
|
Error after keyword "BASE_DIRECTORY":
|
||||||
|
|
||||||
|
missing required value
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
CMake Error at .+/cmake_path/call-cmake_path.cmake:[0-9]+ \(cmake_path\):
|
CMake Error at .+/cmake_path/call-cmake_path.cmake:[0-9]+ \(cmake_path\):
|
||||||
cmake_path OUTPUT_VARIABLE requires an argument.
|
Error after keyword "OUTPUT_VARIABLE":
|
||||||
|
|
||||||
|
missing required value
|
||||||
|
|||||||
Reference in New Issue
Block a user