@@ -10,72 +10,22 @@ is_linux <- function() {
1010 tolower(Sys.info()[[" sysname" ]]) == " linux"
1111}
1212
13- # Predicate whether currently running on R compiled with clang.
14- is_using_clang <- function () {
15- grepl(" clang" , R_compiled_by()[" C" ])
16- }
17-
18- # A `data.frame` giving default clang versions for each OS version of the
19- # Fedora Linux distribution.
20- # Source: https://packages.fedoraproject.org/pkgs/clang/clang/
21- # See Updates section for older Fedora versions.
22- fedora_clang_defaults <- data.frame (
23- os = as.integer(c(36 , 37 , 38 , 39 , 40 )),
24- clang = as.integer(c(14 , 15 , 16 , 17 , 17 ))
25- )
26-
27- # A `data.frame` giving default clang versions for each OS version of the
28- # Debian Linux distribution.
29- # Source: https://packages.debian.org/search?keywords=clang
30- debian_clang_defaults <- data.frame (
31- os = c(" bullseye" , " bookworm" , " trixie" ),
32- clang = as.integer(c(11 , 14 , 16 ))
33- )
34-
35- # Parse the major clang version as integer (e.g. 17) from
36- # the full clang string (e.g. "Debian clang version 17.0.6 (3)")
37- parse_clang_major <- function (clang_string ) {
38- assert_string(clang_string , pattern = " clang" )
39- clang_version <- gsub(pattern = " [^0-9.]" , replacement = " " , x = clang_string )
40- as.integer(gsub(pattern = " ([0-9]+).+" , replacement = " \\ 1" , x = clang_version ))
13+ # Get the compiler information. Workaround for older R versions
14+ # where R_compiled_by() is not available.
15+ get_compiler <- function () {
16+ r_cmd <- file.path(R.home(" bin" ), " R" )
17+ system2(r_cmd , args = " CMD config CC" , stdout = TRUE )
4118}
4219
43- # Predicate whether a non-standard clang version is used, specifically
44- # a higher than default clang version. Assumes that clang is used, otherwise fails.
45- # If not Fedora or Debian of the known versions are used, always returns `FALSE`.
46- is_non_standard_clang <- function (os_string ,
47- clang_major_version ) {
48- assert_string(os_string )
49- assert_int(clang_major_version )
50- if (grepl(" Fedora" , os_string )) {
51- os_version <- as.integer(gsub(pattern = " [^0-9]" , replacement = " " , x = os_string ))
52- assert_int(os_version )
53- which_os <- match(os_version , fedora_clang_defaults $ os )
54- if (is.na(which_os )) {
55- return (FALSE )
56- }
57- clang_major_version > fedora_clang_defaults $ clang [which_os ]
58- } else if (grepl(" Debian" , os_string )) {
59- os_codename <- gsub(pattern = " Debian GNU/Linux ([a-z]+)/*[a-z]*" , replacement = " \\ 1" , x = os_string )
60- assert_string(os_codename )
61- which_os <- match(os_codename , debian_clang_defaults $ os )
62- if (is.na(which_os )) {
63- return (FALSE )
64- }
65- clang_major_version > debian_clang_defaults $ clang [which_os ]
66- } else {
67- FALSE
68- }
20+ # Predicate whether currently using a clang compiler.
21+ is_using_clang <- function () {
22+ grepl(" clang" , get_compiler())
6923}
7024
7125# Predicate whether an R-devel version is running on Linux Fedora or
72- # Debian with a non-standard clang compiler.
26+ # Debian with a clang compiler.
7327is_r_devel_linux_clang <- function () {
7428 is_r_devel() &&
7529 is_linux() &&
76- is_using_clang() &&
77- is_non_standard_clang(
78- os_string = utils :: osVersion ,
79- clang_major_version = parse_clang_major(R_compiled_by()[" C" ])
80- )
30+ is_using_clang()
8131}
0 commit comments