| 1 |
|
| 2 |
renv_equip_macos_specs <- function() { |
| 3 |
|
| 4 |
list( |
| 5 |
|
| 6 |
"4.0" = list( |
| 7 |
url = "https://cran.r-project.org/bin/macosx/tools/clang-8.0.0.pkg", |
| 8 |
dst = "/usr/local/clang8" |
| 9 |
), |
| 10 |
|
| 11 |
"3.7" = list( |
| 12 |
url = "https://cran.r-project.org/bin/macosx/tools/clang-8.0.0.pkg", |
| 13 |
dst = "/usr/local/clang8" |
| 14 |
), |
| 15 |
|
| 16 |
"3.6" = list( |
| 17 |
url = "https://cran.r-project.org/bin/macosx/tools/clang-7.0.0.pkg", |
| 18 |
dst = "/usr/local/clang7" |
| 19 |
), |
| 20 |
|
| 21 |
"3.5" = list( |
| 22 |
url = "https://cran.r-project.org/bin/macosx/tools/clang-6.0.0.pkg", |
| 23 |
dst = "/usr/local/clang6" |
| 24 |
) |
| 25 |
|
| 26 |
) |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
renv_equip_macos_spec <- function(version = getRversion()) { |
| 31 |
renv_equip_macos_specs()[[renv_version_maj_min(version)]] |
| 32 |
} |
| 33 |
|
| 34 |
renv_equip_macos <- function() { |
| 35 |
|
| 36 |
renv_equip_macos_sdk() |
| 37 |
renv_equip_macos_toolchain() |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
renv_equip_macos_sdk <- function() { |
| 42 |
|
| 43 |
sdk <- "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" |
| 44 |
if (file.exists(sdk) || file.exists("/usr/include")) |
| 45 |
return(TRUE) |
| 46 |
|
| 47 |
system("/usr/bin/xcode-select --install") |
| 48 |
|
| 49 |
# give the user some time to respond to the dialog) |
| 50 |
Sys.sleep(5) |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
renv_equip_macos_toolchain <- function() { |
| 55 |
|
| 56 |
if (getRversion() >= "4.1.0") |
| 57 |
return() |
| 58 |
|
| 59 |
spec <- renv_equip_macos_spec() |
| 60 |
if (is.null(spec)) { |
| 61 |
fmt <- "no known toolchain recorded in renv for R %s" |
| 62 |
warningf(fmt, getRversion()) |
| 63 |
return(FALSE) |
| 64 |
} |
| 65 |
|
| 66 |
url <- spec$url |
| 67 |
dst <- spec$dst |
| 68 |
|
| 69 |
clang <- file.path(dst, "bin/clang") |
| 70 |
if (file.exists(clang)) { |
| 71 |
fmt <- "- LLVM toolchain for R %s is already installed at %s." |
| 72 |
writef(fmt, getRversion(), dQuote(dst)) |
| 73 |
return(TRUE) |
| 74 |
} |
| 75 |
|
| 76 |
destfile <- file.path(tempdir(), basename(url)) |
| 77 |
download(url, destfile = destfile) |
| 78 |
|
| 79 |
if (renv_equip_macos_rstudio(spec, destfile)) |
| 80 |
return(TRUE) |
| 81 |
|
| 82 |
command <- paste("sudo /usr/sbin/installer -pkg", shQuote(destfile), "-target /") |
| 83 |
bulletin( |
| 84 |
"The R LLVM toolchain has been successfully downloaded. Please execute:", |
| 85 |
command, |
| 86 |
"in a separate terminal to complete installation." |
| 87 |
) |
| 88 |
|
| 89 |
TRUE |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
renv_equip_macos_rstudio <- function(spec, destfile) { |
| 94 |
|
| 95 |
rstudio <- |
| 96 |
renv_rstudio_available() && |
| 97 |
requireNamespace("rstudioapi", quietly = TRUE) |
| 98 |
|
| 99 |
if (!rstudio) |
| 100 |
return(FALSE) |
| 101 |
|
| 102 |
command <- paste("sudo -kS /usr/sbin/installer -pkg", shQuote(destfile), "-target /") |
| 103 |
prompt <- paste( |
| 104 |
"Installation of the R LLVM toolchain requires sudo.", |
| 105 |
"Please enter your account password.", |
| 106 |
sep = "\n" |
| 107 |
) |
| 108 |
|
| 109 |
installed <- local({ |
| 110 |
|
| 111 |
password <- rstudioapi::askForPassword(prompt) |
| 112 |
if (is.null(password)) |
| 113 |
return(FALSE) |
| 114 |
|
| 115 |
status <- system(command, input = password) |
| 116 |
if (status != 0L) |
| 117 |
return(FALSE) |
| 118 |
|
| 119 |
TRUE |
| 120 |
|
| 121 |
}) |
| 122 |
|
| 123 |
if (!installed) |
| 124 |
return(FALSE) |
| 125 |
|
| 126 |
bulletin( |
| 127 |
"The R LLVM toolchain has been downloaded and installed to:", |
| 128 |
spec$dst, |
| 129 |
"This toolchain will be used by renv when installing packages from source." |
| 130 |
) |
| 131 |
|
| 132 |
return(TRUE) |
| 133 |
|
| 134 |
} |