Unverified Commit 4d43e96b authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] move R source files into R-package, reduce duplication in build_r.R (#3087)

* [R-package] move R source files into R-package

* fix linting warning

* stuff
parent cd70bad4
...@@ -56,7 +56,7 @@ if [[ $TRAVIS == "true" ]] && [[ $TASK == "lint" ]]; then ...@@ -56,7 +56,7 @@ if [[ $TRAVIS == "true" ]] && [[ $TASK == "lint" ]]; then
echo "Linting R code" echo "Linting R code"
Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit -1 Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit -1
echo "Linting C++ code" echo "Linting C++ code"
cpplint --filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length --recursive ./src ./include || exit -1 cpplint --filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length --recursive ./src ./include ./R-package || exit -1
exit 0 exit 0
fi fi
......
...@@ -15,9 +15,6 @@ src/ @guolinke @chivee @btrotta ...@@ -15,9 +15,6 @@ src/ @guolinke @chivee @btrotta
CMakeLists.txt @guolinke @chivee @Laurae2 @jameslamb @wxchan @henry0312 @StrikerRUS @huanzhang12 @btrotta CMakeLists.txt @guolinke @chivee @Laurae2 @jameslamb @wxchan @henry0312 @StrikerRUS @huanzhang12 @btrotta
# R code # R code
include/LightGBM/lightgbm_R.h @Laurae2 @jameslamb
include/LightGBM/R_object_helper.h @Laurae2 @jameslamb
src/lightgbm_R.cpp @Laurae2 @jameslamb
R-package/ @Laurae2 @jameslamb R-package/ @Laurae2 @jameslamb
*.R @Laurae2 @jameslamb *.R @Laurae2 @jameslamb
......
^build_package.R$ ^build_r.R$
\.gitkeep$ \.gitkeep$
^docs$ ^docs$
^pkgdown$ ^pkgdown$
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
* Copyright (c) 2017 Microsoft Corporation. All rights reserved. * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information. * Licensed under the MIT License. See LICENSE file in the project root for license information.
*/ */
#include <LightGBM/lightgbm_R.h>
#include "lightgbm_R.h"
#include <LightGBM/utils/common.h> #include <LightGBM/utils/common.h>
#include <LightGBM/utils/log.h> #include <LightGBM/utils/log.h>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define LIGHTGBM_R_H_ #define LIGHTGBM_R_H_
#include <LightGBM/c_api.h> #include <LightGBM/c_api.h>
#include <LightGBM/R_object_helper.h> #include "R_object_helper.h"
/*! /*!
* \brief get string message of the last error * \brief get string message of the last error
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
args <- commandArgs(trailingOnly = TRUE) args <- commandArgs(trailingOnly = TRUE)
INSTALL_AFTER_BUILD <- !("--skip-install" %in% args) INSTALL_AFTER_BUILD <- !("--skip-install" %in% args)
TEMP_R_DIR <- file.path(getwd(), "lightgbm_r")
TEMP_SOURCE_DIR <- file.path(TEMP_R_DIR, "src")
# 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
...@@ -56,13 +58,13 @@ INSTALL_AFTER_BUILD <- !("--skip-install" %in% args) ...@@ -56,13 +58,13 @@ INSTALL_AFTER_BUILD <- !("--skip-install" %in% args)
} }
# Make a new temporary folder to work in # Make a new temporary folder to work in
unlink(x = "lightgbm_r", recursive = TRUE) unlink(x = TEMP_R_DIR, recursive = TRUE)
dir.create("lightgbm_r") dir.create(TEMP_R_DIR)
# copy in the relevant files # copy in the relevant files
result <- file.copy( result <- file.copy(
from = "R-package/./" from = "R-package/./"
, to = "lightgbm_r/" , to = sprintf("%s/", TEMP_R_DIR)
, recursive = TRUE , recursive = TRUE
, overwrite = TRUE , overwrite = TRUE
) )
...@@ -70,7 +72,7 @@ result <- file.copy( ...@@ -70,7 +72,7 @@ result <- file.copy(
result <- file.copy( result <- file.copy(
from = "include/" from = "include/"
, to = file.path("lightgbm_r", "src/") , to = sprintf("%s/", TEMP_SOURCE_DIR)
, recursive = TRUE , recursive = TRUE
, overwrite = TRUE , overwrite = TRUE
) )
...@@ -78,7 +80,7 @@ result <- file.copy( ...@@ -78,7 +80,7 @@ result <- file.copy(
result <- file.copy( result <- file.copy(
from = "src/" from = "src/"
, to = file.path("lightgbm_r", "src/") , to = sprintf("%s/", TEMP_SOURCE_DIR)
, recursive = TRUE , recursive = TRUE
, overwrite = TRUE , overwrite = TRUE
) )
...@@ -86,7 +88,7 @@ result <- file.copy( ...@@ -86,7 +88,7 @@ result <- file.copy(
result <- file.copy( result <- file.copy(
from = "compute/" from = "compute/"
, to = file.path("lightgbm_r", "src/") , to = sprintf("%s/", TEMP_SOURCE_DIR)
, recursive = TRUE , recursive = TRUE
, overwrite = TRUE , overwrite = TRUE
) )
...@@ -94,15 +96,29 @@ result <- file.copy( ...@@ -94,15 +96,29 @@ result <- file.copy(
result <- file.copy( result <- file.copy(
from = "CMakeLists.txt" from = "CMakeLists.txt"
, to = file.path("lightgbm_r", "inst", "bin/") , to = file.path(TEMP_R_DIR, "inst", "bin/")
, overwrite = TRUE , overwrite = TRUE
) )
.handle_result(result) .handle_result(result)
# copy files into the place CMake expects
for (src_file in c("lightgbm_R.cpp", "lightgbm_R.h", "R_object_helper.h")) {
result <- file.copy(
from = file.path(TEMP_SOURCE_DIR, src_file)
, to = file.path(TEMP_SOURCE_DIR, "src", src_file)
, overwrite = TRUE
)
.handle_result(result)
result <- file.remove(
file.path(TEMP_SOURCE_DIR, src_file)
)
.handle_result(result)
}
# 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
.run_shell_command("R", c("CMD", "build", "lightgbm_r", "--keep-empty-dirs")) .run_shell_command("R", c("CMD", "build", TEMP_R_DIR, "--keep-empty-dirs"))
# Install the package # Install the package
version <- gsub( version <- gsub(
...@@ -110,7 +126,7 @@ version <- gsub( ...@@ -110,7 +126,7 @@ version <- gsub(
"", "",
grep( grep(
"Version: " "Version: "
, readLines(con = file.path("lightgbm_r", "DESCRIPTION")) , readLines(con = file.path(TEMP_R_DIR, "DESCRIPTION"))
, value = TRUE , value = TRUE
) )
) )
......
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