Skip to content

Commit

Permalink
add an optional check for bashism
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@77306 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Oct 17, 2019
1 parent 5cc1b76 commit 0866fd0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
\item \command{R --help} now mentions the option \command{--no-echo}
(renamed from \command{--slave}) and its previously undocumented
short form \command{-s}.

\item \command{R CMD check} now optionally checks
\command{configure} and \command{cleanup} scripts for
non-Bourne-shell code (\sQuote{bashisms}).
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/manual/R-exts.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ to use @samp{FC FFLAGS FPICFLAGS} for fixed-form Fortran and
be used with @R{} versions before 3.6.0 should use the legacy forms
@samp{F77 FFLAGS FPICFLAGS} and @samp{FC FCFLAGS FCPICFLAGS}, but
@samp{F77} and @samp{FCPICFLAGS} are no longer defined, so such packages
should depend on @samp{R (< 3.7)}.)
should depend on @samp{R (< 4.0)}.)

To check for an external BLAS library using the @code{AX_BLAS} macro
from the official Autoconf Macro Archive, one can simply do
Expand Down
11 changes: 11 additions & 0 deletions doc/manual/R-ints.texi
Original file line number Diff line number Diff line change
Expand Up @@ -4314,6 +4314,16 @@ instances where @env{TEMPDIR} is not respected and so files are left in
@file{/tmp/boost_interprocess} on some OSes.
@c macOS is one.
Default: false (but true for CRAN submission checks).

@item _R_CHECK_BASHISMS_
Check the top-level scripts @file{configure} (unless generated by
@file{autoconf}) and @file{cleanup} for non-Bourne-shell code, using the
Perl script @command{checkbashisms} if available. This includes
reporting scripts using the non-portable @code{#! /bin/bash}.
(Script @command{checkbashisms} is available in most Linux distributions
and from @uref{https://sourceforge.net/@/projects/@/checkbaskisms/@/files}.)
Default: false (but true for CRAN submission checks except on Windows).

@end vtable

CRAN's submission checks use something like
Expand Down Expand Up @@ -4353,6 +4363,7 @@ _R_CHECK_AUTOCONF_=true
_R_CHECK_DATALIST_=true
_R_CHECK_THINGS_IN_CHECK_DIR_=true
_R_CHECK_THINGS_IN_TEMP_DIR_=true
_R_CHECK_BASHISMS_=true
@end example

@noindent
Expand Down
51 changes: 51 additions & 0 deletions src/library/tools/R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,56 @@ add_dummies <- function(dir, Log)
}
}

## checkbashisms skips non-shell scripts, and bash ones with a message.
if (config_val_to_logical(Sys.getenv("_R_CHECK_BASHISMS_", "FALSE"))
&& any(file.exists("configure", "cleanup"))) {
if (!nzchar(Sys.which("checkbashisms"))) {
if(!any) {
any <- TRUE
warningLog(Log)
}
printLog0(Log, "A complete check needs the 'checkbashisms' script\n")
} else {
for (f in c("configure", "cleanup")) {
## /bin/bash is not portable
if (file.exists(f) &&
grepl("^#! */bin/bash",
readLines(f, 1L, warn = FALSE))) {
if(!any) {
any <- TRUE
msg <- paste0(sQuote(f), ": /bin/bash is not portable")
noteLog(Log, msg)
}
}
## skip autoconf scripts as checkbashisms warns on system parts
if (file.exists(f) &&
!any(grepl("Generated by GNU Autoconf",
readLines(f, warn = FALSE)))) {
out <- suppressWarnings(system2("checkbashisms", c("-p -n", f),
stdout = TRUE, stderr = TRUE,
timeout = 60))
if (length(out) &&
!any(grepl("could not find any possible bashisms",
out))) {
## Skip one report (on two lines)
o <- grep("does not appear to have a #! interpreter line;", out)
if (length(o) && length(out) > o)
out <- out[-(o:(o+1L))]
if (length(out)) {
if(!any) {
any <- TRUE
noteLog(Log)
}
printLog0(Log,
.format_lines_with_indent(out),
"\n")
}
}
}
}
}
}

if(check_incoming) {
## CRAN must be able to convert
## inst/README.md or README.md
Expand Down Expand Up @@ -5962,6 +6012,7 @@ add_dummies <- function(dir, Log)
"package:_R_CHECK_PACKAGE_NAME_,verbose")
Sys.setenv("_R_CHECK_CODOC_VARIABLES_IN_USAGES_" = "TRUE")
Sys.setenv("_R_CHECK_DATALIST_" = "TRUE")
if(!WINDOWS) Sys.setenv("_R_CHECK_BASHISMS_" = "TRUE")
R_check_vc_dirs <- TRUE
R_check_executables_exclusions <- FALSE
R_check_doc_sizes2 <- TRUE
Expand Down

0 comments on commit 0866fd0

Please sign in to comment.