Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
^docs$
^pkgdown$
^dev-lib$
^[\.]?air\.toml$
^\.vscode$
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check.yaml

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage.yaml

Expand Down Expand Up @@ -35,14 +34,16 @@ jobs:
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./cobertura.xml
plugins: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
}
}
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Jim", "Hester", role = "aut"),
person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("aut", "cre")),
person("Posit Software, PBC", role = c("cph", "fnd"))
person("Posit Software, PBC", role = c("cph", "fnd"),
comment = c(ROR = "03wc8by49"))
)
Description: Provides functions used to build R packages. Locates
compilers needed to build R packages on various platforms and ensures
Expand All @@ -31,6 +32,7 @@ Suggests:
withr (>= 2.3.0)
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Config/usethis/last-upkeep: 2025-04-30
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2023
YEAR: 2025
COPYRIGHT HOLDER: pkgbuild authors
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 pkgbuild authors
Copyright (c) 2025 pkgbuild authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
76 changes: 60 additions & 16 deletions R/build-bg.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,34 @@ pkgbuild_process <- R6Class(
"pkgbuild_process",
inherit = callr::rcmd_process,
public = list(
initialize = function(path = ".", dest_path = NULL, binary = FALSE,
vignettes = TRUE, manual = FALSE, clean_doc = NULL,
args = NULL, needs_compilation = pkg_has_src(path),
compile_attributes = FALSE,
register_routines = FALSE, quiet = FALSE) {
initialize = function(
path = ".",
dest_path = NULL,
binary = FALSE,
vignettes = TRUE,
manual = FALSE,
clean_doc = NULL,
args = NULL,
needs_compilation = pkg_has_src(path),
compile_attributes = FALSE,
register_routines = FALSE,
quiet = FALSE
) {
rcb_init(
self, private, super, path, dest_path, binary, vignettes,
manual, clean_doc, args, needs_compilation, compile_attributes,
register_routines, quiet
self,
private,
super,
path,
dest_path,
binary,
vignettes,
manual,
clean_doc,
args,
needs_compilation,
compile_attributes,
register_routines,
quiet
)
},
is_incomplete_error = function() FALSE,
Expand Down Expand Up @@ -98,13 +117,34 @@ pkgbuild_process <- R6Class(
)
)

rcb_init <- function(self, private, super, path, dest_path, binary,
vignettes, manual, clean_doc, args, needs_compilation,
compile_attributes, register_routines, quiet) {
rcb_init <- function(
self,
private,
super,
path,
dest_path,
binary,
vignettes,
manual,
clean_doc,
args,
needs_compilation,
compile_attributes,
register_routines,
quiet
) {
options <- build_setup(
path, dest_path, binary, vignettes, manual, clean_doc,
args, needs_compilation, compile_attributes,
register_routines, quiet
path,
dest_path,
binary,
vignettes,
manual,
clean_doc,
args,
needs_compilation,
compile_attributes,
register_routines,
quiet
)

private$path <- options$path
Expand All @@ -114,9 +154,13 @@ rcb_init <- function(self, private, super, path, dest_path, binary,

## Build tools already checked in setup

withr_set_makevars(compiler_flags(debug = FALSE), new_path = private$makevars_file)
withr_set_makevars(
compiler_flags(debug = FALSE),
new_path = private$makevars_file
)
withr_with_envvar(
c("R_MAKEVARS_USER" = private$makevars_file), {
c("R_MAKEVARS_USER" = private$makevars_file),
{
options <- callr::rcmd_process_options(
cmd = options$cmd,
cmdargs = c(options$path, options$args),
Expand Down
11 changes: 9 additions & 2 deletions R/build-tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"WARNING: Rtools is required to build R packages, but is not ",
"currently installed.\n\n",
"Please download and install the appropriate version of Rtools for ",
getRversion(), " from\n", rtools_url(), "."
getRversion(),
" from\n",
rtools_url(),
"."

Check warning on line 51 in R/build-tools.R

View check run for this annotation

Codecov / codecov/patch

R/build-tools.R#L48-L51

Added lines #L48 - L51 were not covered by tests
)
}

Expand Down Expand Up @@ -90,7 +93,11 @@
#' @rdname has_build_tools
#' @param .local_envir The environment to use for scoping.
#' @export
local_build_tools <- function(debug = FALSE, required = TRUE, .local_envir = parent.frame()) {
local_build_tools <- function(
debug = FALSE,
required = TRUE,
.local_envir = parent.frame()
) {
if (required) {
check_build_tools(debug = debug, quiet = TRUE)
}
Expand Down
89 changes: 71 additions & 18 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,37 @@
#' @export
#' @return a string giving the location (including file name) of the built
#' package
build <- function(path = ".", dest_path = NULL, binary = FALSE, vignettes = TRUE,
manual = FALSE, clean_doc = NULL, args = NULL, quiet = FALSE,
needs_compilation = pkg_has_src(path), compile_attributes = FALSE,
register_routines = FALSE) {
build <- function(
path = ".",
dest_path = NULL,
binary = FALSE,
vignettes = TRUE,
manual = FALSE,
clean_doc = NULL,
args = NULL,
quiet = FALSE,
needs_compilation = pkg_has_src(path),
compile_attributes = FALSE,
register_routines = FALSE
) {
options <- build_setup(
path, dest_path, binary, vignettes, manual, clean_doc, args,
needs_compilation, compile_attributes, register_routines, quiet
path,
dest_path,
binary,
vignettes,
manual,
clean_doc,
args,
needs_compilation,
compile_attributes,
register_routines,
quiet
)
on.exit(unlink(options$out_dir, recursive = TRUE), add = TRUE)

withr_with_makevars(
compiler_flags(debug = FALSE), {
compiler_flags(debug = FALSE),
{
output <- withr_with_temp_libpaths(
rcmd_build_tools(
options$cmd,
Expand All @@ -132,10 +151,13 @@
)
)

if (should_stop_for_warnings() &&
grepl("\n\\s*warning:", output$stdout, ignore.case = TRUE)) {
if (
should_stop_for_warnings() &&
grepl("\n\\s*warning:", output$stdout, ignore.case = TRUE)
) {
cli::cli_alert_warning(
"Stopping as requested for a warning during {.code R CMD build}.")
"Stopping as requested for a warning during {.code R CMD build}."
)
if (quiet) {
cli::cli_alert_warning("The full output is printed below.")
cli::cli_verbatim(output$stdout)
Expand All @@ -145,7 +167,8 @@

out_file <- dir(options$out_dir)
file.copy(
file.path(options$out_dir, out_file), options$dest_path,
file.path(options$out_dir, out_file),
options$dest_path,
overwrite = TRUE
)

Expand All @@ -158,15 +181,29 @@
)
}

build_setup <- function(path, dest_path, binary, vignettes, manual, clean_doc, args,
needs_compilation, compile_attributes, register_routines, quiet) {
build_setup <- function(
path,
dest_path,
binary,
vignettes,
manual,
clean_doc,
args,
needs_compilation,
compile_attributes,
register_routines,
quiet
) {
if (!file.exists(path)) {
stop("`path` must exist", call. = FALSE)
}
if (!is_dir(path)) {
if (!binary) stop("`binary` must be TRUE for package files", call. = FALSE)
if (compile_attributes) {
stop("`compile_attributes` must be FALSE for package files", call. = FALSE)
stop(
"`compile_attributes` must be FALSE for package files",
call. = FALSE
)
}
if (register_routines) {
stop("`register_routines` must be FALSE for package files", call. = FALSE)
Expand Down Expand Up @@ -200,7 +237,12 @@
build_setup_binary(path, dest_path, args, needs_compilation)
} else {
build_setup_source(
path, dest_path, vignettes, manual, clean_doc, args,
path,
dest_path,
vignettes,
manual,
clean_doc,
args,
needs_compilation
)
}
Expand All @@ -224,8 +266,15 @@
)
}

build_setup_source <- function(path, dest_path, vignettes, manual, clean_doc,
args, needs_compilation) {
build_setup_source <- function(
path,
dest_path,
vignettes,
manual,
clean_doc,
args,
needs_compilation
) {
if (!("--resave-data" %in% args)) {
args <- c(args, "--no-resave-data")
}
Expand Down Expand Up @@ -256,7 +305,11 @@
doc_dir <- file.path(path, "inst", "doc")
if (dir.exists(doc_dir)) {
if (is.null(clean_doc) && interactive()) {
message("Building the package will delete...\n '", doc_dir, "'\nAre you sure?")
message(
"Building the package will delete...\n '",
doc_dir,
"'\nAre you sure?"
)

Check warning on line 312 in R/build.R

View check run for this annotation

Codecov / codecov/patch

R/build.R#L308-L312

Added lines #L308 - L312 were not covered by tests
res <- utils::menu(c("Yes", "No"))
if (res == 2) {
return()
Expand Down
Loading