summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-02-17 13:45:45 +0000
committerKitware Robot <kwrobot@kitware.com>2022-02-17 08:45:52 -0500
commit9c81f2cb8bcb5f4ad96f2ad527035649bd70d5fc (patch)
treedb1cd55736b9bcdd96ba70016cee8028cc0e9085
parented9e7a27324ec54cc1a0ae9397ae5b49f0c9bab3 (diff)
parentf73457ca2ecb7abe66050910d74a37f80d10de2e (diff)
downloadcmake-9c81f2cb8bcb5f4ad96f2ad527035649bd70d5fc.tar.gz
Merge topic 'cmake-empty-cmd-line-arg' into release-3.23
f73457ca2e cmake: Ignore any empty "" command line arguments 67f97f5478 Tests: Add RunCMake helper to run cmake with raw execute_process args Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6980
-rw-r--r--Source/cmake.cxx24
-rw-r--r--Tests/RunCMake/CommandLine/B-S-extra-path-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/B-no-arg3-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/C-no-arg2-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/C-no-arg3-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CommandLine/S-B-extra-path-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/S-no-arg3-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt1
-rw-r--r--Tests/RunCMake/RunCMake.cmake17
15 files changed, 60 insertions, 6 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index e1ba12c210..d80c4bc6e7 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -544,6 +544,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
"-C", "-C must be followed by a file name.",
CommandArgument::Values::One, CommandArgument::RequiresSeparator::No,
[&](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");
// Resolve script path specified on command line
// relative to $PWD.
@@ -800,7 +804,18 @@ void cmake::SetArgs(const std::vector<std::string>& args)
ListPresets listPresets = ListPresets::None;
#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 {
+ if (value.empty()) {
+ cmSystemTools::Error("No source directory specified for -S");
+ return false;
+ }
std::string path = cmSystemTools::CollapseFullPath(value);
cmSystemTools::ConvertToUnixSlashes(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 {
+ if (value.empty()) {
+ cmSystemTools::Error("No build directory specified for -B");
+ return false;
+ }
std::string path = cmSystemTools::CollapseFullPath(value);
cmSystemTools::ConvertToUnixSlashes(path);
state->SetHomeOutputDirectory(path);
@@ -836,6 +855,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
};
std::vector<CommandArgument> arguments = {
+ CommandArgument{ "", CommandArgument::Values::Zero, EmptyStringArgLambda },
CommandArgument{ "-S", "No source directory specified for -S",
CommandArgument::Values::One,
CommandArgument::RequiresSeparator::No, SourceArgLambda },
@@ -1179,8 +1199,8 @@ void cmake::SetArgs(const std::vector<std::string>& args)
if (!extraProvidedPath.empty() && !scriptMode) {
this->IssueMessage(MessageType::WARNING,
- cmStrCat("Ignoring extra path from command line:\n ",
- extraProvidedPath));
+ cmStrCat("Ignoring extra path from command line:\n \"",
+ extraProvidedPath, "\""));
}
if (!possibleUnknownArg.empty() && !scriptMode) {
cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg));
diff --git a/Tests/RunCMake/CommandLine/B-S-extra-path-stderr.txt b/Tests/RunCMake/CommandLine/B-S-extra-path-stderr.txt
index 8794f74bb2..e168a1b4e7 100644
--- a/Tests/RunCMake/CommandLine/B-S-extra-path-stderr.txt
+++ b/Tests/RunCMake/CommandLine/B-S-extra-path-stderr.txt
@@ -1,4 +1,4 @@
^CMake Warning:
Ignoring extra path from command line:
- /extra/path/$
+ "/extra/path/"$
diff --git a/Tests/RunCMake/CommandLine/B-no-arg3-result.txt b/Tests/RunCMake/CommandLine/B-no-arg3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/B-no-arg3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt b/Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt
new file mode 100644
index 0000000000..cf63fdd3a9
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/B-no-arg3-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: No build directory specified for -B
diff --git a/Tests/RunCMake/CommandLine/C-no-arg2-result.txt b/Tests/RunCMake/CommandLine/C-no-arg2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C-no-arg2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt b/Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt
new file mode 100644
index 0000000000..5992dcd613
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C-no-arg2-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Error: -C must be followed by a file name.
+CMake Error: Run 'cmake --help' for all supported options.$
diff --git a/Tests/RunCMake/CommandLine/C-no-arg3-result.txt b/Tests/RunCMake/CommandLine/C-no-arg3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C-no-arg3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt b/Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt
new file mode 100644
index 0000000000..e80d89f0e4
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/C-no-arg3-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: No file name specified for -C
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 033fbe6be5..5944d2d6f3 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -7,6 +7,10 @@ run_cmake_command(InvalidArg1 ${CMAKE_COMMAND} -invalid)
run_cmake_command(InvalidArg2 ${CMAKE_COMMAND} --invalid)
run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
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(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.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-no-arg -S )
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-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
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-no-arg -B )
run_cmake_with_options(B-no-arg2 -B -T)
+ run_cmake_with_raw_args(B-no-arg3 [[-B ""]])
file(REMOVE_RECURSE "${binary_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/)
diff --git a/Tests/RunCMake/CommandLine/S-B-extra-path-stderr.txt b/Tests/RunCMake/CommandLine/S-B-extra-path-stderr.txt
index 8794f74bb2..e168a1b4e7 100644
--- a/Tests/RunCMake/CommandLine/S-B-extra-path-stderr.txt
+++ b/Tests/RunCMake/CommandLine/S-B-extra-path-stderr.txt
@@ -1,4 +1,4 @@
^CMake Warning:
Ignoring extra path from command line:
- /extra/path/$
+ "/extra/path/"$
diff --git a/Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt b/Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt
new file mode 100644
index 0000000000..6fa434126c
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/S-B-non-path-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Warning:
+ Ignoring empty string \(""\) provided on the command line\.$
diff --git a/Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt b/Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt
new file mode 100644
index 0000000000..6fa434126c
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/S-B-non-path2-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Warning:
+ Ignoring empty string \(""\) provided on the command line\.$
diff --git a/Tests/RunCMake/CommandLine/S-no-arg3-result.txt b/Tests/RunCMake/CommandLine/S-no-arg3-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/S-no-arg3-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt b/Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt
new file mode 100644
index 0000000000..d4fe65e903
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/S-no-arg3-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: No source directory specified for -S
diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake
index 6f79b78e6c..9f692eea36 100644
--- a/Tests/RunCMake/RunCMake.cmake
+++ b/Tests/RunCMake/RunCMake.cmake
@@ -119,12 +119,16 @@ function(run_cmake test)
else()
set(RunCMake_TEST_OPTIONS "")
endif()
+ if(NOT DEFINED RunCMake_TEST_RAW_ARGS)
+ set(RunCMake_TEST_RAW_ARGS "")
+ endif()
if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
endif()
- execute_process(
+ string(CONCAT _code [[execute_process(
COMMAND ${RunCMake_TEST_COMMAND}
${RunCMake_TEST_OPTIONS}
+ ]] "${RunCMake_TEST_RAW_ARGS}\n" [[
WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
OUTPUT_VARIABLE actual_stdout
ERROR_VARIABLE ${actual_stderr_var}
@@ -132,7 +136,8 @@ function(run_cmake test)
ENCODING UTF8
${maybe_timeout}
${maybe_input_file}
- )
+ )]])
+ cmake_language(EVAL CODE "${_code}")
set(msg "")
if(NOT "${actual_result}" MATCHES "${expect_result}")
string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
@@ -196,6 +201,9 @@ function(run_cmake test)
string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
string(APPEND command " ${options}")
endif()
+ if(RunCMake_TEST_RAW_ARGS)
+ string(APPEND command " ${RunCMake_TEST_RAW_ARGS}")
+ endif()
string(APPEND msg "Command was:\n command> ${command}\n")
endif()
if(msg)
@@ -228,6 +236,11 @@ function(run_cmake_with_options test)
run_cmake(${test})
endfunction()
+function(run_cmake_with_raw_args test args)
+ set(RunCMake_TEST_RAW_ARGS "${args}")
+ run_cmake(${test})
+endfunction()
+
function(ensure_files_match expected_file actual_file)
if(NOT EXISTS "${expected_file}")
message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")