Skip to content
Browse files

add check for compilation flags used

git-svn-id: 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
ripley committed Dec 14, 2017
1 parent ad63529 commit 2e80059595bcfe075347b2a90fa4fb5604d868fa
Showing with 62 additions and 1 deletion.
  1. +12 −0 doc/manual/R-exts.texi
  2. +9 −0 doc/manual/R-ints.texi
  3. +41 −1 src/library/tools/R/check.R
@@ -4338,6 +4338,18 @@ although @option{-pthread} is pretty close to portable. (Option
only cancel built-in defines (not portable) and those defined earlier on
the command line (@R{} does not use any).)

People have used @command{configure} to customize @file{src/Makevars},
including for specific compilers. This is unsafe for several reasons.
First, unintended compilers might meet the check---for example, several
compilers other than GCC identify themselves as `GCC' whilst being only
partially conformant. Second, future versions of compilers may behave
differently (including updates to quite old series) so for example
@option{-Werror} (and specializations) can make a package
non-installable under a future version. Third, using flags to suppress
diagnostic messages can hide important information for debugging on a
platform not tested by the package maintainer. (@command{R CMD check}
can optionally report on unsafe flags which were used.)

Do be very careful with passing arguments between @R{}, C and
@acronym{FORTRAN} code. In particular, @code{long} in C will be 32-bit
@@ -4152,6 +4152,15 @@ Default: false (but true for CRAN submission checks).
Run additional checks on the pragmas in C/C++ source code and headers.
Default: false (but true for CRAN submission checks).

If the package is installed and has C/C++/Fortran code, check the
install log for non-portable flags (for example those added to
@file{src/Makevars} during configuration). Currently @flag{-W} flags
are reported, except @flag{-Wall}, @flag{-Wextra} and
@flag{-Weverything}, and flags which appear to be attempts to suppress
warnings are highlighted.
Default: false (but true for CRAN submission checks).

Check that any dependence on R is not on a recent patch-level version
such as @code{R (>= 3.3.3)} since blocking installation of a package
@@ -2559,7 +2559,7 @@ setRlibs <-
check_src <- function() {
Check_pragmas <- Sys.getenv("_R_CHECK_PRAGMAS_", "FALSE")
if(config_val_to_logical(Check_pragmas) &&
any(file.exists(c("src", "inst/include")))) {
any(dir.exists(c("src", "inst/include")))) {
checkingLog(Log, "pragmas in C/C++ headers and code")
ans <- .check_pragmas('.')
if(length(ans)) {
@@ -2590,6 +2590,45 @@ setRlibs <-
printLog0(Log, paste(c(msg,""), collapse = "\n"))
} else resultLog(Log, "OK")

Check_flags <- Sys.getenv("_R_CHECK_COMPILATION_FLAGS_", "FALSE")
if(config_val_to_logical(Check_flags)) {
instlog <- if (startsWith(install, "check"))
substr(install, 7L, 1000L)
file.path(pkgoutdir, "00install.out")
if (file.exists(instlog) && dir.exists('src')) {
checkingLog(Log, "compilation flags used")
lines <- readLines(instlog, warn = FALSE)
poss <- grep(" -W", lines, useBytes = TRUE, value = TRUE)
tokens <- unlist(strsplit(poss, " ", perl = TRUE,
useBytes = TRUE))
warns <- grep("^[-]W", tokens,
value = TRUE, perl = TRUE, useBytes = TRUE)
## Not sure -Wextra and -Weverything are portable, though
## -Werror is not compiler independent
## (as what is a warning is not)
warns <- setdiff(unique(warns),
c("-Wall", "-Wextra", "-Weverything"))
warns <- warns[!startsWith(warns, "-Wl,")] # linker flags
diags <- grep(" -fno-diagnostics-show-option", tokens,
useBytes = TRUE, value = TRUE)
warns <- c(warns, diags)
if(any(grepl("^-Wno-", warns)) || length(diags)) {
msg <- c("Compilation used the following non-portable flag(s):",
"including flag(s) suppressing warnings")
printLog0(Log, paste(c(msg,""), collapse = "\n"))
} else if(length(warns)) {
warningLog(Log) # might consider NOTE instead
msg <- c("Compilation used the following non-portable flag(s):",
printLog0(Log, paste(c(msg,""), collapse = "\n"))
} else
resultLog(Log, "OK")

check_sos <- function() {
@@ -5008,6 +5047,7 @@ setRlibs <-
Sys.setenv("_R_CHECK_PRAGMAS_" = "TRUE")
R_check_vc_dirs <- TRUE
R_check_executables_exclusions <- FALSE
R_check_doc_sizes2 <- TRUE

0 comments on commit 2e80059

Please sign in to comment.
You can’t perform that action at this time.