| 1 |
|
| 2 |
renv_rtools_list <- function() { |
| 3 |
|
| 4 |
drive <- Sys.getenv("SYSTEMDRIVE", unset = "C:") |
| 5 |
|
| 6 |
roots <- c( |
| 7 |
|
| 8 |
renv_rtools_registry(), |
| 9 |
|
| 10 |
Sys.getenv("RTOOLS45_HOME", unset = file.path(drive, "rtools45")), |
| 11 |
Sys.getenv("RTOOLS44_HOME", unset = file.path(drive, "rtools44")), |
| 12 |
Sys.getenv("RTOOLS43_HOME", unset = file.path(drive, "rtools43")), |
| 13 |
Sys.getenv("RTOOLS42_HOME", unset = file.path(drive, "rtools42")), |
| 14 |
Sys.getenv("RTOOLS40_HOME", unset = file.path(drive, "rtools40")), |
| 15 |
file.path(drive, "Rtools"), |
| 16 |
list.files(file.path(drive, "RBuildTools"), full.names = TRUE), |
| 17 |
|
| 18 |
"~/Rtools", |
| 19 |
list.files("~/RBuildTools", full.names = TRUE) |
| 20 |
|
| 21 |
) |
| 22 |
|
| 23 |
roots <- unique(roots[file.exists(roots)]) |
| 24 |
lapply(roots, renv_rtools_read) |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
renv_rtools_find <- function() { |
| 29 |
|
| 30 |
for (spec in renv_rtools_list()) |
| 31 |
if (renv_rtools_compatible(spec)) |
| 32 |
return(spec) |
| 33 |
|
| 34 |
NULL |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
renv_rtools_read <- function(root) { |
| 39 |
|
| 40 |
list( |
| 41 |
root = root, |
| 42 |
version = renv_rtools_version(root) |
| 43 |
) |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
renv_rtools_version <- function(root) { |
| 48 |
|
| 49 |
name <- basename(root) |
| 50 |
|
| 51 |
# check for 'rtools<xyz>' folder |
| 52 |
# e.g. C:/rtools42 |
| 53 |
pattern <- "^rtools(\\d)(\\d)$" |
| 54 |
if (grepl(pattern, name, perl = TRUE, ignore.case = TRUE)) |
| 55 |
return(gsub(pattern, "\\1.\\2", name, perl = TRUE, ignore.case = TRUE)) |
| 56 |
|
| 57 |
# check for versioned installation path |
| 58 |
# e.g. C:/RBuildTools/4.2 |
| 59 |
version <- catch(numeric_version(name)) |
| 60 |
if (!inherits(version, "error")) |
| 61 |
return(format(version)) |
| 62 |
|
| 63 |
# detect older Rtools installations |
| 64 |
path <- file.path(root, "VERSION.txt") |
| 65 |
if (!file.exists(path)) |
| 66 |
return(NULL) |
| 67 |
|
| 68 |
contents <- readLines(path, warn = FALSE) |
| 69 |
version <- gsub("[^[:digit:].]", "", contents) |
| 70 |
numeric_version(version) |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
renv_rtools_compatible <- function(spec) { |
| 75 |
|
| 76 |
if (is.null(spec$version)) |
| 77 |
return(FALSE) |
| 78 |
|
| 79 |
ranges <- list( |
| 80 |
"4.5" = c("4.5.0", "9.9.9"), |
| 81 |
"4.4" = c("4.4.0", "9.9.9"), |
| 82 |
"4.3" = c("4.3.0", "4.4.0"), |
| 83 |
"4.2" = c("4.2.0", "4.3.0"), |
| 84 |
"4.0" = c("4.0.0", "4.2.0"), |
| 85 |
"3.5" = c("3.3.0", "4.0.0"), |
| 86 |
"3.4" = c("3.3.0", "4.0.0"), |
| 87 |
"3.3" = c("3.2.0", "3.3.0"), |
| 88 |
"3.2" = c("3.1.0", "3.2.0"), |
| 89 |
"3.1" = c("3.0.0", "3.1.0") |
| 90 |
) |
| 91 |
|
| 92 |
version <- numeric_version(spec$version)[1, 1:2] |
| 93 |
range <- ranges[[format(version)]] |
| 94 |
if (is.null(range)) |
| 95 |
return(FALSE) |
| 96 |
|
| 97 |
rversion <- getRversion() |
| 98 |
range[[1]] <= rversion && rversion < range[[2]] |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
renv_rtools_registry <- function() { |
| 103 |
|
| 104 |
status <- tryCatch( |
| 105 |
utils::readRegistry( |
| 106 |
key = "SOFTWARE\\R-Core\\Rtools", |
| 107 |
hive = "HLM" |
| 108 |
), |
| 109 |
error = function(e) list() |
| 110 |
) |
| 111 |
|
| 112 |
path <- status$InstallPath %||% "" |
| 113 |
if (file.exists(path)) |
| 114 |
return(renv_path_normalize(path)) |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
renv_rtools_envvars <- function(root) { |
| 119 |
|
| 120 |
version <- renv_rtools_version(root) |
| 121 |
|
| 122 |
if (version < "4.0") |
| 123 |
renv_rtools_envvars_default(root) |
| 124 |
else if (version < "4.2") |
| 125 |
renv_rtools_envvars_rtools40(root) |
| 126 |
else if (version < "4.3") |
| 127 |
renv_rtools_envvars_rtools42(root) |
| 128 |
else if (version < "4.4") |
| 129 |
renv_rtools_envvars_rtools43(root) |
| 130 |
else |
| 131 |
renv_rtools_envvars_default(root) |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
renv_rtools_envvars_default <- function(root) { |
| 136 |
|
| 137 |
# add Rtools utilities to path |
| 138 |
bin <- normalizePath(file.path(root, "usr/bin"), mustWork = FALSE) |
| 139 |
path <- paste(bin, Sys.getenv("PATH"), sep = .Platform$path.sep) |
| 140 |
|
| 141 |
# set BINPREF |
| 142 |
binpref <- "" |
| 143 |
|
| 144 |
list(PATH = path, BINPREF = binpref) |
| 145 |
|
| 146 |
} |
| 147 |
|
| 148 |
renv_rtools_envvars_rtools43 <- function(root) { |
| 149 |
|
| 150 |
# add Rtools utilities to path |
| 151 |
bin <- normalizePath(file.path(root, "usr/bin"), mustWork = FALSE) |
| 152 |
path <- paste(bin, Sys.getenv("PATH"), sep = .Platform$path.sep) |
| 153 |
|
| 154 |
# set BINPREF |
| 155 |
binpref <- "" |
| 156 |
|
| 157 |
list(PATH = path, BINPREF = binpref) |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
renv_rtools_envvars_rtools42 <- function(root) { |
| 162 |
|
| 163 |
# add Rtools utilities to path |
| 164 |
bin <- normalizePath(file.path(root, "usr/bin"), mustWork = FALSE) |
| 165 |
|
| 166 |
path <- paste(bin, Sys.getenv("PATH"), sep = .Platform$path.sep) |
| 167 |
|
| 168 |
# set BINPREF |
| 169 |
binpref <- "" |
| 170 |
|
| 171 |
list(PATH = path, BINPREF = binpref) |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
renv_rtools_envvars_rtools40 <- function(root) { |
| 176 |
|
| 177 |
# add Rtools utilities to path |
| 178 |
bin <- normalizePath(file.path(root, "usr/bin"), mustWork = FALSE) |
| 179 |
path <- paste(bin, Sys.getenv("PATH"), sep = .Platform$path.sep) |
| 180 |
|
| 181 |
# set BINPREF (note: trailing slash is required) |
| 182 |
binpref <- "/mingw$(WIN)/bin/" |
| 183 |
|
| 184 |
list(PATH = path, BINPREF = binpref) |
| 185 |
|
| 186 |
} |