Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpful message when build fails for long paths #178

Merged
merged 3 commits into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions R/install.R
Expand Up @@ -91,13 +91,32 @@ safe_build_package <- function(pkgdir, build_opts, dest_path, quiet, use_pkgbuil

pkgdir <- normalizePath(pkgdir)

message("Running `R CMD build`...")
in_dir(dest_path, {
with_envvar(env, {
output <- rcmd("build", c(build_opts, shQuote(pkgdir)), quiet = quiet)
output <- rcmd("build", c(build_opts, shQuote(pkgdir)), quiet = quiet,
fail_on_status = FALSE)
})
})

file.path(dest_path, sub("^[*] building[^[:alnum:]]+([[:alnum:]_.]+)[^[:alnum:]]+$", "\\1", output[length(output)]))
if (output$status != 0) {
cat("STDOUT:\n")
cat(output$stdout, sep = "\n")
cat("STDERR:\n")
cat(output$stderr, sep = "\n")
if (sys_type() == "windows" &&
gaborcsardi marked this conversation as resolved.
Show resolved Hide resolved
any(grepl("over-long path length", output$stderr))) {
message(
"\nIt seems that this package contains files with very long paths.\n",
"This is not supported on most Windows versions. Please contant the\n",
gaborcsardi marked this conversation as resolved.
Show resolved Hide resolved
"package authors and tell them about this. See this GitHub issue\n",
"for more details: https://github.com/r-lib/remotes/issues/84\n")
}
stop(sprintf("Failed to `R CMD build` package, try `build = FALSE`."),
call. = FALSE)
}

file.path(dest_path, sub("^[*] building[^[:alnum:]]+([[:alnum:]_.]+)[^[:alnum:]]+$", "\\1", output$stdout[length(output$stdout)]))
}
}

Expand Down
18 changes: 12 additions & 6 deletions R/utils.R
Expand Up @@ -9,7 +9,7 @@ viapply <- function(X, FUN, ..., USE.NAMES = TRUE) {
vapply(X, FUN, integer(1L), ..., USE.NAMES = USE.NAMES)
}

rcmd <- function(cmd, args, path = R.home("bin"), quiet) {
rcmd <- function(cmd, args, path = R.home("bin"), quiet, fail_on_status = TRUE) {
if (os_type() == "windows") {
real_cmd <- file.path(path, "Rcmd.exe")
args <- c(cmd, args)
Expand All @@ -18,19 +18,25 @@ rcmd <- function(cmd, args, path = R.home("bin"), quiet) {
args <- c("CMD", cmd, args)
}

outfile <- tempfile()
status <- system2(real_cmd, args, stderr = NULL, stdout = outfile)
out <- readLines(outfile, warn = FALSE)
stdoutfile <- tempfile()
stderrfile <- tempfile()
on.exit(unlink(c(stdoutfile, stderrfile), recursive = TRUE), add = TRUE)
status <- system2(real_cmd, args, stderr = stderrfile, stdout = stdoutfile)
out <- tryCatch(readLines(stdoutfile, warn = FALSE), error = function(x) "")
err <- tryCatch(readLines(stderrfile, warn = FALSE), error = function(x) "")

if (status != 0) {
if (fail_on_status && status != 0) {
cat("STDOUT:\n")
cat(out, sep = "\n")
cat("STDERR:\n")
cat(err, sep = "\n")
stop(sprintf("Error running '%s' (status '%i')", cmd, status), call. = FALSE)
}
if (!quiet) {
cat(out, sep = "\n")
}

out
list(stdout = out, stderr = err, status = status)
}

is_bioconductor <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-install.R
Expand Up @@ -39,7 +39,7 @@ test_that("safe_build_package fails appropriately without pkgbuild", {
capture.output(
expect_error(fixed = TRUE,
safe_build_package(test_path("invalidpkg"), build_opts = opts , out, quiet = TRUE, use_pkgbuild = FALSE),
"Error running 'build' (status '1')"
"Failed to `R CMD build` package"
))
})

Expand Down