Commit 1c27a15e authored by James Lamb's avatar James Lamb Committed by Laurae
Browse files

removed external dependenciesin build_r.R (fixes #2122) (#2123)

parent 94fbe5bb
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
# Sys.setenv("CXX" = "/usr/local/bin/g++-8") # Sys.setenv("CXX" = "/usr/local/bin/g++-8")
# Sys.setenv("CC" = "/usr/local/bin/gcc-8") # Sys.setenv("CC" = "/usr/local/bin/gcc-8")
library(testthat)
library(roxygen2)
library(devtools)
# R returns FALSE (not a non-zero exit code) if a file copy operation # R returns FALSE (not a non-zero exit code) if a file copy operation
# breaks. Let's fix that # breaks. Let's fix that
.handle_result <- function(res) { .handle_result <- function(res) {
...@@ -17,6 +13,15 @@ library(devtools) ...@@ -17,6 +13,15 @@ library(devtools)
} }
} }
# system() will not raise an R exception if the process called
# fails. Wrapping it here to get that behavior
.run_shell_command <- function(cmd, ...){
exit_code <- system(cmd, ...)
if (exit_code != 0){
stop(paste0("Command failed with exit code: ", exit_code))
}
}
# Make a new temporary folder to work in # Make a new temporary folder to work in
unlink(x = "lightgbm_r", recursive = TRUE) unlink(x = "lightgbm_r", recursive = TRUE)
dir.create("lightgbm_r") dir.create("lightgbm_r")
...@@ -51,15 +56,12 @@ result <- file.copy(from = "CMakeLists.txt", ...@@ -51,15 +56,12 @@ result <- file.copy(from = "CMakeLists.txt",
overwrite = TRUE) overwrite = TRUE)
.handle_result(result) .handle_result(result)
# rebuild documentation
# devtools::document(pkg = "lightgbm_r")
# Build the package # Build the package
# NOTE: --keep-empty-dirs is necessary to keep the deep paths expected # NOTE: --keep-empty-dirs is necessary to keep the deep paths expected
# by CMake while also meeting the CRAN req to create object files # by CMake while also meeting the CRAN req to create object files
# on demand # on demand
devtools::build(pkg = "lightgbm_r", cmd <- "R CMD build lightgbm_r --keep_empty-dirs"
args = c("--keep-empty-dirs")) .run_shell_command(cmd)
# Install the package # Install the package
version <- gsub( version <- gsub(
...@@ -73,7 +75,8 @@ version <- gsub( ...@@ -73,7 +75,8 @@ version <- gsub(
) )
tarball <- file.path(getwd(), sprintf("lightgbm_%s.tar.gz", version)) tarball <- file.path(getwd(), sprintf("lightgbm_%s.tar.gz", version))
system(sprintf("R CMD INSTALL %s --no-multiarch", tarball)) cmd <- sprintf("R CMD INSTALL %s --no-multiarch", tarball)
.run_shell_command(cmd)
# Run R CMD CHECK # Run R CMD CHECK
# R CMD CHECK lightgbm_2.1.2.tar.gz --as-cran | tee check.log | cat # R CMD CHECK lightgbm_2.1.2.tar.gz --as-cran | tee check.log | cat
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment