From 08ccd4a3fd341cb05fb5bf63e596fcdf860e9332 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 30 Oct 2021 22:31:35 -0500 Subject: [PATCH] [R-package] allow use of custom R executable when building CRAN package (#4754) * [R-package] allow use of custom R executable building CRAN package * Update build-cran-package.sh Co-authored-by: Nikita Titov Co-authored-by: Nikita Titov --- .ci/test_r_package_valgrind.sh | 4 +++- .github/workflows/r_package.yml | 2 +- R-package/README.md | 5 +++-- build-cran-package.sh | 31 ++++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.ci/test_r_package_valgrind.sh b/.ci/test_r_package_valgrind.sh index 80a2830b7422..fc27689f9090 100755 --- a/.ci/test_r_package_valgrind.sh +++ b/.ci/test_r_package_valgrind.sh @@ -1,7 +1,9 @@ #!/bin/bash RDscriptvalgrind -e "install.packages(c('R6', 'data.table', 'jsonlite', 'Matrix', 'testthat'), repos = 'https://cran.r-project.org', Ncpus = parallel::detectCores())" || exit -1 -sh build-cran-package.sh || exit -1 +sh build-cran-package.sh \ + --r-executable=RDvalgrind \ + || exit -1 RDvalgrind CMD INSTALL --preclean --install-tests lightgbm_*.tar.gz || exit -1 cd R-package/tests diff --git a/.github/workflows/r_package.yml b/.github/workflows/r_package.yml index 6f07c6e4f394..13127c25b047 100644 --- a/.github/workflows/r_package.yml +++ b/.github/workflows/r_package.yml @@ -195,7 +195,7 @@ jobs: shell: bash run: | RDscript${{ matrix.r_customization }} -e "install.packages(c('R6', 'data.table', 'jsonlite', 'Matrix', 'testthat'), repos = 'https://cran.r-project.org', Ncpus = parallel::detectCores())" - sh build-cran-package.sh + sh build-cran-package.sh --r-executable=RD${{ matrix.r_customization }} RD${{ matrix.r_customization }} CMD INSTALL lightgbm_*.tar.gz || exit -1 - name: Run tests with sanitizers shell: bash diff --git a/R-package/README.md b/R-package/README.md index 918db731c48a..352071f0ad4b 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -394,7 +394,7 @@ RDscript${R_CUSTOMIZATION} \ -e "install.packages(c('R6', 'data.table', 'jsonlite', 'Matrix', 'testthat'), repos = 'https://cran.r-project.org', Ncpus = parallel::detectCores())" # install lightgbm -sh build-cran-package.sh +sh build-cran-package.sh --r-executable=RD${R_CUSTOMIZATION} RD${R_CUSTOMIZATION} \ CMD INSTALL lightgbm_*.tar.gz @@ -423,7 +423,8 @@ docker run \ RDscriptvalgrind -e "install.packages(c('R6', 'data.table', 'jsonlite', 'Matrix', 'testthat'), repos = 'https://cran.rstudio.com', Ncpus = parallel::detectCores())" -sh build-cran-package.sh +sh build-cran-package.sh \ + --r-executable=RDvalgrind RDvalgrind CMD INSTALL \ --preclean \ diff --git a/build-cran-package.sh b/build-cran-package.sh index 967ee4a03c8f..e4def4a14657 100755 --- a/build-cran-package.sh +++ b/build-cran-package.sh @@ -4,11 +4,40 @@ # Prepare a source distribution of the R package # to be submitted to CRAN. # +# [arguments] +# +# --r-executable Customize the R executable used by `R CMD build`. +# Useful if building the R package in an environment with +# non-standard builds of R, such as those provided in +# https://github.com/wch/r-debug. +# # [usage] +# +# # default usage # sh build-cran-package.sh +# +# # custom R build +# sh build-cran-package.sh --r-executable=RDvalgrind set -e +LGB_R_EXECUTABLE=R + +while [ $# -gt 0 ]; do + case "$1" in + --r-executable=*) + LGB_R_EXECUTABLE="${1#*=}" + ;; + *) + echo "invalid argument '${1}'" + exit -1 + ;; + esac + shift +done + +echo "Building lightgbm with R executable: ${LGB_R_EXECUTABLE}" + ORIG_WD="$(pwd)" TEMP_R_DIR="$(pwd)/lightgbm_r" @@ -140,7 +169,7 @@ cd "${TEMP_R_DIR}" cd "${ORIG_WD}" -R CMD build \ +"${LGB_R_EXECUTABLE}" CMD build \ --keep-empty-dirs \ lightgbm_r