Skip to content

Commit 3cc8e66

Browse files
authored
add systemFile() helper for arch-aware package paths (#251)
Consolidates the four places that constructed paths within the installed package while accounting for the architecture-specific subdirectory used on Windows (e.g. 'lib/x64').
1 parent d65bcd4 commit 3cc8e66

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

R/tbb.R

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ tbbLibraryPath <- function(name = NULL) {
4141
tbbName <- file.path(tbbRoot, libName)
4242
if (file.exists(tbbName))
4343
return(tbbName)
44-
45-
arch <- if (nzchar(.Platform$r_arch)) .Platform$r_arch
46-
suffix <- paste(c("lib", arch, libName), collapse = "/")
47-
tbbName <- system.file(suffix, package = "RcppParallel")
44+
45+
tbbName <- systemFile("lib", libName)
4846
if (file.exists(tbbName))
4947
return(tbbName)
5048

@@ -90,10 +88,8 @@ tbbLdFlags <- function() {
9088
# on Windows, we statically link to oneTBB
9189
if (is_windows()) {
9290

93-
libPath <- system.file("libs", package = "RcppParallel")
94-
if (nzchar(.Platform$r_arch))
95-
libPath <- file.path(libPath, .Platform$r_arch)
96-
91+
libPath <- systemFile("libs")
92+
9793
ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath))
9894
return(ldFlags)
9995

@@ -127,9 +123,6 @@ tbbRoot <- function() {
127123
if (nzchar(TBB_LIB))
128124
return(TBB_LIB)
129125

130-
rArch <- .Platform$r_arch
131-
parts <- c("lib", if (nzchar(rArch)) rArch)
132-
libDir <- paste(parts, collapse = "/")
133-
system.file(libDir, package = "RcppParallel")
126+
systemFile("lib")
134127

135128
}

R/utils.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
# like system.file(), but injects the architecture-specific subdirectory
3+
# used on Windows when set; e.g. systemFile("lib") resolves 'lib/x64'
4+
systemFile <- function(dir, name = NULL) {
5+
arch <- .Platform$r_arch
6+
parts <- c(dir, if (nzchar(arch)) arch, name)
7+
system.file(paste(parts, collapse = "/"), package = "RcppParallel")
8+
}
9+
210
# generate paths consumable by the compilers and linkers
311
# in particular, on Windows and Solaris, this means the path _cannot_ be quoted !!
412
asBuildPath <- function(path) {

R/zzz.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ loadTbbLibrary <- function(name) {
2323
# NOTE: resolve against the package's own library directory, where
2424
# install.libs.R places the stub; tbbRoot() would prefer TBB_LIB,
2525
# which on Windows points at Rtools and holds only static libraries
26-
arch <- .Platform$r_arch
27-
parts <- c("lib", if (nzchar(arch)) arch, paste0(name, ".dll"))
28-
path <- system.file(paste(parts, collapse = "/"), package = "RcppParallel")
26+
path <- systemFile("lib", paste0(name, ".dll"))
2927
if (!file.exists(path))
3028
return(NULL)
3129

0 commit comments

Comments
 (0)