Skip to content

Commit

Permalink
Avoid overriding user defined Makevars files
Browse files Browse the repository at this point in the history
If a user has setup a Makevars file we should use the settings in that
directly rather than overriding them
  • Loading branch information
jimhester committed Sep 18, 2018
1 parent 1af9c61 commit 60162f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Development

* `compile_dll()` now does not supply compiler flags if there is an existing
user defined Makevars file.

* `local_build_tools()` function added to provide a deferred equivalent to
`with_build_tools()`. So you can add rtools to the PATH until the end of a
function body.
Expand Down
16 changes: 14 additions & 2 deletions R/compile-dll.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@ compile_dll <- function(path = ".", quiet = FALSE) {
install_dir <- tempfile("devtools_install_")
dir.create(install_dir)

withr::with_makevars(compiler_flags(TRUE), assignment = "+=", {
# If the user has a makevars file just use that
if (length(makevars_user()) > 0) {
install_min(
path,
dest = install_dir,
components = "libs",
args = if (needs_clean(path)) "--preclean",
quiet = quiet
)
})
} else {
# Otherwise set makevars for fast development / debugging
withr::with_makevars(compiler_flags(TRUE), assignment = "+=", {
install_min(
path,
dest = install_dir,
components = "libs",
args = if (needs_clean(path)) "--preclean",
quiet = quiet
)
})
}

invisible(dll_path(file.path(install_dir, pkg_name(path))))
}
Expand Down
29 changes: 29 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,32 @@ is_windows <- function() {
is_dir <- function(x) {
isTRUE(file.info(x)$isdir)
}

# This is tools::makevars_user, provided here for backwards compatibility with older versions of R
makevars_user <- function () {
m <- character()
if (.Platform$OS.type == "windows") {
if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) {
if (file.exists(f))
m <- f
}
else if ((Sys.getenv("R_ARCH") == "/x64") && file.exists(f <- path.expand("~/.R/Makevars.win64")))
m <- f
else if (file.exists(f <- path.expand("~/.R/Makevars.win")))
m <- f
else if (file.exists(f <- path.expand("~/.R/Makevars")))
m <- f
}
else {
if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) {
if (file.exists(f))
m <- f
}
else if (file.exists(f <- path.expand(paste0("~/.R/Makevars-",
Sys.getenv("R_PLATFORM")))))
m <- f
else if (file.exists(f <- path.expand("~/.R/Makevars")))
m <- f
}
m
}

0 comments on commit 60162f8

Please sign in to comment.