mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-26 10:48:38 -06:00
cmake: Ignore any empty "" command line arguments
Don't treat empty quote arguments("") as the current working
directory but instead ignore them.
Fixes #23217
This commit is contained in:
committed by
Brad King
parent
67f97f5478
commit
f73457ca2e
@@ -544,6 +544,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||||||
"-C", "-C must be followed by a file name.",
|
"-C", "-C must be followed by a file name.",
|
||||||
CommandArgument::Values::One, CommandArgument::RequiresSeparator::No,
|
CommandArgument::Values::One, CommandArgument::RequiresSeparator::No,
|
||||||
[&](std::string const& value, cmake* state) -> bool {
|
[&](std::string const& value, cmake* state) -> bool {
|
||||||
|
if (value.empty()) {
|
||||||
|
cmSystemTools::Error("No file name specified for -C");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
cmSystemTools::Stdout("loading initial cache file " + value + "\n");
|
cmSystemTools::Stdout("loading initial cache file " + value + "\n");
|
||||||
// Resolve script path specified on command line
|
// Resolve script path specified on command line
|
||||||
// relative to $PWD.
|
// relative to $PWD.
|
||||||
@@ -800,7 +804,18 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
ListPresets listPresets = ListPresets::None;
|
ListPresets listPresets = ListPresets::None;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto EmptyStringArgLambda = [](std::string const&, cmake* state) -> bool {
|
||||||
|
state->IssueMessage(
|
||||||
|
MessageType::WARNING,
|
||||||
|
"Ignoring empty string (\"\") provided on the command line.");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
auto SourceArgLambda = [](std::string const& value, cmake* state) -> bool {
|
auto SourceArgLambda = [](std::string const& value, cmake* state) -> bool {
|
||||||
|
if (value.empty()) {
|
||||||
|
cmSystemTools::Error("No source directory specified for -S");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::string path = cmSystemTools::CollapseFullPath(value);
|
std::string path = cmSystemTools::CollapseFullPath(value);
|
||||||
cmSystemTools::ConvertToUnixSlashes(path);
|
cmSystemTools::ConvertToUnixSlashes(path);
|
||||||
state->SetHomeDirectory(path);
|
state->SetHomeDirectory(path);
|
||||||
@@ -808,6 +823,10 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto BuildArgLambda = [&](std::string const& value, cmake* state) -> bool {
|
auto BuildArgLambda = [&](std::string const& value, cmake* state) -> bool {
|
||||||
|
if (value.empty()) {
|
||||||
|
cmSystemTools::Error("No build directory specified for -B");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::string path = cmSystemTools::CollapseFullPath(value);
|
std::string path = cmSystemTools::CollapseFullPath(value);
|
||||||
cmSystemTools::ConvertToUnixSlashes(path);
|
cmSystemTools::ConvertToUnixSlashes(path);
|
||||||
state->SetHomeOutputDirectory(path);
|
state->SetHomeOutputDirectory(path);
|
||||||
@@ -836,6 +855,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<CommandArgument> arguments = {
|
std::vector<CommandArgument> arguments = {
|
||||||
|
CommandArgument{ "", CommandArgument::Values::Zero, EmptyStringArgLambda },
|
||||||
CommandArgument{ "-S", "No source directory specified for -S",
|
CommandArgument{ "-S", "No source directory specified for -S",
|
||||||
CommandArgument::Values::One,
|
CommandArgument::Values::One,
|
||||||
CommandArgument::RequiresSeparator::No, SourceArgLambda },
|
CommandArgument::RequiresSeparator::No, SourceArgLambda },
|
||||||
@@ -1179,8 +1199,8 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
|
|
||||||
if (!extraProvidedPath.empty() && !scriptMode) {
|
if (!extraProvidedPath.empty() && !scriptMode) {
|
||||||
this->IssueMessage(MessageType::WARNING,
|
this->IssueMessage(MessageType::WARNING,
|
||||||
cmStrCat("Ignoring extra path from command line:\n ",
|
cmStrCat("Ignoring extra path from command line:\n \"",
|
||||||
extraProvidedPath));
|
extraProvidedPath, "\""));
|
||||||
}
|
}
|
||||||
if (!possibleUnknownArg.empty() && !scriptMode) {
|
if (!possibleUnknownArg.empty() && !scriptMode) {
|
||||||
cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg));
|
cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
^CMake Warning:
|
^CMake Warning:
|
||||||
Ignoring extra path from command line:
|
Ignoring extra path from command line:
|
||||||
|
|
||||||
/extra/path/$
|
"/extra/path/"$
|
||||||
|
|||||||
1
Tests/RunCMake/CommandLine/B-no-arg3-result.txt
Normal file
1
Tests/RunCMake/CommandLine/B-no-arg3-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
1
Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
^CMake Error: No build directory specified for -B
|
||||||
1
Tests/RunCMake/CommandLine/C-no-arg2-result.txt
Normal file
1
Tests/RunCMake/CommandLine/C-no-arg2-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
2
Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt
Normal file
2
Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
^CMake Error: -C must be followed by a file name.
|
||||||
|
CMake Error: Run 'cmake --help' for all supported options.$
|
||||||
1
Tests/RunCMake/CommandLine/C-no-arg3-result.txt
Normal file
1
Tests/RunCMake/CommandLine/C-no-arg3-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
1
Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
^CMake Error: No file name specified for -C
|
||||||
@@ -7,6 +7,10 @@ run_cmake_command(InvalidArg1 ${CMAKE_COMMAND} -invalid)
|
|||||||
run_cmake_command(InvalidArg2 ${CMAKE_COMMAND} --invalid)
|
run_cmake_command(InvalidArg2 ${CMAKE_COMMAND} --invalid)
|
||||||
run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
|
run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
|
||||||
run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
|
run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
|
||||||
|
run_cmake_command(C-no-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -C -T)
|
||||||
|
set(RunCMake_TEST_RAW_ARGS [[-C ""]])
|
||||||
|
run_cmake_command(C-no-arg3 ${CMAKE_COMMAND} -B DummyBuildDir)
|
||||||
|
unset(RunCMake_TEST_RAW_ARGS)
|
||||||
run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
|
run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
|
||||||
run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
|
run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
|
||||||
run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
|
run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
|
||||||
@@ -158,8 +162,11 @@ endif()
|
|||||||
run_cmake_with_options(S-arg-reverse-order ${binary_dir} -S${source_dir} )
|
run_cmake_with_options(S-arg-reverse-order ${binary_dir} -S${source_dir} )
|
||||||
run_cmake_with_options(S-no-arg -S )
|
run_cmake_with_options(S-no-arg -S )
|
||||||
run_cmake_with_options(S-no-arg2 -S -T)
|
run_cmake_with_options(S-no-arg2 -S -T)
|
||||||
|
run_cmake_with_raw_args(S-no-arg3 [[-S ""]])
|
||||||
run_cmake_with_options(S-B -S ${source_dir} -B ${binary_dir})
|
run_cmake_with_options(S-B -S ${source_dir} -B ${binary_dir})
|
||||||
run_cmake_with_options(S-B-extra-path -S ${source_dir} -B ${binary_dir} /extra/path/)
|
run_cmake_with_options(S-B-extra-path -S ${source_dir} -B ${binary_dir} /extra/path/)
|
||||||
|
run_cmake_with_raw_args(S-B-non-path "-S \"${source_dir}\" -B \"${binary_dir}\" \"\"")
|
||||||
|
run_cmake_with_raw_args(S-B-non-path2 "-S \"${source_dir}\" \"\" -B \"${binary_dir}\"")
|
||||||
|
|
||||||
# make sure that -B can explicitly construct build directories
|
# make sure that -B can explicitly construct build directories
|
||||||
file(REMOVE_RECURSE "${binary_dir}")
|
file(REMOVE_RECURSE "${binary_dir}")
|
||||||
@@ -168,6 +175,7 @@ endif()
|
|||||||
run_cmake_with_options(B-arg-reverse-order ${source_dir} -B${binary_dir})
|
run_cmake_with_options(B-arg-reverse-order ${source_dir} -B${binary_dir})
|
||||||
run_cmake_with_options(B-no-arg -B )
|
run_cmake_with_options(B-no-arg -B )
|
||||||
run_cmake_with_options(B-no-arg2 -B -T)
|
run_cmake_with_options(B-no-arg2 -B -T)
|
||||||
|
run_cmake_with_raw_args(B-no-arg3 [[-B ""]])
|
||||||
file(REMOVE_RECURSE "${binary_dir}")
|
file(REMOVE_RECURSE "${binary_dir}")
|
||||||
run_cmake_with_options(B-S -B${binary_dir} -S${source_dir})
|
run_cmake_with_options(B-S -B${binary_dir} -S${source_dir})
|
||||||
run_cmake_with_options(B-S-extra-path -B${binary_dir} -S${source_dir} /extra/path/)
|
run_cmake_with_options(B-S-extra-path -B${binary_dir} -S${source_dir} /extra/path/)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
^CMake Warning:
|
^CMake Warning:
|
||||||
Ignoring extra path from command line:
|
Ignoring extra path from command line:
|
||||||
|
|
||||||
/extra/path/$
|
"/extra/path/"$
|
||||||
|
|||||||
2
Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt
Normal file
2
Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
^CMake Warning:
|
||||||
|
Ignoring empty string \(""\) provided on the command line\.$
|
||||||
2
Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt
Normal file
2
Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
^CMake Warning:
|
||||||
|
Ignoring empty string \(""\) provided on the command line\.$
|
||||||
1
Tests/RunCMake/CommandLine/S-no-arg3-result.txt
Normal file
1
Tests/RunCMake/CommandLine/S-no-arg3-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
1
Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
^CMake Error: No source directory specified for -S
|
||||||
Reference in New Issue
Block a user