Skip to content

Commit

Permalink
Rtools: fall back to R CMD config, path, registry
Browse files Browse the repository at this point in the history
If we do not find Rtools44, Rtools43 or Rtools42 at
the usual places or where they should be, e.g. because
they were not installed from an installer, but from
.zst files.
  • Loading branch information
gaborcsardi committed Oct 28, 2024
1 parent d3a7f1a commit 79356bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgbuild (development version)

* pkgbuild now does a better job at finding Rtools 4.3 and 4.4 if they
were not installed from an installer.

# pkgbuild 1.4.4

* pkgbuild now supports R 4.4.x and Rtools44 (#183).
Expand Down
5 changes: 5 additions & 0 deletions R/rtools-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ version_info <- list(
),
"4.3" = list(
version_min = "4.3.0",
version_max = "4.3.99",
path = "usr/bin"
),
"4.4" = list(
version_min = "4.4.0",
version_max = "99.99.99",
path = "usr/bin"
),
Expand Down
4 changes: 4 additions & 0 deletions R/rtools-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ scan_path_for_rtools <- function(debug = FALSE) {

# We have a candidate install_path
install_path <- dirname(dirname(ls_path))
# ls is one more directory down on recent rtools
if (basename(install_path) == "usr") {
install_path <- dirname(install_path)
}

gcc_path <- Sys.which("gcc")
if (debug) {
Expand Down
29 changes: 14 additions & 15 deletions R/rtools.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ has_rtools <- function(debug = FALSE) {
rtools_path_set(rtools(rtools44_aarch64_home, "4.4"))
return(TRUE)
}
return(FALSE)
}

# R 4.4.0 or later
Expand All @@ -53,11 +52,11 @@ has_rtools <- function(debug = FALSE) {
rtools_path_set(rtools(rtools44_home, "4.4"))
return(TRUE)
}
return(FALSE)
}

# R 4.3.0 or later on ARM64
if (getRversion() >= "4.3.0" && grepl("aarch", R.version$platform)) {
if (getRversion() >= "4.3.0" && getRversion() < "4.4.0" &&
grepl("aarch", R.version$platform)) {
rtools43_aarch64_home <- Sys.getenv("RTOOLS43_AARCH64_HOME", "C:\rtools43-aarch64")
if (file.exists(file.path(rtools43_aarch64_home, "usr", "bin"))) {
if (debug) {
Expand All @@ -66,11 +65,10 @@ has_rtools <- function(debug = FALSE) {
rtools_path_set(rtools(rtools43_aarch64_home, "4.3"))
return(TRUE)
}
return(FALSE)
}

# R 4.3.0 or later
if (getRversion() >= "4.3.0") {
if (getRversion() >= "4.3.0" && getRversion() < "4.4.0") {
rtools43_home <- Sys.getenv("RTOOLS43_HOME", "C:\\rtools43")
if (file.exists(file.path(rtools43_home, "usr", "bin"))) {
if (debug) {
Expand All @@ -79,25 +77,26 @@ has_rtools <- function(debug = FALSE) {
rtools_path_set(rtools(rtools43_home, "4.3"))
return(TRUE)
}
return(FALSE)
}

# R 4.2.x or later and ucrt?
ucrt <- is_ucrt()
if (ucrt) {
rtools42_home <- Sys.getenv("RTOOLS42_HOME", "C:\\rtools42")
if (file.exists(file.path(rtools42_home, "usr", "bin"))) {
if (debug) {
cat("Found in Rtools 4.2 installation folder\n")
if (getRversion() >= "4.2.0" && getRversion() < "4.3.0") {
ucrt <- is_ucrt()
if (ucrt) {
rtools42_home <- Sys.getenv("RTOOLS42_HOME", "C:\\rtools42")
if (file.exists(file.path(rtools42_home, "usr", "bin"))) {
if (debug) {
cat("Found in Rtools 4.2 installation folder\n")
}
rtools_path_set(rtools(rtools42_home, "4.2"))
return(TRUE)
}
rtools_path_set(rtools(rtools42_home, "4.2"))
return(TRUE)
}
}

# In R 4.0 we can use RTOOLS40_HOME, recent versions of Rtools40 work fine
# with ucrt as well, currently.
if (is_R4()) {
if (getRversion() >= "4.0.0" && getRversion() < "4.3.0") {
rtools40_home <- Sys.getenv("RTOOLS40_HOME", "C:\\rtools40")
fld <- if (ucrt) "ucrt64" else "usr"
if (file.exists(file.path(rtools40_home, fld, "bin"))) {
Expand Down

0 comments on commit 79356bd

Please sign in to comment.