diff options
author | Brad King <brad.king@kitware.com> | 2019-01-23 13:15:29 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-01-23 13:15:36 (GMT) |
commit | c1247d861a42fa79e7ca4cc9a793b1fa1f012dce (patch) | |
tree | 29ac3c5421837467a8ce8e3bc195c2ae5d4fef06 | |
parent | 877eed30c7f3fa873b36ec3654c00c50a3977425 (diff) | |
parent | f2fca92686fb360c433d06452700d90dcf62c9fa (diff) | |
download | CMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.zip CMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.tar.gz CMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.tar.bz2 |
Merge topic 'cmake_build_jobs_supports_no_space'
f2fca92686 cmake: --build supports '-jN'
e463133cd2 Tests: Remove unused files from RunCMake.CommandLine test
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2819
10 files changed, 57 insertions, 19 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 10655d5..0c25498 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -358,6 +358,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 @@ -375,7 +400,6 @@ static int do_build(int ac, char const* const* av) enum Doing { DoingNone, - DoingJobs, DoingDir, DoingTarget, DoingConfig, @@ -385,12 +409,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) { @@ -412,18 +441,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-jobs-no-number-trailing-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-stderr.txt index 3c2c808..3c2c808 100644 --- a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing-stderr.txt +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-stderr.txt diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-good-number-trailing-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-trailing--target-stderr.txt index 3c2c808..3c2c808 100644 --- a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-good-number-trailing-stderr.txt +++ b/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-space-good-number-trailing--target-stderr.txt 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--parallel-no-number-trailing-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-stderr.txt index 3c2c808..3c2c808 100644 --- a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-no-number-trailing-stderr.txt +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-stderr.txt diff --git a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-good-number-trailing-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-trailing--target-stderr.txt index 3c2c808..3c2c808 100644 --- a/Tests/RunCMake/CommandLine/BuildDir--build--parallel-good-number-trailing-stderr.txt +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-space-good-number-trailing--target-stderr.txt diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 70fcdba..c1aaf0d 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -115,6 +115,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 .. |