Skip to content

Commit

Permalink
[R-package] allow use of custom R executable when building CRAN packa…
Browse files Browse the repository at this point in the history
…ge (#4754)

* [R-package] allow use of custom R executable building CRAN package

* Update build-cran-package.sh

Co-authored-by: Nikita Titov <[email protected]>

Co-authored-by: Nikita Titov <[email protected]>
  • Loading branch information
jameslamb and StrikerRUS authored Oct 31, 2021
1 parent dac0dff commit 08ccd4a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .ci/test_r_package_valgrind.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/r_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
31 changes: 30 additions & 1 deletion build-cran-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -140,7 +169,7 @@ cd "${TEMP_R_DIR}"

cd "${ORIG_WD}"

R CMD build \
"${LGB_R_EXECUTABLE}" CMD build \
--keep-empty-dirs \
lightgbm_r

Expand Down

0 comments on commit 08ccd4a

Please sign in to comment.