diff --git a/.ci/test_r_package_valgrind.sh b/.ci/test_r_package_valgrind.sh index 80a2830b742..fc27689f909 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 6f07c6e4f39..13127c25b04 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 918db731c48..352071f0ad4 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 967ee4a03c8..e4def4a1465 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