diff options
10 files changed, 61 insertions, 19 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 5a04eab..b5a42ff 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -360,6 +360,31 @@ int do_cmake(int ac, char const* const* av) return 0; } +namespace { +int extract_job_number(int& index, char const* current, char const* next, + int len_of_flag) +{ + std::string command(current); + std::string jobString = command.substr(len_of_flag); + if (jobString.empty() && next && isdigit(next[0])) { + ++index; // skip parsing the job number + jobString = std::string(next); + } + + int jobs = -1; + unsigned long numJobs = 0; + if (jobString.empty()) { + jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL; + } else if (cmSystemTools::StringToULong(jobString.c_str(), &numJobs)) { + jobs = int(numJobs); + } else { + std::cerr << "'" << command.substr(0, len_of_flag) << "' invalid number '" + << jobString << "' given.\n\n"; + } + return jobs; +} +} + static int do_build(int ac, char const* const* av) { #ifndef CMAKE_BUILD_WITH_CMAKE @@ -377,7 +402,6 @@ static int do_build(int ac, char const* const* av) enum Doing { DoingNone, - DoingJobs, DoingDir, DoingTarget, DoingConfig, @@ -387,12 +411,17 @@ static int do_build(int ac, char const* const* av) for (int i = 2; i < ac; ++i) { if (doing == DoingNative) { nativeOptions.emplace_back(av[i]); - } else if ((strcmp(av[i], "-j") == 0) || - (strcmp(av[i], "--parallel") == 0)) { - jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL; - /* does the next argument start with a number? */ - if ((i + 1 < ac) && (isdigit(*av[i + 1]))) { - doing = DoingJobs; + } else if (cmHasLiteralPrefix(av[i], "-j")) { + const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr); + jobs = extract_job_number(i, av[i], nextArg, sizeof("-j") - 1); + if (jobs < 0) { + dir.clear(); + } + } else if (cmHasLiteralPrefix(av[i], "--parallel")) { + const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr); + jobs = extract_job_number(i, av[i], nextArg, sizeof("--parallel") - 1); + if (jobs < 0) { + dir.clear(); } } else if (strcmp(av[i], "--target") == 0) { if (!hasTarget) { @@ -414,18 +443,6 @@ static int do_build(int ac, char const* const* av) doing = DoingNative; } else { switch (doing) { - case DoingJobs: { - unsigned long numJobs = 0; - if (cmSystemTools::StringToULong(av[i], &numJobs)) { - jobs = int(numJobs); - doing = DoingNone; - } else { - std::cerr << "'" << av[i - 1] << "' invalid number '" << av[i] - << "' given.\n\n"; - dir.clear(); - break; - } - } break; case DoingDir: dir = cmSystemTools::CollapseFullPath(av[i]); doing = DoingNone; diff --git a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-result.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-stderr.txt new file mode 100644 index 0000000..e73d760 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-bad-number-stderr.txt @@ -0,0 +1,3 @@ +^'--parallel' invalid number '12ab' given\. ++ +Usage: cmake --build <dir> \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-stderr.txt new file mode 100644 index 0000000..3c2c808 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-stderr.txt @@ -0,0 +1 @@ +(^$|^Warning: .* does not support parallel builds\. Ignoring parallel build command line option\.) diff --git a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-trailing--target-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-trailing--target-stderr.txt new file mode 100644 index 0000000..3c2c808 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-trailing--target-stderr.txt @@ -0,0 +1 @@ +(^$|^Warning: .* does not support parallel builds\. Ignoring parallel build command line option\.) diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-result.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-stderr.txt new file mode 100644 index 0000000..c810087 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-bad-number-stderr.txt @@ -0,0 +1,3 @@ +^'-j' invalid number '12ab' given\. ++ +Usage: cmake --build <dir> \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-stderr.txt new file mode 100644 index 0000000..3c2c808 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-stderr.txt @@ -0,0 +1 @@ +(^$|^Warning: .* does not support parallel builds\. Ignoring parallel build command line option\.) diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-trailing--target-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-trailing--target-stderr.txt new file mode 100644 index 0000000..3c2c808 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-trailing--target-stderr.txt @@ -0,0 +1 @@ +(^$|^Warning: .* does not support parallel builds\. Ignoring parallel build command line option\.) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 0e04ad1..ff9fcac 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -105,6 +105,19 @@ function(run_BuildDir) ${CMAKE_COMMAND} --build BuildDir-build --parallel 2) run_cmake_command(BuildDir--build--parallel-good-number-trailing--target ${CMAKE_COMMAND} -E chdir .. ${CMAKE_COMMAND} --build BuildDir-build --parallel 2 --target CustomTarget) + run_cmake_command(BuildDir--build-jobs-no-space-bad-number ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build -j12ab) + run_cmake_command(BuildDir--build-jobs-no-space-good-number ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build -j2) + run_cmake_command(BuildDir--build-jobs-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build -j2 --target CustomTarget) + run_cmake_command(BuildDir--build--parallel-no-space-bad-number ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build --parallel12ab) + run_cmake_command(BuildDir--build--parallel-no-space-good-number ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build --parallel2) + run_cmake_command(BuildDir--build--parallel-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build --parallel2 --target CustomTarget) + # No default jobs for Xcode and FreeBSD build command if(NOT RunCMake_GENERATOR MATCHES "Xcode" AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD") run_cmake_command(BuildDir--build-jobs-no-number ${CMAKE_COMMAND} -E chdir .. |