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] Avoid bashisms (non-POSIX code) in R-package/configure #6746

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

smoser
Copy link
Contributor

@smoser smoser commented Dec 11, 2024

On systems that did not have bash as /bin/sh this would end up causing strange compilation errors.

Fixes #6743.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

I was under the impression that R CMD check would run checkbashisms and that that would catch stuff like this (#6743 (comment)).

But it seems not. I just ran it (on my mac, with Homebrew's checkbashisms v2.23.7),

checkbashisms ./R-package/configure

It caught these += issues and some others. Do any of these look relevant?

possible bashism in ./R-package/configure line 344 ([^] should be [!]):
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
possible bashism in ./R-package/configure line 348 ([^] should be [!]):
          /^X\(\/\/\)[^/].*/{
possible bashism in ./R-package/configure line 462 ([^] should be [!]):
    sed '/^.*\/\([^/][^/]*\)\/*$/{
possible bashism in ./R-package/configure line 526 (unsafe echo with backslash):
  case `echo 'xy\c'` in
possible bashism in ./R-package/configure line 1792 (should be VAR="${VAR}foo"):
    LGB_CPPFLAGS+=" -DMM_PREFETCH=1"
possible bashism in ./R-package/configure line 1827 (should be VAR="${VAR}foo"):
    LGB_CPPFLAGS+=" -DMM_MALLOC=1"
possible bashism in ./R-package/configure line 1853 (should be >word 2>&1):
    if command -v brew &> /dev/null; then
possible bashism in ./R-package/configure line 1857 (should be >word 2>&1):
        brew --prefix libomp &>/dev/null && ac_brew_openmp=yes

The sed ones are code-generated by autoconf and out of our control. But those two output-redirection ones about brew are in our control.

Also... can you please try testing your branch on whatever system you're on that led to the errors reported in #6743?

git clone --recursive [email protected]:microsoft/LightGBM.git
cd ./LightGBM
sh build-cran-package.sh --no-build-vignettes
R CMD INSTALL ./lightgbm_*.tar.gz

@jameslamb jameslamb changed the title Do not use '+=' in R-package/configure, it is not posix sh. [R-package] Avoid '+=' in R-package/configure, it is not posix sh Dec 11, 2024
@jameslamb jameslamb changed the title [R-package] Avoid '+=' in R-package/configure, it is not posix sh [R-package] Avoid '+=' in R-package/configure Dec 11, 2024
@smoser
Copy link
Contributor Author

smoser commented Dec 11, 2024

@smoser please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
...

@microsoft-github-policy-service agree company="Chainguard"

@smoser smoser force-pushed the fix-plus-equal-not-posix branch from 403d321 to 6f3b008 Compare December 11, 2024 15:06
@smoser
Copy link
Contributor Author

smoser commented Dec 11, 2024

The sed ones are code-generated by autoconf and out of our control. But those two output-redirection ones about brew are in our control.

Fixed the output-redirection (those are definitely not posix). I'll test later, but the changes here are absolutely improvement on their own.

@smoser
Copy link
Contributor Author

smoser commented Dec 11, 2024

Also... can you please try testing your branch on whatever system you're on that led to the errors reported in #6743?

$ git clone --recursive https://github.com/microsoft/LightGBM.git
$ cd LightGBM
$ git remote add smoser https://github.com/smoser/LightGBM.git
$ git checkout smoser/fix-plus-equal-not-posix
$ git log HEAD^.. --oneline
6f3b008a Remove bashisms in R-package/configure
$ sh build-cran-package.sh --no-build-vignettes
Building lightgbm with R executable: R
Removing files not needed for CRAN
Removing unknown pragmas in headers
Cleaning sed backup files
* checking for file ‘lightgbm_r/DESCRIPTION’ ... OK
* preparing ‘lightgbm’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* running ‘cleanup’
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a ‘data/datalist’ file should be added
* building ‘lightgbm_4.5.0.99.tar.gz’

Done building R-package

Then copied the lightgbm_4.5.0.99.tar.gz into a container where I previously had the problem.

$ R CMD INSTALL ./lightgbm_4.5.0.99.tar.gz   
* installing to library '/usr/lib/R/library'
ERROR: dependencies 'R6', 'data.table', 'jsonlite' are not available for package 'lightgbm'

$ R -e "install.packages('R6', repos = 'https://cran.rstudio.com/')"
$ R -e "install.packages('data.table', repos = 'https://cran.rstudio.com/')"
$ R -e "install.packages('jsonlite', repos = 'https://cran.rstudio.com/')"

$ R CMD INSTALL ./lightgbm_4.5.0.99.tar.gz
...
* installing to library '/usr/lib/R/library'
* installing *source* package 'lightgbm' ...
** using staged installation
checking location of R... /usr/lib/R
checking whether MM_PREFETCH works... yes
checking whether MM_MALLOC works... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
using C++ compiler: 'g++ (Wolfi 14.2.0-r5) 14.2.0'
using C++17
...

Note, I clearly don't know what I'm doing with R dependencies.. I'm sure there is a better way to install the necessary deps, but i muddled my way through there.

The output of configure looks sane and its building now, so this LGTM.

@jameslamb
Copy link
Collaborator

Nah that's great, thank you very much! Just one more thing... it looks like you didn't push the changes you made related to output-redirection (I still just see += changes). Could you push those?

'+=' (VAR+=Value) is bash specific.
'&>' redirect operator is as well.

On systems that did not have bash as /bin/sh this would end up
causing strange compilation errors.

Fixes microsoft#6743.
@smoser smoser force-pushed the fix-plus-equal-not-posix branch from 6f3b008 to a0afebd Compare December 11, 2024 16:52
@jameslamb jameslamb self-requested a review December 12, 2024 03:39
@jameslamb jameslamb changed the title [R-package] Avoid '+=' in R-package/configure [R-package] Avoid bashisms (non-POSIX code) in R-package/configure Dec 12, 2024
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the report and fix!

@jameslamb jameslamb merged commit 53e0ddf into microsoft:master Dec 12, 2024
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[R-package] installation via install.packages fails if /bin/sh is not bash (bashisms in configure)
2 participants