11# !/usr/bin/env Rscript
2+ if (! requireNamespace(" revdepcheck" )) {
3+ stop(' Install revdepcheck: remotes::install_github("r-lib/revdepcheck")' )
4+ }
25library(" revdepcheck" )
36options(warn = 1L )
47
@@ -96,38 +99,69 @@ revdep_children <- local({
9699 }
97100})
98101
99- revdep_pkgs_with_status <- function (status = " error" ) {
102+ revdep_pkgs_with_status <- function (status = c( " error" , " failure " ) ) {
100103 status <- match.arg(status )
101104 res <- revdepcheck :: revdep_summary()
102- field <- switch (status , error = " errors" )
103- has_status <- vapply(res , FUN = function (x ) {
104- z <- x [[" new" ]][[field ]]
105- is.character(z ) && any(nchar(z ) > 0 )
106- }, FUN.VALUE = NA , USE.NAMES = TRUE )
107- has_status <- ! is.na(has_status ) & has_status
108- names(has_status )[has_status ]
105+ if (status == " failure" ) {
106+ names(which(sapply(res , FUN = .subset2 , " status" ) == " E" ))
107+ } else if (status == " error" ) {
108+ field <- switch (status , error = " errors" )
109+ has_status <- vapply(res , FUN = function (x ) {
110+ z <- x [[" new" ]][[field ]]
111+ is.character(z ) && any(nchar(z ) > 0 )
112+ }, FUN.VALUE = NA , USE.NAMES = TRUE )
113+ has_status <- ! is.na(has_status ) & has_status
114+ names(has_status )[has_status ]
115+ }
109116}
110117
111- revdep_preinstall <- function (pkgs ) {
112- pkgs <- unique(pkgs )
113- lib_paths_org <- lib_paths <- .libPaths()
114- on.exit(.libPaths(lib_paths_org ))
118+ revdep_preinstall_libs <- function () {
119+ lib_paths <- .libPaths()
115120 lib_paths [1 ] <- sprintf(" %s-revdepcheck" , lib_paths [1 ])
116121 dir.create(lib_paths [1 ], recursive = TRUE , showWarnings = FALSE )
117- .libPaths(lib_paths )
122+ lib_paths
123+ }
124+
125+ revdep_preinstall <- function (pkgs ) {
126+ oopts <- options(Ncpus = available_cores())
127+ lib_paths_org <- .libPaths()
128+ on.exit({
129+ .libPaths(lib_paths_org )
130+ options(oopts )
131+ })
132+ .libPaths(revdep_preinstall_libs())
133+
134+ pkgs <- unique(pkgs )
118135 message(sprintf(" Triggering crancache builds by pre-installing %d packages: %s" , length(pkgs ), paste(sQuote(pkgs ), collapse = " , " )))
119136 message(" .libPaths():" )
120137 message(paste(paste0(" - " , .libPaths()), collapse = " \n " ))
121138 # # Install one-by-one to update cache sooner
122139 for (kk in seq_along(pkgs )) {
123140 pkg <- pkgs [kk ]
124- message(sprintf(" Pre-installing package %d of %d: %s" ,
125- kk , length(pkgs ), pkg ))
126- crancache :: install_packages(pkg )
141+ message(sprintf(" Pre-installing package %d of %d: %s (Ncpus = %d) " ,
142+ kk , length(pkgs ), pkg , getOption( " Ncpus " , 1L ) ))
143+ crancache :: install_packages(pkg , dependencies = c( " Depends " , " Imports " , " LinkingTo " , " Suggests " ) )
127144 }
128145}
129146
130- args <- base :: commandArgs()
147+ revdep_preinstall_update <- function () {
148+ oopts <- options(Ncpus = available_cores())
149+ lib_paths_org <- .libPaths()
150+ on.exit({
151+ .libPaths(lib_paths_org )
152+ options(oopts )
153+ })
154+ .libPaths(revdep_preinstall_libs())
155+
156+ message(" Update crancache for all pre-installing packages:" )
157+ message(" .libPaths():" )
158+ message(paste(paste0(" - " , .libPaths()), collapse = " \n " ))
159+ message(sprintf(" Ncpus=%d" , getOption(" Ncpus" , 1L )))
160+ crancache :: update_packages(ask = FALSE )
161+ }
162+
163+
164+ args <- base :: commandArgs(trailingOnly = TRUE )
131165if (" --reset" %in% args ) {
132166 revdep_reset()
133167} else if (" --todo-reset" %in% args ) {
@@ -137,17 +171,25 @@ if ("--reset" %in% args) {
137171 todo()
138172} else if (" --add" %in% args ) {
139173 pos <- which(" --add" == args )
174+ if (pos == length(args )) stop(" Missing value for option '--add'" )
140175 pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
141176 revdep_add(packages = pkgs )
142177 todo()
143178} else if (" --rm" %in% args ) {
144179 pos <- which(" --rm" == args )
180+ if (pos == length(args )) stop(" Missing value for option '--rm'" )
145181 pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
146182 revdep_rm(packages = pkgs )
147183 todo()
148184} else if (" --add-broken" %in% args ) {
149185 revdep_add_broken()
150186 todo()
187+ } else if (" --add-error" %in% args ) {
188+ # res <- revepcheck::revdep_summary()
189+ pkgs <- revdep_pkgs_with_status(" error" )
190+ str(pkgs )
191+ revdep_add(packages = pkgs )
192+ todo()
151193} else if (" --add-all" %in% args ) {
152194 revdep_init()
153195 pkgs <- revdep_children()
@@ -168,6 +210,7 @@ if ("--reset" %in% args) {
168210 todo()
169211} else if (" --show-check" %in% args ) {
170212 pos <- which(" --show-check" == args )
213+ if (pos == length(args )) stop(" Missing value for option '--show-check" )
171214 pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
172215 for (pkg in pkgs ) {
173216 for (dir in c(" old" , " new" )) {
@@ -188,20 +231,34 @@ if ("--reset" %in% args) {
188231 cat(sprintf(" [n=%d] %s\n " , length(pkgs ), paste(pkgs , collapse = " " )))
189232} else if (" --list-error" %in% args ) {
190233 cat(paste(revdep_pkgs_with_status(" error" ), collapse = " " ), " \n " , sep = " " )
234+ } else if (" --list-failure" %in% args ) {
235+ cat(paste(revdep_pkgs_with_status(" failure" ), collapse = " " ), " \n " , sep = " " )
191236} else if (" --add-error" %in% args ) {
192237 revdepcheck :: revdep_add(packages = revdep_pkgs_with_status(" error" ))
238+ } else if (" --add-failure" %in% args ) {
239+ revdepcheck :: revdep_add(packages = revdep_pkgs_with_status(" failure" ))
240+ } else if (" --preinstall-update" %in% args ) {
241+ revdep_preinstall_update()
193242} else if (" --preinstall-children" %in% args ) {
194243 pkg <- revdep_this_package()
195244 pkgs <- revdepcheck ::: cran_revdeps(pkg )
196245 revdep_preinstall(pkgs )
197246} else if (" --preinstall-error" %in% args ) {
198247 res <- revdepcheck :: revdep_summary()
199248 revdep_preinstall(revdep_pkgs_with_status(" error" ))
249+ } else if (" --preinstall-failure" %in% args ) {
250+ res <- revdepcheck :: revdep_summary()
251+ revdep_preinstall(revdep_pkgs_with_status(" failure" ))
252+ } else if (" --preinstall-todo" %in% args ) {
253+ todo <- revdep_todo()
254+ revdep_preinstall(todo $ package )
200255} else if (" --preinstall" %in% args ) {
201256 pos <- which(" --preinstall" == args )
257+ if (pos == length(args )) stop(" Missing value for option '--preinstall'" )
202258 pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
203259 revdep_preinstall(pkgs )
204260} else {
261+ stopifnot(length(args ) == 0L )
205262 check()
206263 revdep_report(all = TRUE )
207264}
0 commit comments