diff --git a/R/use_extendr.R b/R/use_extendr.R index e0694db3..7c62d9c7 100644 --- a/R/use_extendr.R +++ b/R/use_extendr.R @@ -172,6 +172,43 @@ use_extendr <- function(path = ".", data = list(pkg_name = pkg_name) ) + # create tools directory if it does not exist + if (!dir.exists("tools")) { + dir.create("tools") + } + + # add msrv.R template + use_rextendr_template( + "cran/msrv.R", + save_as = file.path("tools", "msrv.R"), + quiet = quiet, + overwrite = overwrite + ) + + # add configure and configure.win templates + use_rextendr_template( + "cran/configure", + save_as = "configure", + quiet = quiet, + overwrite = overwrite, + data = list(lib_name = lib_name) + ) + + # configure needs to be made executable + # ignore for Windows + if (.Platform[["OS.type"]] == "unix") { + Sys.chmod("configure", "0755") + } + + use_rextendr_template( + "cran/configure.win", + save_as = "configure.win", + quiet = quiet, + overwrite = overwrite, + data = list(lib_name = lib_name) + ) + + if (!isTRUE(quiet)) { cli::cli_alert_success("Finished configuring {.pkg extendr} for package {.pkg {pkg_name}}.") cli::cli_ul( diff --git a/tests/testthat/_snaps/use_cran_defaults.md b/tests/testthat/_snaps/use_cran_defaults.md index 4bd18e92..06295c5e 100644 --- a/tests/testthat/_snaps/use_cran_defaults.md +++ b/tests/testthat/_snaps/use_cran_defaults.md @@ -17,6 +17,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' v Writing 'R/extendr-wrappers.R' + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect. @@ -25,9 +28,9 @@ Code use_cran_defaults() Message - v Writing 'tools/msrv.R' - v Writing 'configure' - v Writing 'configure.win' + > File 'tools/msrv.R' already exists. Skip writing the file. + > File 'configure' already exists. Skip writing the file. + > File 'configure.win' already exists. Skip writing the file. > File 'src/Makevars' already exists. Skip writing the file. > File 'src/Makevars.win' already exists. Skip writing the file. v Adding "^src/rust/vendor$" to '.Rbuildignore'. diff --git a/tests/testthat/_snaps/use_extendr.md b/tests/testthat/_snaps/use_extendr.md index 5d8829ca..bb281aff 100644 --- a/tests/testthat/_snaps/use_extendr.md +++ b/tests/testthat/_snaps/use_extendr.md @@ -17,6 +17,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' v Writing 'R/extendr-wrappers.R' + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect. @@ -218,6 +221,9 @@ > File 'src/rust/src/lib.rs' already exists. Skip writing the file. > File 'src/testpkg.wrap-win.def' already exists. Skip writing the file. > File 'R/extendr-wrappers.R' already exists. Skip writing the file. + > File 'tools/msrv.R' already exists. Skip writing the file. + > File 'configure' already exists. Skip writing the file. + > File 'configure.win' already exists. Skip writing the file. v Finished configuring extendr for package testpkg.wrap. * Please run `rextendr::document()` for changes to take effect. @@ -235,6 +241,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' > File 'R/extendr-wrappers.R' already exists. Skip writing the file. + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect.