From 8c2ea1e5cf8e0d5b384da75239cacb3c2265ece6 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Tue, 18 Aug 2026 19:48:43 -0400 Subject: [PATCH] feat: default porcelain to the user library for 0.5.0 Setup, sitrep, and verify now target .libPaths()[1], latest runtime is the newest gdal-v* bundle, and sitrep reports the gdalraster package version. Co-authored-by: Cursor --- .github/workflows/build.yml | 3 +- .github/workflows/e2e.yml | 1 - .github/workflows/edge-cases.yml | 5 +- AGENTS.md | 12 +- DESCRIPTION | 2 +- NEWS.md | 34 ++++- R/aaa.R | 6 +- R/gdal_build.R | 43 ++++-- R/gdal_python.R | 14 +- R/gdal_runtime.R | 9 +- R/gdal_setup.R | 39 +++-- R/gdal_sitrep.R | 188 ++++++++++++++++++++----- R/gdal_verify.R | 16 ++- R/manifest.R | 2 +- R/utils_pkg.R | 75 ++++++++-- R/zzz.R | 3 - README.md | 21 ++- dev/scripts/local_release_verify.R | 7 +- dev/scripts/pkg_docs.R | 2 +- dev/scripts/test_script.R | 10 +- dev/tmp/verify_move_aside.R | 60 -------- inst/extdata/README.md | 7 +- man/gdal_build_gdalraster.Rd | 14 +- man/gdal_enable_python.Rd | 13 +- man/gdal_home.Rd | 2 +- man/gdal_setup.Rd | 14 +- man/gdal_sitrep.Rd | 24 +++- man/gdal_uninstall.Rd | 12 +- man/gdal_update.Rd | 12 +- man/gdal_verify.Rd | 17 ++- tests/testthat/helper-fixtures.R | 16 ++- tests/testthat/test-manifest-runtime.R | 48 +++++++ tests/testthat/test-sitrep-api.R | 162 ++++++++++++++++++++- vignettes/architecture.qmd | 2 +- vignettes/getting-started.qmd | 27 ++-- vignettes/runtime-guide.qmd | 16 +-- vignettes/troubleshooting.qmd | 21 +-- 37 files changed, 702 insertions(+), 257 deletions(-) delete mode 100644 dev/tmp/verify_move_aside.R diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a7b709..707f623 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -130,7 +130,7 @@ jobs: "" \ "or dispatch the Build GDAL (Windows) workflow with \`gdal_version=${upstream_tag}\`." \ "" \ - "After publishing, rebuild gdalraster against the new bundle and verify with \`gdalraster.windows::verify_gdalraster_runtime()\`, then update the README latest-release line and the default \`gdal_version\` in build.yml.")" + "After publishing, rebuild gdalraster against the new bundle and verify with \`gdalraster.windows::gdal_verify()\`, then update the README latest-release line and the default \`gdal_version\` in build.yml.")" # ───────────────────────────────────────────────────────────────────────────── # JOB 1 — Build GDAL from source @@ -525,7 +525,6 @@ jobs: ```r pak::pak("${{ github.repository }}") gdalraster.windows::gdal_setup( - user_lib = TRUE, tag = "${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || steps.names.outputs.release_tag }}" ) library(gdalraster) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 645a31e..a981bf7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -56,7 +56,6 @@ jobs: tag <- Sys.getenv("RUNTIME_TAG", unset = "latest") if (!nzchar(tag)) tag <- "latest" gdalraster.windows::gdal_setup( - user_lib = TRUE, tag = tag, verify = TRUE ) diff --git a/.github/workflows/edge-cases.yml b/.github/workflows/edge-cases.yml index 02698f9..c3d677b 100644 --- a/.github/workflows/edge-cases.yml +++ b/.github/workflows/edge-cases.yml @@ -62,7 +62,7 @@ jobs: tag <- Sys.getenv("RUNTIME_TAG", unset = "latest") scenario <- Sys.getenv("SCENARIO") gdalraster.windows::gdal_setup( - user_lib = scenario != "foreign-gdalraster", + isolated = scenario == "foreign-gdalraster", tag = tag, verify = scenario != "foreign-gdalraster" ) @@ -104,7 +104,6 @@ jobs: path.expand("~/.Rprofile") ) state <- gdalraster.windows::gdal_sitrep( - user_lib = TRUE, network = FALSE, quiet = TRUE ) @@ -150,6 +149,7 @@ jobs: if (scenario == "foreign-gdalraster") { state <- gdalraster.windows::gdal_sitrep( + isolated = TRUE, network = FALSE, quiet = TRUE ) @@ -168,7 +168,6 @@ jobs: ) stopifnot(is.null(result)) stopifnot(gdalraster.windows::gdal_verify( - user_lib = TRUE, python = FALSE, quiet = TRUE )) diff --git a/AGENTS.md b/AGENTS.md index 2695ea8..b98e701 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,15 +9,16 @@ Primary user flow: ```r pak::pak("jimbrig/gdalraster.windows") -gdalraster.windows::gdal_setup(user_lib = TRUE) +gdalraster.windows::gdal_setup() # every later session library(gdalraster) gdalraster::gdal_global_reg_names() ``` -The non-destructive setup default uses an isolated package-managed library. -Users opt into replacement in `.libPaths()[1]` with `user_lib = TRUE`. +Setup, sitrep, verify, and update default to `.libPaths()[1]`. Pass `lib` +for a custom library, or `isolated = TRUE` for the package-managed isolated +library under `tools::R_user_dir("gdalraster.windows", "data")/library`. ## required system behavior @@ -39,7 +40,7 @@ Users opt into replacement in `.libPaths()[1]` with `user_lib = TRUE`. persist or export `PYTHONPATH`. 8. Verify in fresh processes that the Algorithm API, required drivers, first Parquet open, CRS support, and GeoPackage validator work. -9. Keep installs non-destructive by default. +9. Default installs target the user library; isolated installs are opt-in. ## responsibility split @@ -74,7 +75,8 @@ There is no runtime activation API, auto-bootstrap, `.Rprofile` hook, - Use `rlang::caller_env()` and `rlang::caller_arg()` in validators. - Use `withr` for scoped state. - Stage complete package replacements before changing an installed package. -- Preserve the isolated library as the default build destination. +- Default `gdalraster` installs to `.libPaths()[1]`; isolated library + installs are opt-in via `isolated = TRUE`. - Never add Parquet initialization or session-order workarounds; Arrow/TLS correctness belongs to the bundle build. diff --git a/DESCRIPTION b/DESCRIPTION index 791beb9..949c9d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gdalraster.windows Title: Self-Contained gdalraster Builds for Windows -Version: 0.4.0 +Version: 0.5.0 Authors@R: person("Jimmy", "Briggs", , "jimmy.briggs@jimbrig.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7489-8787")) diff --git a/NEWS.md b/NEWS.md index fc31320..dabbbee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,33 @@ +# gdalraster.windows 0.5.0 + +## Breaking changes + +- Porcelain functions (`gdal_setup()`, `gdal_sitrep()`, `gdal_verify()`, + `gdal_update()`, `gdal_uninstall()`, `gdal_build_gdalraster()`, and + `gdal_enable_python()`) now default to `.libPaths()[1]`, the library used + by `library(gdalraster)`. Pass `lib` for a custom library, or + `isolated = TRUE` for the package-managed isolated library. `user_lib` + remains accepted as a deprecated alias (`user_lib = FALSE` is equivalent + to `isolated = TRUE`). + +## Sitrep and runtime selection + +- `gdal_home()` and the default data/library paths are slash-normalized. +- Latest runtime selection uses the newest published `gdal-v*` GDAL bundle, + not R package tags such as `v0.3.1` that still carry a leftover zip. +- `gdal_sitrep()` reports the installed `gdalraster` package version on the + gdalraster line, not the GDAL runtime tag. It prints the inspected + `gdal_home` and library paths, reports missing build provenance instead of + `NA`, and no longer warns about other `libgdal` DLLs merely present on + `PATH`. + +## Migration from 0.4.0 + +- Bare `gdal_setup()` / `gdal_sitrep()` now target `.libPaths()[1]`. Isolated + leftovers under `tools::R_user_dir("gdalraster.windows", "data")/library` + are unused unless you pass `isolated = TRUE`. Remove them with + `gdal_uninstall(isolated = TRUE, runtime = FALSE, python = FALSE)`. + # gdalraster.windows 0.4.0 ## Breaking redesign @@ -54,8 +84,8 @@ removed activation helpers. 2. Remove persistent GDAL-related `PATH`, `GDAL_DATA`, `PROJ_DATA`, `PROJ_LIB`, and `PYTHONPATH` workarounds. -3. Run `gdal_setup(user_lib = TRUE)` once for plain - `library(gdalraster)` discovery, or omit `user_lib` for an isolated install. +3. Run `gdal_setup()` once for plain `library(gdalraster)` discovery, or + `gdal_setup(isolated = TRUE)` for an isolated install. # gdalraster.windows 0.3.1 diff --git a/R/aaa.R b/R/aaa.R index 0fd1e5c..1377f9e 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -1,4 +1,3 @@ - # ------------------------------------------------------------------------ # # Title : Shared Package Resources @@ -26,6 +25,11 @@ #' @keywords internal .bundle_asset_pattern <- "gdal-(bundle|ucrt64)-.*\\.zip$" +#' Regex selecting GDAL runtime bundle release tags +#' @noRd +#' @keywords internal +.bundle_tag_pattern <- "^gdal-v" + # stale runtime naming ------------------------------------------------------- #' Suffix marking sibling directories that hold moved-aside runtime files diff --git a/R/gdal_build.R b/R/gdal_build.R index a103d0e..cebe0a1 100644 --- a/R/gdal_build.R +++ b/R/gdal_build.R @@ -5,11 +5,11 @@ #' installed package, then records build provenance. #' #' @param gdal_home Installed GDAL build runtime. -#' @param lib Destination library. The default is an isolated package-managed -#' library. -#' @param user_lib Install into `.libPaths()[1]`. This is destructive when an -#' existing `gdalraster` is installed there and requires `force = TRUE` in -#' non-interactive sessions. +#' @param lib Destination library. Defaults to `.libPaths()[1]`. +#' @param isolated Install into the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. #' @param source_tarball Optional local `gdalraster` source tarball. #' @param repo Upstream source repository. #' @param ref Git reference used for the source archive. @@ -24,7 +24,8 @@ gdal_build_gdalraster <- function( gdal_home = default_gdal_home(), lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, source_tarball = NULL, repo = .gdalraster_repo, ref = "HEAD", @@ -35,7 +36,8 @@ gdal_build_gdalraster <- function( ) { abort_if_not_windows() abort_if_no_build_tools() - check_flag(user_lib) + check_flag(isolated) + check_optional_flag(user_lib) check_flag(upgrade) check_flag(force) check_flag(enable_python) @@ -57,7 +59,7 @@ gdal_build_gdalraster <- function( ) } - lib <- resolve_gdalraster_lib(lib = lib, user_lib = user_lib) + lib <- resolve_gdalraster_lib(lib = lib, isolated = isolated, user_lib = user_lib) package_dir <- file.path(lib, "gdalraster") if ("gdalraster" %in% loadedNamespaces()) { cli::cli_abort( @@ -106,8 +108,12 @@ gdal_build_gdalraster <- function( makevars <- c( GDAL_HOME = gdal_home, PKG_CPPFLAGS = paste0("-I\"", file.path(gdal_home, "include"), "\""), + # --allow-multiple-definition is a linker workaround for symbol overlap + # between the bundle import library and residual Rtools GDAL archives on + # the search path. see #3. do not treat this as a permanent contract. PKG_LIBS = paste0( - "-L\"", file.path(gdal_home, "lib"), + "-L\"", + file.path(gdal_home, "lib"), "\" -lgdal -Wl,--allow-multiple-definition" ) ) @@ -180,12 +186,21 @@ gdal_build_gdalraster <- function( #' @keywords internal #' @noRd -resolve_gdalraster_lib <- function(lib = NULL, user_lib = FALSE) { - if (isTRUE(user_lib)) { - return(normalizePath(.libPaths()[[1L]], winslash = "/", mustWork = FALSE)) +resolve_gdalraster_lib <- function( + lib = NULL, + isolated = FALSE, + user_lib = NULL +) { + if (!is.null(user_lib)) { + isolated <- !isTRUE(user_lib) + } + if (!is.null(lib)) { + return(normalize_pkg_path(lib)) + } + if (isTRUE(isolated)) { + return(default_gdalraster_lib()) } - lib <- if (is.null(lib)) default_gdalraster_lib() else lib - normalizePath(lib, winslash = "/", mustWork = FALSE) + normalize_pkg_path(.libPaths()[[1L]]) } #' @keywords internal diff --git a/R/gdal_python.R b/R/gdal_python.R index 2ec14e0..69b417c 100644 --- a/R/gdal_python.R +++ b/R/gdal_python.R @@ -6,6 +6,11 @@ #' does not affect isolated virtual environments. #' #' @param lib Library containing the self-contained `gdalraster` package. +#' Defaults to `.libPaths()[1]`. +#' @param isolated Use the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. #' @param python Optional path to the CPython executable GDAL embeds. #' @param site_packages Optional explicit `site-packages` directory. #' @param quiet Suppress status messages. @@ -14,17 +19,22 @@ #' located. #' @export gdal_enable_python <- function( - lib = default_gdalraster_lib(), + lib = NULL, + isolated = FALSE, + user_lib = NULL, python = NULL, site_packages = NULL, quiet = FALSE ) { abort_if_not_windows() - check_string(lib) + check_flag(isolated) + check_optional_flag(user_lib) check_optional_string(python) check_optional_string(site_packages) check_flag(quiet) + lib <- resolve_gdalraster_lib(lib, isolated = isolated, user_lib = user_lib) + package_python <- file.path( normalizePath(lib, winslash = "/", mustWork = FALSE), "gdalraster", diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index 73cee2f..f329363 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -2,7 +2,7 @@ #' #' Resolution order is the `gdalraster.windows.gdal_home` option, the #' `GDALRASTER_WINDOWS_GDAL_HOME` environment variable, then the package-managed -#' user data directory. +#' user data directory. The returned path is normalized to forward slashes. #' #' @return A single path. #' @export @@ -95,8 +95,11 @@ gdal_install_runtime <- function( ) { cli::cli_alert_warning( paste0( - "GDAL runtime ", manifest_value(installed, "Bundle-Tag", "unknown"), - " is installed; ", asset$tag, " is available. Run gdal_update() to upgrade." + "GDAL runtime ", + manifest_value(installed, "Bundle-Tag", "unknown"), + " is installed; ", + asset$tag, + " is available. Run gdal_update() to upgrade." ) ) return(invisible(gdal_home)) diff --git a/R/gdal_setup.R b/R/gdal_setup.R index c536609..6364f49 100644 --- a/R/gdal_setup.R +++ b/R/gdal_setup.R @@ -2,10 +2,14 @@ #' #' Installs the GDAL build runtime when needed, builds and vendors #' `gdalraster`, provisions embedded Python when available, and verifies the -#' result in fresh processes. +#' result in fresh processes. The default destination is `.libPaths()[1]`. #' -#' @param lib Destination library for `gdalraster`. -#' @param user_lib Use `.libPaths()[1]` instead of the isolated managed library. +#' @param lib Destination library for `gdalraster`. Defaults to +#' `.libPaths()[1]`. +#' @param isolated Install into the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. #' @param update Upgrade the runtime to the requested/latest bundle and rebuild. #' @param force Reinstall and rebuild even when provenance is current. #' @param tag Runtime bundle release tag or `"latest"`. @@ -19,7 +23,8 @@ #' @export gdal_setup <- function( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, update = FALSE, force = FALSE, tag = "latest", @@ -30,7 +35,8 @@ gdal_setup <- function( verify = TRUE ) { abort_if_not_windows() - check_flag(user_lib) + check_flag(isolated) + check_optional_flag(user_lib) check_flag(update) check_flag(force) check_flag(upgrade) @@ -41,7 +47,7 @@ gdal_setup <- function( check_optional_string(fallback_zip) check_optional_string(source_tarball) - lib <- resolve_gdalraster_lib(lib, user_lib) + lib <- resolve_gdalraster_lib(lib, isolated = isolated, user_lib = user_lib) before <- gdal_sitrep(lib = lib, network = FALSE, quiet = TRUE) install_runtime <- !before$runtime_installed || isTRUE(update) || isTRUE(force) build_package <- !before$gdalraster_installed || @@ -88,7 +94,6 @@ gdal_setup <- function( gdal_build_gdalraster( gdal_home = default_gdal_home(), lib = lib, - user_lib = FALSE, source_tarball = source_tarball, upgrade = upgrade, force = after_runtime$gdalraster_installed || isTRUE(force) || isTRUE(update), @@ -131,7 +136,8 @@ gdal_setup <- function( #' @export gdal_update <- function( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, tag = "latest", local_zip = NULL, fallback_zip = NULL, @@ -141,6 +147,7 @@ gdal_update <- function( ) { gdal_setup( lib = lib, + isolated = isolated, user_lib = user_lib, update = TRUE, force = TRUE, @@ -155,8 +162,12 @@ gdal_update <- function( #' Uninstall managed GDAL resources #' -#' @param lib Library containing the managed `gdalraster` package. -#' @param user_lib Use `.libPaths()[1]`. +#' @param lib Library containing the managed `gdalraster` package. Defaults to +#' `.libPaths()[1]`. +#' @param isolated Remove the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. #' @param runtime Remove the GDAL build runtime. #' @param package Remove the managed `gdalraster` package. #' @param python Remove managed embedded-Python `.pth` files. @@ -166,21 +177,23 @@ gdal_update <- function( #' @export gdal_uninstall <- function( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, runtime = TRUE, package = TRUE, python = TRUE, force = FALSE ) { abort_if_not_windows() - check_flag(user_lib) + check_flag(isolated) + check_optional_flag(user_lib) check_flag(runtime) check_flag(package) check_flag(python) check_flag(force) check_optional_string(lib) - lib <- resolve_gdalraster_lib(lib, user_lib) + lib <- resolve_gdalraster_lib(lib, isolated = isolated, user_lib = user_lib) package_dir <- file.path(lib, "gdalraster") targets_exist <- (runtime && dir.exists(default_gdal_home())) || (package && dir.exists(package_dir)) || diff --git a/R/gdal_sitrep.R b/R/gdal_sitrep.R index 499a7c7..a907a04 100644 --- a/R/gdal_sitrep.R +++ b/R/gdal_sitrep.R @@ -1,29 +1,43 @@ #' Report GDAL and gdalraster installation state #' -#' Reports bundle and build provenance, staleness, embedded-Python -#' provisioning, and common collision risks without changing the session. +#' Reports the installed GDAL runtime, the `gdalraster` build in the active +#' library, staleness against the newest `gdal-v*` bundle, embedded-Python +#' provisioning, and session collision risks without changing the session. +#' +#' The default inspects `.libPaths()[1]`, the library used by +#' `library(gdalraster)`. Pass `lib` for a custom library, or `isolated = TRUE` +#' for the package-managed isolated library. #' #' @param lib Library expected to contain the managed `gdalraster` build. -#' @param user_lib Inspect `.libPaths()[1]` instead of the isolated library. -#' @param network Query GitHub for the latest bundle release. +#' Defaults to `.libPaths()[1]`. +#' @param isolated Inspect the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. +#' @param network Query GitHub for the latest GDAL runtime bundle (`gdal-v*`). #' @param quiet Return state without printing it. #' #' @return Invisibly, a named list describing installation state. #' @export gdal_sitrep <- function( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, network = rlang::is_interactive(), quiet = FALSE ) { - check_flag(user_lib) + check_flag(isolated) + check_optional_flag(user_lib) check_flag(network) check_flag(quiet) check_optional_string(lib) + if (!is.null(user_lib)) { + isolated <- !isTRUE(user_lib) + } home <- default_gdal_home() - lib <- resolve_gdalraster_lib(lib, user_lib) - package_dir <- file.path(lib, "gdalraster") + lib <- resolve_gdalraster_lib(lib, isolated = isolated) + package_dir <- normalize_pkg_path(file.path(lib, "gdalraster")) bundle <- installed_bundle_manifest(home) build <- read_manifest(build_manifest_path(package_dir)) latest <- if (isTRUE(network)) { @@ -41,20 +55,21 @@ gdal_sitrep <- function( pth_files <- managed_python_pth_files() pth_targets <- vapply(pth_files, pth_target, character(1)) - package_python <- normalizePath( - file.path(package_dir, "python"), - winslash = "/", - mustWork = FALSE - ) + package_python <- normalize_pkg_path(file.path(package_dir, "python")) python_ready <- any(!is.na(pth_targets) & identical_paths(pth_targets, package_python)) python_stale <- pth_files[is.na(pth_targets) | !dir.exists(pth_targets)] - path_gdal <- path_gdal_dlls() + path_gdal <- path_gdal_dlls(exclude = c(home, package_dir)) loaded_gdal <- loaded_gdal_dlls() legacy_hook <- legacy_hook_detected() - visible_gdalraster <- suppressWarnings(system.file(package = "gdalraster")) + visible_gdalraster <- visible_gdalraster_dir() foreign_gdalraster <- nzchar(visible_gdalraster) && !identical_paths(visible_gdalraster, package_dir) + visible_build <- if (nzchar(visible_gdalraster)) { + read_manifest(build_manifest_path(visible_gdalraster)) + } else { + NULL + } state <- list( gdal_home = home, @@ -64,19 +79,22 @@ gdal_sitrep <- function( latest_tag = latest, update_available = !is.na(latest) && !identical(latest, manifest_value(bundle, "Bundle-Tag")), + isolated = isolated, lib = lib, package_dir = package_dir, gdalraster_installed = dir.exists(package_dir), + gdalraster_version = installed_package_version(package_dir), build_tag = manifest_value(build, "Bundle-Tag"), build_current = build_is_current(bundle, build), python_ready = python_ready, - python_pth = pth_files, - python_stale = python_stale, + python_pth = normalize_pkg_path(pth_files), + python_stale = normalize_pkg_path(python_stale), path_gdal = path_gdal, loaded_gdal = loaded_gdal, legacy_hook = legacy_hook, foreign_gdalraster = foreign_gdalraster, - visible_gdalraster = visible_gdalraster + visible_gdalraster = visible_gdalraster, + visible_build_current = build_is_current(bundle, visible_build) ) if (!isTRUE(quiet)) { @@ -85,23 +103,63 @@ gdal_sitrep <- function( invisible(state) } +#' @keywords internal +#' @noRd +gdalraster_status_label <- function(state) { + if (!isTRUE(state$gdalraster_installed)) { + return("not installed") + } + version <- state$gdalraster_version + if (is.na(version) || !nzchar(version)) { + if (is.na(state$build_tag)) { + return("installed (missing provenance)") + } + return("installed") + } + version +} + +#' @keywords internal +#' @noRd +installed_package_version <- function(package_dir) { + path <- file.path(package_dir, "DESCRIPTION") + if (!file.exists(path)) { + return(NA_character_) + } + + fields <- tryCatch( + read.dcf(path, fields = "Version"), + error = function(cnd) NULL + ) + if (is.null(fields) || nrow(fields) != 1L) { + return(NA_character_) + } + version <- fields[1L, "Version"] + if (is.na(version) || !nzchar(version)) { + return(NA_character_) + } + unname(version) +} + #' @keywords internal #' @noRd print_gdal_sitrep <- function(state) { cli::cli_h2("gdalraster.windows") cli::cli_inform(c( - "*" = "runtime: {if (state$runtime_installed) state$bundle_tag else 'not installed'}", - "*" = "gdalraster: {if (state$gdalraster_installed) state$build_tag else 'not installed'}", + "*" = "GDAL runtime: {if (state$runtime_installed) state$bundle_tag else 'not installed'}", + "*" = "gdal_home: {.path {state$gdal_home}}", + "*" = "gdalraster: {gdalraster_status_label(state)}", + "*" = "library: {.path {state$lib}}", "*" = "build current: {.val {state$build_current}}", "*" = "embedded Python: {.val {state$python_ready}}" )) warnings <- character() if (isTRUE(state$update_available)) { - warnings <- c(warnings, paste0("bundle ", state$latest_tag, " is available")) - } - if (length(state$path_gdal) > 0L) { - warnings <- c(warnings, "other libgdal DLLs are present on PATH") + warnings <- c( + warnings, + paste0("GDAL runtime ", state$latest_tag, " is available") + ) } if (length(state$loaded_gdal) > 0L) { warnings <- c(warnings, "a libgdal DLL is already loaded in this session") @@ -109,8 +167,23 @@ print_gdal_sitrep <- function(state) { if (isTRUE(state$legacy_hook)) { warnings <- c(warnings, "a legacy gdalraster.windows .Rprofile hook was detected") } - if (isTRUE(state$foreign_gdalraster)) { - warnings <- c(warnings, "a different gdalraster installation is visible on .libPaths()") + if (isTRUE(state$foreign_gdalraster) && isTRUE(state$isolated)) { + warnings <- c( + warnings, + paste0( + "library(gdalraster) would load ", + state$visible_gdalraster, + " instead of the isolated install" + ) + ) + } else if (isTRUE(state$foreign_gdalraster)) { + warnings <- c( + warnings, + paste0( + "library(gdalraster) currently loads ", + state$visible_gdalraster + ) + ) } if (length(state$python_stale) > 0L) { warnings <- c(warnings, "a managed Python .pth file has a stale target") @@ -122,7 +195,7 @@ print_gdal_sitrep <- function(state) { if (!isTRUE(state$runtime_installed) || !isTRUE(state$gdalraster_installed)) { cli::cli_inform(c("i" = "Run {.fn gdal_setup} to complete setup.")) } else if (!isTRUE(state$build_current)) { - cli::cli_inform(c("i" = "Run {.fn gdal_update} to rebuild against the installed bundle.")) + cli::cli_inform(c("i" = "Run {.fn gdal_update} to rebuild against the installed GDAL runtime.")) } else { cli::cli_inform(c("i" = "Run {.fn gdal_verify} for fresh-process verification.")) } @@ -131,21 +204,50 @@ print_gdal_sitrep <- function(state) { #' @keywords internal #' @noRd identical_paths <- function(x, y) { - tolower(normalizePath(x, winslash = "/", mustWork = FALSE)) == - tolower(normalizePath(y, winslash = "/", mustWork = FALSE)) + tolower(normalize_pkg_path(x)) == tolower(normalize_pkg_path(y)) } #' @keywords internal #' @noRd -path_gdal_dlls <- function() { +path_is_under <- function(path, root) { + if ( + length(path) != 1L || + length(root) != 1L || + is.na(path) || + is.na(root) || + !nzchar(path) || + !nzchar(root) + ) { + return(FALSE) + } + path <- tolower(normalize_pkg_path(path)) + root <- tolower(normalize_pkg_path(root)) + identical(path, root) || startsWith(path, paste0(root, "/")) +} + +#' @keywords internal +#' @noRd +path_gdal_dlls <- function(exclude = character()) { parts <- strsplit(Sys.getenv("PATH", unset = ""), .Platform$path.sep, fixed = TRUE)[[1L]] parts <- unique(parts[nzchar(parts) & dir.exists(parts)]) - unique(unlist(lapply( - parts, - list.files, - pattern = .gdal_dll_pattern, - full.names = TRUE - ), use.names = FALSE)) + dlls <- unique(unlist( + lapply( + parts, + list.files, + pattern = .gdal_dll_pattern, + full.names = TRUE + ), + use.names = FALSE + )) + dlls <- normalize_pkg_path(dlls) + keep <- !vapply( + dlls, + function(dll) { + any(vapply(exclude, function(root) path_is_under(dll, root), logical(1))) + }, + logical(1) + ) + unname(dlls[keep]) } #' @keywords internal @@ -156,7 +258,19 @@ loaded_gdal_dlls <- function() { function(dll) dll[["path"]], character(1) ) - unname(paths[grepl(.gdal_dll_pattern, basename(paths), ignore.case = TRUE)]) + normalize_pkg_path( + unname(paths[grepl(.gdal_dll_pattern, basename(paths), ignore.case = TRUE)]) + ) +} + +#' @keywords internal +#' @noRd +visible_gdalraster_dir <- function() { + path <- suppressWarnings(system.file(package = "gdalraster")) + if (!nzchar(path)) { + return("") + } + normalize_pkg_path(path) } #' @keywords internal diff --git a/R/gdal_verify.R b/R/gdal_verify.R index 4ffcbd3..92b5aa9 100644 --- a/R/gdal_verify.R +++ b/R/gdal_verify.R @@ -5,8 +5,12 @@ #' registration, a first Parquet dataset open, and the GeoPackage Python #' validator when embedded Python has been provisioned. #' -#' @param lib Library containing the managed `gdalraster` package. -#' @param user_lib Use `.libPaths()[1]`. +#' @param lib Library containing the managed `gdalraster` package. Defaults to +#' `.libPaths()[1]`. +#' @param isolated Verify the package-managed isolated library instead of +#' `.libPaths()[1]`. Ignored when `lib` is set. +#' @param user_lib Deprecated. `user_lib = TRUE` is now the default; +#' `user_lib = FALSE` is equivalent to `isolated = TRUE`. #' @param python Run the embedded-Python validation when its managed `.pth` #' file is ready. #' @param quiet Suppress verification output. @@ -15,17 +19,19 @@ #' @export gdal_verify <- function( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, python = TRUE, quiet = FALSE ) { abort_if_not_windows() - check_flag(user_lib) + check_flag(isolated) + check_optional_flag(user_lib) check_flag(python) check_flag(quiet) check_optional_string(lib) - lib <- resolve_gdalraster_lib(lib, user_lib) + lib <- resolve_gdalraster_lib(lib, isolated = isolated, user_lib = user_lib) package_dir <- file.path(lib, "gdalraster") if (!dir.exists(package_dir)) { if (!isTRUE(quiet)) { diff --git a/R/manifest.R b/R/manifest.R index b3be334..e4feb7e 100644 --- a/R/manifest.R +++ b/R/manifest.R @@ -90,7 +90,7 @@ installed_bundle_manifest <- function(gdal_home = default_gdal_home()) { #' @keywords internal #' @noRd -installed_build_manifest <- function(lib = default_gdalraster_lib()) { +installed_build_manifest <- function(lib = normalize_pkg_path(.libPaths()[[1L]])) { read_manifest(build_manifest_path(file.path(lib, "gdalraster"))) } diff --git a/R/utils_pkg.R b/R/utils_pkg.R index d6ea5c9..489952b 100644 --- a/R/utils_pkg.R +++ b/R/utils_pkg.R @@ -23,20 +23,40 @@ pkg_version <- function() { # paths ----------------------------------------------------------------------------------------------------------- +#' Normalize package-managed paths to forward slashes +#' @keywords internal +#' @noRd +normalize_pkg_path <- function(path, mustWork = FALSE) { + if (!is.character(path) || length(path) == 0L) { + return(path) + } + vapply( + path, + function(item) { + if (is.na(item) || !nzchar(item)) { + return(item) + } + normalizePath(item, winslash = "/", mustWork = mustWork) + }, + character(1), + USE.NAMES = FALSE + ) +} + #' @keywords internal #' @noRd default_gdal_home <- function() { opt_home <- getOption("gdalraster.windows.gdal_home", default = "") if (is.character(opt_home) && length(opt_home) == 1L && nzchar(opt_home)) { - return(normalizePath(opt_home, winslash = "/", mustWork = FALSE)) + return(normalize_pkg_path(opt_home)) } env_home <- Sys.getenv("GDALRASTER_WINDOWS_GDAL_HOME", unset = "") if (nzchar(env_home)) { - return(normalizePath(env_home, winslash = "/", mustWork = FALSE)) + return(normalize_pkg_path(env_home)) } - file.path(tools::R_user_dir(pkg_name(), which = "data"), "gdal") + normalize_pkg_path(file.path(tools::R_user_dir(pkg_name(), which = "data"), "gdal")) } #' @keywords internal @@ -131,7 +151,7 @@ cleanup_stale_runtimes <- function(gdal_home) { #' @keywords internal #' @noRd default_gdalraster_lib <- function() { - file.path(tools::R_user_dir(pkg_name(), which = "data"), "library") + normalize_pkg_path(file.path(tools::R_user_dir(pkg_name(), which = "data"), "library")) } #' @keywords internal @@ -211,6 +231,19 @@ check_flag <- function(x, arg = rlang::caller_arg(x), call = rlang::caller_env() invisible(x) } +#' @keywords internal +#' @noRd +check_optional_flag <- function( + x, + arg = rlang::caller_arg(x), + call = rlang::caller_env() +) { + if (!is.null(x)) { + check_flag(x, arg = arg, call = call) + } + invisible(x) +} + #' @keywords internal #' @noRd abort_if_missing_dir <- function(path, arg, call = rlang::caller_env()) { @@ -303,22 +336,40 @@ github_api_json <- function(url, pat = github_pat()) { httr2::resp_body_json(resp, simplifyVector = FALSE) } -#' Pick the first (newest) non-draft, non-prerelease release carrying an -#' asset that matches `asset_pattern`. +#' Pick the newest published non-draft, non-prerelease `gdal-v*` release +#' carrying an asset that matches `asset_pattern`. #' #' The repository publishes two kinds of releases: GDAL runtime bundle -#' releases (`gdal-v*`, with a bundle zip asset) and R package releases -#' (`v*`, no bundle asset). GitHub's single "latest release" pointer usually -#' tracks the package releases, so "latest" here is resolved by scanning the -#' release list for bundle assets instead of trusting `/releases/latest`. +#' releases (`gdal-v*` tags, with a bundle zip asset) and R package releases +#' (`v*` tags). Package releases may still carry a leftover bundle zip from +#' earlier publishing, so "latest" ignores `v*` tags even when an asset +#' matches. GitHub's `/releases/latest` pointer tracks the package releases, +#' so this scans the release list instead. #' #' @keywords internal #' @noRd select_release_asset <- function(releases, asset_pattern, call = rlang::caller_env()) { + published_at <- vapply( + releases, + function(release) { + value <- release$published_at + if (is.null(value) || !nzchar(value)) { + return("1970-01-01T00:00:00Z") + } + as.character(value) + }, + character(1) + ) + releases <- releases[order(published_at, decreasing = TRUE)] + for (release in releases) { if (isTRUE(release$draft) || isTRUE(release$prerelease)) { next } + tag <- release$tag_name + if (is.null(tag) || !grepl(.bundle_tag_pattern, tag)) { + next + } for (asset in release$assets) { asset_name <- asset[["name"]] if (is.null(asset_name) || !nzchar(asset_name)) { @@ -329,14 +380,14 @@ select_release_asset <- function(releases, asset_pattern, call = rlang::caller_e id = asset$id, name = asset_name, url = asset$browser_download_url, - tag = release$tag_name + tag = tag )) } } } cli::cli_abort( - "No release with an asset matching {.val {asset_pattern}} was found.", + "No {.val gdal-v*} release with an asset matching {.val {asset_pattern}} was found.", call = call ) } diff --git a/R/zzz.R b/R/zzz.R index 78f399b..a2ae960 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,9 +3,6 @@ .onAttach <- function(libname, pkgname) { bundle <- installed_bundle_manifest() build <- installed_build_manifest() - if (!build_is_current(bundle, build)) { - build <- installed_build_manifest(.libPaths()[[1L]]) - } if (build_is_current(bundle, build)) { packageStartupMessage( cli::format_inline( diff --git a/README.md b/README.md index 40eb5ba..895bd70 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,12 @@ data, and `osgeo_utils`. Later sessions require no activation helper, ## Setup -To install the self-contained build into the regular user library: +Install the package, then build a self-contained `gdalraster` into the regular +user library: ```r pak::pak("jimbrig/gdalraster.windows") -gdalraster.windows::gdal_setup(user_lib = TRUE) +gdalraster.windows::gdal_setup() ``` Then, in any fresh session: @@ -35,20 +36,15 @@ library(gdalraster) gdalraster::gdal_global_reg_names() ``` -The default remains non-destructive and targets an isolated managed library: - -```r -gdalraster.windows::gdal_setup() -``` - -Pass `user_lib = TRUE` when plain `library(gdalraster)` discovery is required. +Pass `lib` for a custom library, or `isolated = TRUE` for a package-managed +library that does not replace `.libPaths()[1]`. ## Status, verification, and updates ```r -gdalraster.windows::gdal_sitrep(user_lib = TRUE) -gdalraster.windows::gdal_verify(user_lib = TRUE) -gdalraster.windows::gdal_update(user_lib = TRUE) +gdalraster.windows::gdal_sitrep() +gdalraster.windows::gdal_verify() +gdalraster.windows::gdal_update() ``` Verification runs in fresh processes and checks: @@ -63,7 +59,6 @@ Verification runs in fresh processes and checks: ```r gdalraster.windows::gdal_setup( - user_lib = TRUE, local_zip = "C:/Downloads/gdal-bundle-v3.13.2-windows-x64.zip" ) ``` diff --git a/dev/scripts/local_release_verify.R b/dev/scripts/local_release_verify.R index 1309e37..7759d42 100644 --- a/dev/scripts/local_release_verify.R +++ b/dev/scripts/local_release_verify.R @@ -1,12 +1,11 @@ -# non-interactive local verification for 0.4.0 + gdal-v3.13.2 +# non-interactive local verification for 0.5.0 + gdal-v3.13.2 options(warn = 1) stopifnot(!interactive()) library(gdalraster.windows) -cat("== gdal_setup(user_lib=TRUE, tag=gdal-v3.13.2) ==\n") +cat("== gdal_setup(tag=gdal-v3.13.2) ==\n") gdal_setup( - user_lib = TRUE, tag = "gdal-v3.13.2", force = TRUE, update = TRUE, @@ -14,7 +13,7 @@ gdal_setup( ) cat("== sitrep ==\n") -print(gdal_sitrep(user_lib = TRUE, network = FALSE)) +print(gdal_sitrep(network = FALSE)) cat("== fresh-session functional checks ==\n") script <- tempfile(fileext = ".R") diff --git a/dev/scripts/pkg_docs.R b/dev/scripts/pkg_docs.R index 64db3f4..a71cf3d 100644 --- a/dev/scripts/pkg_docs.R +++ b/dev/scripts/pkg_docs.R @@ -12,7 +12,7 @@ # gdalraster is a soft dependency: declared in Suggests (extra.suggests) but # never required to be installed locally (pkg_ignore + # check_if_suggests_is_installed = FALSE) since this package builds its own -# gdalraster from source into an isolated library. +# gdalraster from source into `.libPaths()[1]` by default. attachment::att_amend_desc( pkg_ignore = "gdalraster", extra.suggests = "gdalraster", diff --git a/dev/scripts/test_script.R b/dev/scripts/test_script.R index e42d733..2e014fb 100644 --- a/dev/scripts/test_script.R +++ b/dev/scripts/test_script.R @@ -1,7 +1,7 @@ pak::pak("jimbrig/gdalraster.windows") -gdalraster.windows::install_gdal_runtime(overwrite = TRUE) -gdalraster.windows::install_gdalraster() -gdalraster.windows::load_gdalraster() -gdalraster::gdal_version() # expect 3.13.1, released 2026-06-05 +gdalraster.windows::gdal_setup() +library(gdalraster) +gdalraster::gdal_version() gdalraster::gdal_global_reg_names() -gdalraster.windows::verify_gdalraster_runtime() +gdalraster.windows::gdal_sitrep() +gdalraster.windows::gdal_verify() diff --git a/dev/tmp/verify_move_aside.R b/dev/tmp/verify_move_aside.R deleted file mode 100644 index 746ceb4..0000000 --- a/dev/tmp/verify_move_aside.R +++ /dev/null @@ -1,60 +0,0 @@ -# repro of the self-lock overwrite failure, against a temp copy of the real -# runtime so the installed runtime is never touched. run with Rscript. - -options(gdalraster.windows.auto_bootstrap = FALSE) -pkgload::load_all("D:/jimbrig/gdalraster.windows", export_all = FALSE, quiet = TRUE) - -real_home <- gdalraster.windows::gdal_home() -stopifnot(dir.exists(file.path(real_home, "bin"))) - -root <- file.path(tempdir(), "move-aside-repro") -tmp_home <- file.path(root, "gdal") -dir.create(tmp_home, recursive = TRUE, showWarnings = FALSE) -ok <- file.copy(file.path(real_home, "bin"), tmp_home, recursive = TRUE) -stopifnot(isTRUE(ok)) - -# preload from the temp copy: maps libgdal + full dependency chain, exactly -# what the .onLoad auto-bootstrap did in the failing session -gdalraster.windows::activate_gdal_runtime(gdal_home = tmp_home, preload = TRUE, quiet = TRUE) -cat("preloaded runtime dlls:", length(gdalraster.windows:::loaded_runtime_dlls(tmp_home)), "\n") - -# the failing session performed the release download via httr2/curl while the -# runtime bin dir was on PATH; replicate that so any curl/openssl dependency -# resolution against the runtime dir happens here too -invisible(tryCatch( - httr2::req_perform(httr2::request("https://api.github.com")), - error = function(e) NULL -)) - -# minimal replacement bundle zip -fixture_root <- file.path(root, "fixture") -dir.create(file.path(fixture_root, "bundle", "bin"), recursive = TRUE, showWarnings = FALSE) -writeLines("new", file.path(fixture_root, "bundle", "bin", "libgdal-39.dll")) -zip_path <- file.path(root, "bundle.zip") -old_wd <- setwd(fixture_root) -utils::zip(zipfile = zip_path, files = "bundle", flags = "-r9Xq") -setwd(old_wd) - -gdalraster.windows::install_gdal_runtime( - gdal_home = tmp_home, - overwrite = TRUE, - local_zip = zip_path -) - -stopifnot(file.exists(file.path(tmp_home, "bin", "libgdal-39.dll"))) -stopifnot(identical(readLines(file.path(tmp_home, "bin", "libgdal-39.dll")), "new")) - -stale <- list.files(root, pattern = "^gdal\\.stale-", full.names = TRUE) -cat("stale dirs:", length(stale), "\n") -if (length(stale) == 1L) { - moved <- list.files(stale, recursive = TRUE) - cat("files moved aside:", length(moved), "\n") - cat("zlib1 moved aside:", "bin/zlib1.dll" %in% moved, "\n") -} - -# a later install must reclaim the stale dir once this process exits; here it -# is still pinned, so cleanup must silently leave it in place -gdalraster.windows:::cleanup_stale_runtimes(tmp_home) -cat("stale dir survives while pinned:", dir.exists(stale[1]), "\n") - -cat("REPRO-OK\n") diff --git a/inst/extdata/README.md b/inst/extdata/README.md index 8e75a96..5713b26 100644 --- a/inst/extdata/README.md +++ b/inst/extdata/README.md @@ -1,13 +1,14 @@ Optional packaged fallback runtime asset location. -If you want `install_gdal_runtime()` to have an offline fallback, place: +If you want `gdal_install_runtime()` / `gdal_setup()` to have an offline +fallback, place: - `gdal-ucrt64-fallback.zip` in this directory before building/installing the package. -At runtime, `install_gdal_runtime()` will use this file only when: +At runtime, the installer uses this file only when: - `local_zip` is not supplied, and - release download fails, and -- fallback zip exists. +- the fallback zip exists. diff --git a/man/gdal_build_gdalraster.Rd b/man/gdal_build_gdalraster.Rd index 69f5b3e..d32110e 100644 --- a/man/gdal_build_gdalraster.Rd +++ b/man/gdal_build_gdalraster.Rd @@ -7,7 +7,8 @@ gdal_build_gdalraster( gdal_home = default_gdal_home(), lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, source_tarball = NULL, repo = .gdalraster_repo, ref = "HEAD", @@ -20,12 +21,13 @@ gdal_build_gdalraster( \arguments{ \item{gdal_home}{Installed GDAL build runtime.} -\item{lib}{Destination library. The default is an isolated package-managed -library.} +\item{lib}{Destination library. Defaults to \code{.libPaths()[1]}.} -\item{user_lib}{Install into \code{.libPaths()[1]}. This is destructive when an -existing \code{gdalraster} is installed there and requires \code{force = TRUE} in -non-interactive sessions.} +\item{isolated}{Install into the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{source_tarball}{Optional local \code{gdalraster} source tarball.} diff --git a/man/gdal_enable_python.Rd b/man/gdal_enable_python.Rd index 28a0ae0..c9d37ac 100644 --- a/man/gdal_enable_python.Rd +++ b/man/gdal_enable_python.Rd @@ -5,14 +5,23 @@ \title{Enable GDAL embedded-Python utilities} \usage{ gdal_enable_python( - lib = default_gdalraster_lib(), + lib = NULL, + isolated = FALSE, + user_lib = NULL, python = NULL, site_packages = NULL, quiet = FALSE ) } \arguments{ -\item{lib}{Library containing the self-contained \code{gdalraster} package.} +\item{lib}{Library containing the self-contained \code{gdalraster} package. +Defaults to \code{.libPaths()[1]}.} + +\item{isolated}{Use the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{python}{Optional path to the CPython executable GDAL embeds.} diff --git a/man/gdal_home.Rd b/man/gdal_home.Rd index 703733f..2550e85 100644 --- a/man/gdal_home.Rd +++ b/man/gdal_home.Rd @@ -12,5 +12,5 @@ A single path. \description{ Resolution order is the \code{gdalraster.windows.gdal_home} option, the \code{GDALRASTER_WINDOWS_GDAL_HOME} environment variable, then the package-managed -user data directory. +user data directory. The returned path is normalized to forward slashes. } diff --git a/man/gdal_setup.Rd b/man/gdal_setup.Rd index c9dde00..5e67d88 100644 --- a/man/gdal_setup.Rd +++ b/man/gdal_setup.Rd @@ -6,7 +6,8 @@ \usage{ gdal_setup( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, update = FALSE, force = FALSE, tag = "latest", @@ -18,9 +19,14 @@ gdal_setup( ) } \arguments{ -\item{lib}{Destination library for \code{gdalraster}.} +\item{lib}{Destination library for \code{gdalraster}. Defaults to +\code{.libPaths()[1]}.} -\item{user_lib}{Use \code{.libPaths()[1]} instead of the isolated managed library.} +\item{isolated}{Install into the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{update}{Upgrade the runtime to the requested/latest bundle and rebuild.} @@ -44,5 +50,5 @@ Invisibly, a list describing performed actions. \description{ Installs the GDAL build runtime when needed, builds and vendors \code{gdalraster}, provisions embedded Python when available, and verifies the -result in fresh processes. +result in fresh processes. The default destination is \code{.libPaths()[1]}. } diff --git a/man/gdal_sitrep.Rd b/man/gdal_sitrep.Rd index 719a450..af8b8b7 100644 --- a/man/gdal_sitrep.Rd +++ b/man/gdal_sitrep.Rd @@ -6,17 +6,23 @@ \usage{ gdal_sitrep( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, network = rlang::is_interactive(), quiet = FALSE ) } \arguments{ -\item{lib}{Library expected to contain the managed \code{gdalraster} build.} +\item{lib}{Library expected to contain the managed \code{gdalraster} build. +Defaults to \code{.libPaths()[1]}.} -\item{user_lib}{Inspect \code{.libPaths()[1]} instead of the isolated library.} +\item{isolated}{Inspect the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} -\item{network}{Query GitHub for the latest bundle release.} +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} + +\item{network}{Query GitHub for the latest GDAL runtime bundle (\verb{gdal-v*}).} \item{quiet}{Return state without printing it.} } @@ -24,6 +30,12 @@ gdal_sitrep( Invisibly, a named list describing installation state. } \description{ -Reports bundle and build provenance, staleness, embedded-Python -provisioning, and common collision risks without changing the session. +Reports the installed GDAL runtime, the \code{gdalraster} build in the active +library, staleness against the newest \verb{gdal-v*} bundle, embedded-Python +provisioning, and session collision risks without changing the session. +} +\details{ +The default inspects \code{.libPaths()[1]}, the library used by +\code{library(gdalraster)}. Pass \code{lib} for a custom library, or \code{isolated = TRUE} +for the package-managed isolated library. } diff --git a/man/gdal_uninstall.Rd b/man/gdal_uninstall.Rd index be1d42b..d62c40d 100644 --- a/man/gdal_uninstall.Rd +++ b/man/gdal_uninstall.Rd @@ -6,7 +6,8 @@ \usage{ gdal_uninstall( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, runtime = TRUE, package = TRUE, python = TRUE, @@ -14,9 +15,14 @@ gdal_uninstall( ) } \arguments{ -\item{lib}{Library containing the managed \code{gdalraster} package.} +\item{lib}{Library containing the managed \code{gdalraster} package. Defaults to +\code{.libPaths()[1]}.} -\item{user_lib}{Use \code{.libPaths()[1]}.} +\item{isolated}{Remove the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{runtime}{Remove the GDAL build runtime.} diff --git a/man/gdal_update.Rd b/man/gdal_update.Rd index e37e56d..866abb7 100644 --- a/man/gdal_update.Rd +++ b/man/gdal_update.Rd @@ -6,7 +6,8 @@ \usage{ gdal_update( lib = NULL, - user_lib = FALSE, + isolated = FALSE, + user_lib = NULL, tag = "latest", local_zip = NULL, fallback_zip = NULL, @@ -16,9 +17,14 @@ gdal_update( ) } \arguments{ -\item{lib}{Destination library for \code{gdalraster}.} +\item{lib}{Destination library for \code{gdalraster}. Defaults to +\code{.libPaths()[1]}.} -\item{user_lib}{Use \code{.libPaths()[1]} instead of the isolated managed library.} +\item{isolated}{Install into the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{tag}{Runtime bundle release tag or \code{"latest"}.} diff --git a/man/gdal_verify.Rd b/man/gdal_verify.Rd index 0f8fe69..5ad2cd9 100644 --- a/man/gdal_verify.Rd +++ b/man/gdal_verify.Rd @@ -4,12 +4,23 @@ \alias{gdal_verify} \title{Verify the self-contained gdalraster installation} \usage{ -gdal_verify(lib = NULL, user_lib = FALSE, python = TRUE, quiet = FALSE) +gdal_verify( + lib = NULL, + isolated = FALSE, + user_lib = NULL, + python = TRUE, + quiet = FALSE +) } \arguments{ -\item{lib}{Library containing the managed \code{gdalraster} package.} +\item{lib}{Library containing the managed \code{gdalraster} package. Defaults to +\code{.libPaths()[1]}.} -\item{user_lib}{Use \code{.libPaths()[1]}.} +\item{isolated}{Verify the package-managed isolated library instead of +\code{.libPaths()[1]}. Ignored when \code{lib} is set.} + +\item{user_lib}{Deprecated. \code{user_lib = TRUE} is now the default; +\code{user_lib = FALSE} is equivalent to \code{isolated = TRUE}.} \item{python}{Run the embedded-Python validation when its managed \code{.pth} file is ready.} diff --git a/tests/testthat/helper-fixtures.R b/tests/testthat/helper-fixtures.R index 0ad07ea..9dc16f9 100644 --- a/tests/testthat/helper-fixtures.R +++ b/tests/testthat/helper-fixtures.R @@ -36,8 +36,20 @@ create_bundle_zip <- function(path, tag = "gdal-v9.9.1") { path } -release_fixture <- function(tag, assets = list(), draft = FALSE, prerelease = FALSE) { - list(tag_name = tag, draft = draft, prerelease = prerelease, assets = assets) +release_fixture <- function( + tag, + assets = list(), + draft = FALSE, + prerelease = FALSE, + published_at = NULL +) { + list( + tag_name = tag, + draft = draft, + prerelease = prerelease, + assets = assets, + published_at = published_at + ) } asset_fixture <- function(id, name, url) { diff --git a/tests/testthat/test-manifest-runtime.R b/tests/testthat/test-manifest-runtime.R index 28e91ef..a71f435 100644 --- a/tests/testthat/test-manifest-runtime.R +++ b/tests/testthat/test-manifest-runtime.R @@ -138,6 +138,54 @@ testthat::test_that("release selection ignores package and draft releases", { testthat::expect_identical(result$url, "winner") }) +testthat::test_that("release selection ignores package tags that still carry a bundle zip", { + releases <- list( + release_fixture( + "v0.3.1", + assets = list( + asset_fixture(1L, "gdal-ucrt64-v3.13.1-windows-x64.zip", "stale-package") + ), + published_at = "2026-07-04T01:43:56Z" + ), + release_fixture( + "gdal-v3.13.2", + assets = list( + asset_fixture(2L, "gdal-ucrt64-v3.13.2-windows-x64.zip", "bundle") + ), + published_at = "2026-08-09T05:13:21Z" + ) + ) + + result <- gdalraster.windows:::select_release_asset( + releases, + gdalraster.windows:::.bundle_asset_pattern + ) + testthat::expect_identical(result$tag, "gdal-v3.13.2") + testthat::expect_identical(result$url, "bundle") +}) + +testthat::test_that("release selection prefers the newest published gdal-v tag", { + releases <- list( + release_fixture( + "gdal-v9.9.0", + assets = list(asset_fixture(1L, "gdal-ucrt64-v9.9.0.zip", "older")), + published_at = "2026-01-01T00:00:00Z" + ), + release_fixture( + "gdal-v9.9.1", + assets = list(asset_fixture(2L, "gdal-ucrt64-v9.9.1.zip", "newer")), + published_at = "2026-06-01T00:00:00Z" + ) + ) + + result <- gdalraster.windows:::select_release_asset( + releases, + gdalraster.windows:::.bundle_asset_pattern + ) + testthat::expect_identical(result$tag, "gdal-v9.9.1") + testthat::expect_identical(result$url, "newer") +}) + testthat::test_that("stale runtime helpers preserve unrelated directories", { root <- withr::local_tempdir() home <- file.path(root, "gdal") diff --git a/tests/testthat/test-sitrep-api.R b/tests/testthat/test-sitrep-api.R index 9ca5e57..926ae88 100644 --- a/tests/testthat/test-sitrep-api.R +++ b/tests/testthat/test-sitrep-api.R @@ -11,8 +11,8 @@ testthat::test_that("sitrep classifies a current vendored installation", { testthat::local_mocked_bindings( managed_python_pth_files = function() character(), - path_gdal_dlls = function() character(), loaded_gdal_dlls = function() character(), + visible_gdalraster_dir = function() "", .env = asNamespace("gdalraster.windows") ) @@ -43,8 +43,8 @@ testthat::test_that("sitrep classifies a stale build", { testthat::local_mocked_bindings( managed_python_pth_files = function() character(), - path_gdal_dlls = function() character(), loaded_gdal_dlls = function() character(), + visible_gdalraster_dir = function() "", .env = asNamespace("gdalraster.windows") ) @@ -89,6 +89,164 @@ testthat::test_that("removed activation API is no longer exported", { ) }) +testthat::test_that("gdal_home is slash-normalized", { + home <- gdalraster.windows::gdal_home() + testthat::expect_false(grepl("\\\\", home)) + testthat::expect_identical( + home, + normalizePath(home, winslash = "/", mustWork = FALSE) + ) +}) + +testthat::test_that("library resolution defaults to .libPaths()[1]", { + testthat::expect_identical( + gdalraster.windows:::resolve_gdalraster_lib(), + normalizePath(.libPaths()[[1L]], winslash = "/", mustWork = FALSE) + ) +}) + +testthat::test_that("isolated library is opt-in", { + testthat::expect_identical( + gdalraster.windows:::resolve_gdalraster_lib(isolated = TRUE), + gdalraster.windows:::default_gdalraster_lib() + ) +}) + +testthat::test_that("explicit lib wins over isolated", { + lib <- normalizePath(withr::local_tempdir(), winslash = "/", mustWork = FALSE) + testthat::expect_identical( + gdalraster.windows:::resolve_gdalraster_lib(lib = lib, isolated = TRUE), + lib + ) +}) + +testthat::test_that("user_lib = FALSE still selects the isolated library", { + testthat::expect_identical( + gdalraster.windows:::resolve_gdalraster_lib(user_lib = FALSE), + gdalraster.windows:::default_gdalraster_lib() + ) +}) + +testthat::test_that("sitrep reports missing provenance instead of treating NA as a tag", { + home <- create_bundle_fixture(file.path(withr::local_tempdir(), "gdal")) + lib <- withr::local_tempdir() + dir.create(file.path(lib, "gdalraster")) + withr::local_options(gdalraster.windows.gdal_home = home) + + testthat::local_mocked_bindings( + managed_python_pth_files = function() character(), + loaded_gdal_dlls = function() character(), + visible_gdalraster_dir = function() "", + .env = asNamespace("gdalraster.windows") + ) + + state <- gdalraster.windows::gdal_sitrep( + lib = lib, + network = FALSE, + quiet = TRUE + ) + testthat::expect_true(state$gdalraster_installed) + testthat::expect_true(is.na(state$build_tag)) + testthat::expect_true(is.na(state$gdalraster_version)) + testthat::expect_false(state$build_current) + testthat::expect_identical( + gdalraster.windows:::gdalraster_status_label(state), + "installed (missing provenance)" + ) +}) + +testthat::test_that("sitrep reports the gdalraster package version, not the GDAL tag", { + home <- create_bundle_fixture(file.path(withr::local_tempdir(), "gdal")) + lib <- withr::local_tempdir() + package_dir <- file.path(lib, "gdalraster") + dir.create(package_dir) + writeLines( + c("Package: gdalraster", "Version: 2.6.1.9001"), + file.path(package_dir, "DESCRIPTION") + ) + gdalraster.windows:::write_manifest( + list(`Bundle-Tag` = "gdal-v9.9.1"), + gdalraster.windows:::build_manifest_path(package_dir) + ) + withr::local_options(gdalraster.windows.gdal_home = home) + + testthat::local_mocked_bindings( + managed_python_pth_files = function() character(), + loaded_gdal_dlls = function() character(), + visible_gdalraster_dir = function() "", + .env = asNamespace("gdalraster.windows") + ) + + state <- gdalraster.windows::gdal_sitrep( + lib = lib, + network = FALSE, + quiet = TRUE + ) + testthat::expect_identical(state$bundle_tag, "gdal-v9.9.1") + testthat::expect_identical(state$gdalraster_version, "2.6.1.9001") + testthat::expect_identical( + gdalraster.windows:::gdalraster_status_label(state), + "2.6.1.9001" + ) +}) + +testthat::test_that("sitrep points at a managed build visible on .libPaths()", { + home <- create_bundle_fixture(file.path(withr::local_tempdir(), "gdal")) + inspected_lib <- withr::local_tempdir() + dir.create(file.path(inspected_lib, "gdalraster")) + visible_dir <- file.path(withr::local_tempdir(), "gdalraster") + dir.create(visible_dir) + gdalraster.windows:::write_manifest( + list(`Bundle-Tag` = "gdal-v9.9.1"), + gdalraster.windows:::build_manifest_path(visible_dir) + ) + withr::local_options(gdalraster.windows.gdal_home = home) + + testthat::local_mocked_bindings( + managed_python_pth_files = function() character(), + loaded_gdal_dlls = function() character(), + visible_gdalraster_dir = function() { + normalizePath(visible_dir, winslash = "/", mustWork = TRUE) + }, + .env = asNamespace("gdalraster.windows") + ) + + state <- gdalraster.windows::gdal_sitrep( + lib = inspected_lib, + network = FALSE, + quiet = TRUE + ) + testthat::expect_true(state$foreign_gdalraster) + testthat::expect_true(state$visible_build_current) + testthat::expect_false(state$build_current) +}) + +testthat::test_that("path gdal scan ignores managed runtime and package DLLs", { + root <- withr::local_tempdir() + home <- file.path(root, "gdal") + package_dir <- file.path(root, "gdalraster") + other <- file.path(root, "other-gdal") + dir.create(file.path(home, "bin"), recursive = TRUE) + dir.create(file.path(package_dir, "libs", "x64"), recursive = TRUE) + dir.create(other) + writeLines("dll", file.path(home, "bin", "libgdal-39.dll")) + writeLines("dll", file.path(package_dir, "libs", "x64", "libgdal-39.dll")) + writeLines("dll", file.path(other, "libgdal-39.dll")) + + withr::local_path( + c( + normalizePath(file.path(home, "bin"), winslash = "/", mustWork = TRUE), + normalizePath(file.path(package_dir, "libs", "x64"), winslash = "/", mustWork = TRUE), + normalizePath(other, winslash = "/", mustWork = TRUE) + ), + action = "replace" + ) + + dlls <- gdalraster.windows:::path_gdal_dlls(exclude = c(home, package_dir)) + testthat::expect_length(dlls, 1L) + testthat::expect_true(gdalraster.windows:::path_is_under(dlls, other)) +}) + testthat::test_that("verification returns false when package is absent", { testthat::skip_if_not(.Platform$OS.type == "windows") testthat::expect_false( diff --git a/vignettes/architecture.qmd b/vignettes/architecture.qmd index 1ba3520..b733226 100644 --- a/vignettes/architecture.qmd +++ b/vignettes/architecture.qmd @@ -52,7 +52,7 @@ Another GDAL on `PATH` does not override the vendored DLL while `gdalraster.dll` is loading. The remaining process-level exception is an identically named GDAL DLL already loaded before `gdalraster`; Windows module resolution can reuse an existing loaded module by name. `gdal_sitrep()` reports -both competing `PATH` locations and loaded GDAL modules. +an already-loaded `libgdal` module. Command-line GDAL installations from pixi, conda, OSGeo4W, or MSYS2 remain independent. Their executables can coexist with the vendored R package. diff --git a/vignettes/getting-started.qmd b/vignettes/getting-started.qmd index 2f26f38..79713e4 100644 --- a/vignettes/getting-started.qmd +++ b/vignettes/getting-started.qmd @@ -30,34 +30,32 @@ variable is needed in later sessions. ## One-time setup -Install the package, then build into your regular user library when you want -plain `library(gdalraster)` in every later session: +Install the package, then build into your regular user library: ```{r} #| eval: false pak::pak("jimbrig/gdalraster.windows") -gdalraster.windows::gdal_setup(user_lib = TRUE) +gdalraster.windows::gdal_setup() ``` `gdal_setup()` prints one plan, installs or skips the runtime idempotently, builds and vendors `gdalraster`, provisions embedded Python when a system CPython is available, and verifies the result in fresh processes. -The package's non-destructive default is an isolated managed library: +Interactive sessions ask before replacing an existing `gdalraster` in the +destination library; non-interactive replacement requires `force = TRUE`. + +For a non-destructive isolated library: ```{r} #| eval: false -result <- gdalraster.windows::gdal_setup() +result <- gdalraster.windows::gdal_setup(isolated = TRUE) result$lib ``` -Use `user_lib = TRUE` explicitly to replace a package in `.libPaths()[1]`. -Interactive sessions ask before replacement; non-interactive replacement -requires explicit arguments. - ## Everyday use -After a user-library setup, `gdalraster.windows` does not need to be attached: +After setup, `gdalraster.windows` does not need to be attached: ```{r} #| eval: false @@ -65,7 +63,7 @@ library(gdalraster) gdalraster::gdal_global_reg_names() ``` -For an isolated install, provide its library location: +For an isolated install, load from that library: ```{r} #| eval: false @@ -82,8 +80,8 @@ library( ```{r} #| eval: false -gdalraster.windows::gdal_sitrep(user_lib = TRUE) -gdalraster.windows::gdal_verify(user_lib = TRUE) +gdalraster.windows::gdal_sitrep() +gdalraster.windows::gdal_verify() ``` `gdal_verify()` uses fresh `Rscript --vanilla` processes. It checks the @@ -95,7 +93,7 @@ Python provisioning is ready. ```{r} #| eval: false -gdalraster.windows::gdal_update(user_lib = TRUE) +gdalraster.windows::gdal_update() ``` The runtime and built package manifests let this operation distinguish a @@ -108,7 +106,6 @@ Download a bundle release asset on a connected machine, transfer it, then use: ```{r} #| eval: false gdalraster.windows::gdal_setup( - user_lib = TRUE, local_zip = "C:/Downloads/gdal-bundle-v3.13.2-windows-x64.zip" ) ``` diff --git a/vignettes/runtime-guide.qmd b/vignettes/runtime-guide.qmd index ddc5be4..f3f79f8 100644 --- a/vignettes/runtime-guide.qmd +++ b/vignettes/runtime-guide.qmd @@ -101,16 +101,16 @@ Python-specific check is reported as unavailable. gdalraster.windows::gdal_update() ``` -For a user-library installation: +An update replaces the SDK, rebuilds from source, re-vendors every runtime +component, re-points the managed `.pth`, and verifies in a fresh process. + +For an isolated installation: ```{r} #| eval: false -gdalraster.windows::gdal_update(user_lib = TRUE) +gdalraster.windows::gdal_update(isolated = TRUE) ``` -An update replaces the SDK, rebuilds from source, re-vendors every runtime -component, re-points the managed `.pth`, and verifies in a fresh process. - ## Uninstall ```{r} @@ -118,6 +118,6 @@ component, re-points the managed `.pth`, and verifies in a fresh process. gdalraster.windows::gdal_uninstall(force = TRUE) ``` -Set `user_lib = TRUE` only when the managed build was placed in the regular -user library. The uninstall removes the selected package, SDK, and managed -Python path file. +The uninstall removes the selected package from `.libPaths()[1]`, the SDK, and +the managed Python path file. Pass `isolated = TRUE` when the managed build +was placed in the isolated library. diff --git a/vignettes/troubleshooting.qmd b/vignettes/troubleshooting.qmd index 2b73cb6..5382520 100644 --- a/vignettes/troubleshooting.qmd +++ b/vignettes/troubleshooting.qmd @@ -10,23 +10,24 @@ vignette: > ```{r} #| eval: false -gdalraster.windows::gdal_sitrep(user_lib = TRUE) -gdalraster.windows::gdal_verify(user_lib = TRUE) +gdalraster.windows::gdal_sitrep() +gdalraster.windows::gdal_verify() ``` -Omit `user_lib = TRUE` for the default isolated installation. The sitrep -reports runtime and build manifests, staleness, Python readiness, competing -GDAL DLLs, already loaded modules, legacy profile hooks, and foreign -`gdalraster` packages. +The default inspects `.libPaths()[1]`. Pass `lib` for a custom library, or +`isolated = TRUE` for the package-managed isolated library. The sitrep +reports the GDAL runtime tag, build provenance, staleness, Python readiness, +already loaded `libgdal` modules, legacy profile hooks, and a foreign +`gdalraster` package when `library(gdalraster)` would load a different tree. ## `library(gdalraster)` cannot find the package -The non-destructive default installs into a package-managed isolated library. -Either load from that location or rebuild into the regular user library: +Rebuild into the regular user library, or load an isolated install from its +library: ```{r} #| eval: false -gdalraster.windows::gdal_setup(user_lib = TRUE) +gdalraster.windows::gdal_setup() library(gdalraster) ``` @@ -109,7 +110,7 @@ For a regular user-library build use: ```{r} #| eval: false -gdalraster.windows::gdal_enable_python(lib = .libPaths()[1]) +gdalraster.windows::gdal_enable_python() ``` When no system CPython is available, core GDAL functionality remains ready,