Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] allow use of custom R executable when building CRAN package #4754

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
;;
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