From d4a88541efd98a8728357840b45afd8ab5c031ae Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 6 Nov 2021 21:04:16 -0500 Subject: [PATCH] pass -j through to install.libs.R --- .ci/test_r_package.sh | 2 +- .ci/test_r_package_windows.ps1 | 4 ++-- R-package/src/install.libs.R | 7 ++++--- build_r.R | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index a6656dfb83e6..6693a04a7fe4 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -112,7 +112,7 @@ cd ${BUILD_DIRECTORY} PKG_TARBALL="lightgbm_*.tar.gz" LOG_FILE_NAME="lightgbm.Rcheck/00check.log" if [[ $R_BUILD_TYPE == "cmake" ]]; then - Rscript build_r.R --skip-install || exit -1 + Rscript build_r.R -j2 --skip-install || exit -1 elif [[ $R_BUILD_TYPE == "cran" ]]; then # on Linux, we recreate configure in CI to test if diff --git a/.ci/test_r_package_windows.ps1 b/.ci/test_r_package_windows.ps1 index 3c0f11ca58c6..2d676034154c 100644 --- a/.ci/test_r_package_windows.ps1 +++ b/.ci/test_r_package_windows.ps1 @@ -153,10 +153,10 @@ if ($env:COMPILER -ne "MSVC") { if ($env:R_BUILD_TYPE -eq "cmake") { if ($env:TOOLCHAIN -eq "MINGW") { Write-Output "Telling R to use MinGW" - $env:BUILD_R_FLAGS = "c('--skip-install', '--use-mingw')" + $env:BUILD_R_FLAGS = "c('--skip-install', '--use-mingw', '-j2')" } elseif ($env:TOOLCHAIN -eq "MSYS") { Write-Output "Telling R to use MSYS" - $env:BUILD_R_FLAGS = "c('--skip-install', '--use-msys2')" + $env:BUILD_R_FLAGS = "c('--skip-install', '--use-msys2', '-j2')" } elseif ($env:TOOLCHAIN -eq "MSVC") { $env:BUILD_R_FLAGS = "'--skip-install'" } else { diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 4de9ee9be7b1..f292b43e318c 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -1,5 +1,6 @@ # User options use_gpu <- FALSE +make_args_from_build_script <- character(0L) # For Windows, the package will be built with Visual Studio # unless you set one of these to TRUE @@ -132,7 +133,7 @@ if (WINDOWS && use_visual_studio) { # Prepare installation steps cmake_args <- NULL build_cmd <- "make" -build_args <- c("_lightgbm", "-j4") +build_args <- c("_lightgbm", make_args_from_build_script) lib_folder <- file.path(source_dir, fsep = "/") # add in command-line arguments @@ -194,7 +195,7 @@ if (WINDOWS) { cmake_args <- c(cmake_args, "-G", shQuote(windows_makefile_generator)) .run_shell_command("cmake", c(cmake_args, ".."), strict = FALSE) build_cmd <- windows_build_tool - build_args <- c("_lightgbm", "-j4") + build_args <- c("_lightgbm", make_args_from_build_script) } else { visual_studio_succeeded <- .generate_vs_makefiles(cmake_args) if (!isTRUE(visual_studio_succeeded)) { @@ -203,7 +204,7 @@ if (WINDOWS) { cmake_args <- c(cmake_args, "-G", shQuote(windows_makefile_generator)) .run_shell_command("cmake", c(cmake_args, ".."), strict = FALSE) build_cmd <- windows_build_tool - build_args <- c("_lightgbm", "-j4") + build_args <- c("_lightgbm", make_args_from_build_script) } else { build_cmd <- "cmake" build_args <- c("--build", ".", "--target", "_lightgbm", "--config", "Release") diff --git a/build_r.R b/build_r.R index bb860c3edd58..b4c610197692 100644 --- a/build_r.R +++ b/build_r.R @@ -112,6 +112,20 @@ if (length(keyword_args) > 0L) { ) } +# if provided, set '-j' in 'make' commands in install.libs.R +if (length(parsed_args[["make_args"]]) > 0L) { + install_libs_content <- gsub( + pattern = "make_args_from_build_script <- character(0L)" + , replacement = paste0( + "make_args_from_build_script <- c(\"" + , paste0(parsed_args[["make_args"]], collapse = "\", \"") + , "\")" + ) + , x = install_libs_content + , fixed = TRUE + ) +} + # R returns FALSE (not a non-zero exit code) if a file copy operation # breaks. Let's fix that .handle_result <- function(res) {