From 3e31f398809bb73a03b61ceb995e326ef4297ae2 Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Thu, 15 Oct 2020 13:19:25 -0400 Subject: [PATCH] Enable colored compiler diagnostics with the background process as well (#102) --- NEWS.md | 2 ++ R/build-bg.R | 16 +++++++++++++--- R/build.R | 1 + R/with-debug.R | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 15d3ee9..baa548a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pkgbuild (development version) +* `pkgbuild_process()` and `build()` now use colored compiler diagnostics if supported (#102) + # pkgbuild 1.1.0 * `compile_dll()` now supports automatic cpp11 registration if the package links to cpp11. diff --git a/R/build-bg.R b/R/build-bg.R index 74dfa0b..f4ec98f 100644 --- a/R/build-bg.R +++ b/R/build-bg.R @@ -57,7 +57,10 @@ pkgbuild_process <- R6Class( manual, clean_doc, args, needs_compilation, compile_attributes, register_routines), - finalize = function() super$kill(), + finalize = function() { + unlink(private$makevars_file) + super$kill() + }, is_incomplete_error = function() FALSE, read_all_error = function() "", @@ -83,14 +86,18 @@ pkgbuild_process <- R6Class( private$out_file }, - kill = function(...) super$kill(...) + kill = function(...) { + unlink(private$makevars_file) + super$kill(...) + } ), private = list( path = NULL, dest_path = NULL, out_dir = NULL, - out_file = NULL + out_file = NULL, + makevars_file = NULL ) ) @@ -107,9 +114,12 @@ rcb_init <- function(self, private, super, path, dest_path, binary, private$path <- options$path private$dest_path <- options$dest_path private$out_dir <- options$out_dir + private$makevars_file <- tempfile() ## Build tools already checked in setup + withr::set_makevars(compiler_flags(debug = FALSE), new_path = private$makevars_file, assignment = "+=") + withr::local_envvar("R_MAKEVARS_USER" = private$makevars_file) options <- rcmd_process_options( cmd = options$cmd, cmdargs = c(options$path, options$args), diff --git a/R/build.R b/R/build.R index 14f7520..ca25864 100644 --- a/R/build.R +++ b/R/build.R @@ -45,6 +45,7 @@ build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE needs_compilation, compile_attributes, register_routines, quiet) on.exit(unlink(options$out_dir, recursive = TRUE), add = TRUE) + withr::local_makevars(compiler_flags(debug = FALSE), .assignment = "+=") withr::with_temp_libpaths( rcmd_build_tools( options$cmd, diff --git a/R/with-debug.R b/R/with-debug.R index 96ccaaf..749ab64 100644 --- a/R/with-debug.R +++ b/R/with-debug.R @@ -43,7 +43,7 @@ without_compiler <- function(code) { flags <- c( CC = "test", CXX = "test", - CXX1X = "test", + CXX11 = "test", FC = "test" )