Skip to content

Commit

Permalink
[R-package] [ci] Reduce manual effort for version updates (#3335)
Browse files Browse the repository at this point in the history
* [R-package] [ci] Reduce manual effort for version updates

* fix configure

* remove useless comment

* Update build_r.R

Co-authored-by: Guolin Ke <[email protected]>

* fix recreate-configure check in CI

Co-authored-by: Guolin Ke <[email protected]>
  • Loading branch information
jameslamb and guolinke authored Aug 25, 2020
1 parent 9503d3f commit 5538eb8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
7 changes: 1 addition & 6 deletions .ci/test_r_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ elif [[ $R_BUILD_TYPE == "cran" ]]; then
# on Linux, we recreate configure in CI to test if
# a change in a PR has changed configure.ac
if [[ $OS_NAME == "linux" ]]; then
cd ${BUILD_DIRECTORY}/R-package
autoconf \
--output configure \
configure.ac \
|| exit -1
cd ${BUILD_DIRECTORY}
${BUILD_DIRECTORY}/R-package/recreate-configure.sh

num_files_changed=$(
git diff --name-only | wc -l
Expand Down
4 changes: 2 additions & 2 deletions R-package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: lightgbm
Type: Package
Title: Light Gradient Boosting Machine
Version: 3.0.0-1
Date: 2020-08-06
Version: ~~VERSION~~
Date: ~~DATE~~
Authors@R: c(
person("Guolin", "Ke", email = "[email protected]", role = c("aut", "cre")),
person("Damien", "Soukhavong", email = "[email protected]", role = c("aut")),
Expand Down
2 changes: 1 addition & 1 deletion R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ At build time, `configure` will be run and used to create a file `Makevars`, usi
./R-package/recreate-configure.sh
```

If you do not have easy access to an Ubuntu 18.04 environment, the `configure` script can be generated using Docker.
If you do not have easy access to an Ubuntu 18.04 environment, the `configure` script can be generated using Docker by running the code below from the root of this repo.

```shell
docker run \
Expand Down
18 changes: 9 additions & 9 deletions R-package/configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for lightgbm 3.0.0-1.
# Generated by GNU Autoconf 2.69 for lightgbm 3.0.0.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -576,8 +576,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='lightgbm'
PACKAGE_TARNAME='lightgbm'
PACKAGE_VERSION='3.0.0-1'
PACKAGE_STRING='lightgbm 3.0.0-1'
PACKAGE_VERSION='3.0.0'
PACKAGE_STRING='lightgbm 3.0.0'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

Expand Down Expand Up @@ -1182,7 +1182,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures lightgbm 3.0.0-1 to adapt to many kinds of systems.
\`configure' configures lightgbm 3.0.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1244,7 +1244,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of lightgbm 3.0.0-1:";;
short | recursive ) echo "Configuration of lightgbm 3.0.0:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1311,7 +1311,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
lightgbm configure 3.0.0-1
lightgbm configure 3.0.0
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
Expand All @@ -1328,7 +1328,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by lightgbm $as_me 3.0.0-1, which was
It was created by lightgbm $as_me 3.0.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2377,7 +2377,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by lightgbm $as_me 3.0.0-1, which was
This file was extended by lightgbm $as_me 3.0.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -2430,7 +2430,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
lightgbm config.status 3.0.0-1
lightgbm config.status 3.0.0
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Expand Down
2 changes: 1 addition & 1 deletion R-package/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# * https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Configure-and-cleanup

AC_PREREQ(2.69)
AC_INIT([lightgbm], [3.0.0-1], [], [lightgbm], [])
AC_INIT([lightgbm], [~~VERSION~~], [], [lightgbm], [])

###########################
# find compiler and flags #
Expand Down
16 changes: 15 additions & 1 deletion R-package/recreate-configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
# this script should run on Ubuntu 18.04
AUTOCONF_VERSION=$(cat R-package/AUTOCONF_UBUNTU_VERSION)

# R packages cannot have versions like 3.0.0rc1, but
# 3.0.0-1 is acceptable
LGB_VERSION=$(cat VERSION.txt | sed "s/rc/-/g")

# this script changes configure.ac. Copying to a temporary file
# so changes to configure.ac don't get committed in git
TMP_CONFIGURE_AC=".configure.ac"

echo "Creating 'configure' script with Autoconf ${AUTOCONF_VERSION}"

apt update
Expand All @@ -13,11 +21,17 @@ apt-get install \
autoconf=${AUTOCONF_VERSION}

cd R-package

cp configure.ac ${TMP_CONFIGURE_AC}
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" ${TMP_CONFIGURE_AC}

autoconf \
--output configure \
configure.ac \
${TMP_CONFIGURE_AC} \
|| exit -1

rm ${TMP_CONFIGURE_AC}

rm -r autom4te.cache || echo "no autoconf cache found"

echo "done creating 'configure' script"
12 changes: 12 additions & 0 deletions build-cran-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ if test -d ${TEMP_R_DIR}; then
fi
mkdir -p ${TEMP_R_DIR}

CURRENT_DATE=$(date +'%Y-%m-%d')

# R packages cannot have versions like 3.0.0rc1, but
# 3.0.0-1 is acceptable
LGB_VERSION=$(cat VERSION.txt | sed "s/rc/-/g")

# move relevant files
cp -R R-package/* ${TEMP_R_DIR}
cp -R include ${TEMP_R_DIR}/src/
Expand All @@ -38,6 +44,12 @@ cd ${TEMP_R_DIR}
# for the R package
rm src/main.cpp

# configure.ac and DESCRIPTION have placeholders for version
# and date so they don't have to be updated manually
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" configure.ac
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" DESCRIPTION
sed -i.bak -e "s/~~DATE~~/${CURRENT_DATE}/" DESCRIPTION

# Remove 'region' and 'endregion' pragmas. This won't change
# the correctness of the code. CRAN does not allow you
# to use compiler flag '-Wno-unknown-pragmas' or
Expand Down
25 changes: 25 additions & 0 deletions build_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ result <- file.copy(
)
.handle_result(result)

# R packages cannot have versions like 3.0.0rc1, but
# 3.0.0-1 is acceptable
LGB_VERSION <- readLines("VERSION.txt")[1L]
LGB_VERSION <- gsub(
pattern = "rc"
, replacement = "-"
, x = LGB_VERSION
)

# DESCRIPTION has placeholders for version
# and date so it doesn't have to be updated manually
DESCRIPTION_FILE <- file.path(TEMP_R_DIR, "DESCRIPTION")
description_contents <- readLines(DESCRIPTION_FILE)
description_contents <- gsub(
pattern = "~~VERSION~~"
, replacement = LGB_VERSION
, x = description_contents
)
description_contents <- gsub(
pattern = "~~DATE~~"
, replacement = as.character(Sys.Date())
, x = description_contents
)
writeLines(description_contents, DESCRIPTION_FILE)

# NOTE: --keep-empty-dirs is necessary to keep the deep paths expected
# by CMake while also meeting the CRAN req to create object files
# on demand
Expand Down

0 comments on commit 5538eb8

Please sign in to comment.