From 01611f825840553fecdc98edaa128dd8f6ce9801 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 14 Nov 2022 10:27:59 -0500 Subject: cmake: --build improve detection of no build dir Fixes #24157 --- Source/cmakemain.cxx | 26 ++++++---------------- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 2 ++ .../RunCMake/CommandLine/build-no-dir2-result.txt | 1 + .../RunCMake/CommandLine/build-no-dir2-stderr.txt | 1 + 4 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 Tests/RunCMake/CommandLine/build-no-dir2-result.txt create mode 100644 Tests/RunCMake/CommandLine/build-no-dir2-stderr.txt diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 43bebc1..9f23667 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -522,25 +522,8 @@ int do_build(int ac, char const* const* av) if (ac >= 3) { std::vector inputArgs; - bool hasPreset = false; - for (int i = 2; i < ac; ++i) { - if (strcmp(av[i], "--list-presets") == 0 || - cmHasLiteralPrefix(av[i], "--preset=") || - strcmp(av[i], "--preset") == 0) { - hasPreset = true; - break; - } - } - - if (hasPreset) { - inputArgs.reserve(ac - 2); - cm::append(inputArgs, av + 2, av + ac); - } else { - dir = cmSystemTools::CollapseFullPath(av[2]); - - inputArgs.reserve(ac - 3); - cm::append(inputArgs, av + 3, av + ac); - } + inputArgs.reserve(ac - 2); + cm::append(inputArgs, av + 2, av + ac); decltype(inputArgs.size()) i = 0; for (; i < inputArgs.size() && !nativeOptionsPassed; ++i) { @@ -555,6 +538,11 @@ int do_build(int ac, char const* const* av) break; } } + if (!matched && i == 0) { + dir = cmSystemTools::CollapseFullPath(arg); + matched = true; + parsed = true; + } if (!(matched && parsed)) { dir.clear(); if (!matched) { diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 327b772..a38b146 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -58,6 +58,8 @@ run_cmake_command(P_fresh ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_fresh.cm run_cmake_command(build-no-dir ${CMAKE_COMMAND} --build) +run_cmake_command(build-no-dir2 + ${CMAKE_COMMAND} --build --target=invalid) run_cmake_command(build-no-cache ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}) run_cmake_command(build-unknown-command-short diff --git a/Tests/RunCMake/CommandLine/build-no-dir2-result.txt b/Tests/RunCMake/CommandLine/build-no-dir2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-dir2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-no-dir2-stderr.txt b/Tests/RunCMake/CommandLine/build-no-dir2-stderr.txt new file mode 100644 index 0000000..4811bea --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-dir2-stderr.txt @@ -0,0 +1 @@ +^Usage: cmake --build +\[options\] \[-- \[native-options\]\] -- cgit v0.12