r-lib / pkgdepends

R Package Dependency Resolution
https://r-lib.github.io/pkgdepends/
Other
102 stars 30 forks source link

Run script before GitHub subdirectory is moved out of its context? #303

Closed paleolimbot closed 1 year ago

paleolimbot commented 1 year ago

In trying to remove some hacks from the nanoarrow package, which lives in a subdirectory of the https://github/apache/arrow-nanoarrow , I discovered that during the packaging phase the subdirectory is separated from the context before any script in the R package is run (e.g., cleanup). This means that the vendoring stage (where I copy the nanoarrow sources into the R package) doesn't work out-of-the box with all the pak-based tooling (e.g., GitHub actions in CI).

@jeroen suggested .prepare, as used by r-universe: https://github.com/r-universe-org/build-source/blob/master/entrypoint.sh#L38 , or perhaps an R script ("prepare.R"? "bootstrap.R"? Something defined in the DESCRIPTION?)

See https://github.com/apache/arrow-nanoarrow/pull/98 for context...the example I'm working with is:

> pak::pkg_install("apache/arrow-nanoarrow/r#98")

→ Will update 1 package.
→ Will download 1 package with unknown size.
+ nanoarrow 0.0.0.9000 → 0.0.0.9000 👷🏼‍♀️🔧 ⬇ (GitHub: fcb124f)
? Do you want to continue (Y/n) Y
ℹ Getting 1 pkg with unknown size
✔ Cached copy of nanoarrow 0.0.0.9000 (source) is the latest build
✔ No downloads needed, all packages are cached
ℹ Packaging nanoarrow 0.0.0.9000
✔ Packaged nanoarrow 0.0.0.9000 (298ms)                          
ℹ Building nanoarrow 0.0.0.9000                                  
✖ Failed to build nanoarrow 0.0.0.9000                           
Error:                                                           
! error in pak subprocess
Caused by error in `stop_task_build(state, worker)`:
! Failed to build source package 'nanoarrow'
Full installation output:
* installing *source* package ‘nanoarrow’ ...
staged installation is only possible with locking
** using non-staged installation
Vendored src/nanoarrow.h and/or src/nanoarrow.c are missing
ERROR: configuration failed for package ‘nanoarrow’
* removing ‘/private/var/folders/gt/l87wjg8s7312zs9s7c1fgs900000gn/T/RtmpaubQl5/pkg-lib14a3e54a395ef/nanoarrow’
Type .Last.error to see the more details.

I can't quite locate where in https://github.com/r-lib/pkgdepends/blob/main/R/install-plan.R this could be changed but can take a look next week.

gaborcsardi commented 1 year ago

I don't think pkgdepends or pkgbuild do that. OTOH the first thing R CMD build does is copying the package directory.

paleolimbot commented 1 year ago

Sorry for the indirection...I shouldn't have tried to squeeze that in to the end of a work week. I edited the issue and can take a stab at a solution next week 🙂

gaborcsardi commented 1 year ago

Yeah, I would prefer running an R file with Rscript, that is more portable, and works if there is no sh on Windows. Even if Rtools is installed, sh might not be on the PATH.

paleolimbot commented 1 year ago

No rush, but I took a stab at this in https://github.com/r-lib/pkgbuild/pull/157 !