diff --git a/NEWS.md b/NEWS.md index a0a3f7f..4891588 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/compile-dll.R b/R/compile-dll.R index dbd211f..ae6d7e6 100644 --- a/R/compile-dll.R +++ b/R/compile-dll.R @@ -31,7 +31,8 @@ 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, @@ -39,7 +40,18 @@ compile_dll <- function(path = ".", quiet = FALSE) { 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)))) } diff --git a/R/utils.R b/R/utils.R index aa215de..f82e7fe 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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 +}