[Rcpp-commits] r4141 - in pkg/Rcpp: . R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 10 21:28:49 CET 2012
Author: jjallaire
Date: 2012-12-10 21:28:49 +0100 (Mon, 10 Dec 2012)
New Revision: 4141
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/R/Attributes.R
pkg/Rcpp/src/Attributes.cpp
Log:
warn when depends attribute is not matched with required entries in package description
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-12-10 19:25:53 UTC (rev 4140)
+++ pkg/Rcpp/ChangeLog 2012-12-10 20:28:49 UTC (rev 4141)
@@ -1,5 +1,9 @@
2012-12-10 JJ Allaire <jj at rstudio.org>
+ * R/Attributes.R: warn when depends attribute is not matched with
+ required entries in package description
+ * src/Attributes.cpp: warn when depends attribute is not matched with
+ required entries in package description
* src/AttributesGen.cpp: prune unnecessary includes from RcppExports
* src/Timer.cpp: fix timer build issues on windows
Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R 2012-12-10 19:25:53 UTC (rev 4140)
+++ pkg/Rcpp/R/Attributes.R 2012-12-10 20:28:49 UTC (rev 4141)
@@ -270,9 +270,11 @@
descFile <- file.path(pkgdir,"DESCRIPTION")
if (!file.exists(descFile))
stop("pkgdir must refer to the directory containing an R package")
- DESCRIPTION <- read.dcf(descFile, all = TRUE)
- pkgname <- DESCRIPTION$Package
+ pkgInfo <- tools:::.split_description(tools:::.read_description(descFile))
+ pkgname <- as.character(pkgInfo$DESCRIPTION["Package"])
+ depends <- unique(names(pkgInfo$Depends))
+
# determine source directory
srcDir <- file.path(pkgdir, "src")
if (!file.exists(srcDir))
@@ -295,11 +297,12 @@
# generate the includes list based on LinkingTo. Specify plugins-only
# because we only need as/wrap declarations
- includes <- .linkingToIncludes(DESCRIPTION$LinkingTo, TRUE)
+ linkingTo <- as.character(pkgInfo$DESCRIPTION["LinkingTo"])
+ includes <- .linkingToIncludes(linkingTo, TRUE)
# generate exports
invisible(.Call("compileAttributes", PACKAGE="Rcpp",
- pkgdir, pkgname, cppFiles, cppFileBasenames,
+ pkgdir, pkgname, depends, cppFiles, cppFileBasenames,
includes, verbose, .Platform))
}
Modified: pkg/Rcpp/src/Attributes.cpp
===================================================================
--- pkg/Rcpp/src/Attributes.cpp 2012-12-10 19:25:53 UTC (rev 4140)
+++ pkg/Rcpp/src/Attributes.cpp 2012-12-10 20:28:49 UTC (rev 4141)
@@ -26,6 +26,7 @@
#include <fstream>
#include <cstring>
#include <map>
+#include <set>
#include <algorithm>
#define RCPP_NO_SUGAR
@@ -485,6 +486,7 @@
// RcppExports.cpp and RcppExports.R
RcppExport SEXP compileAttributes(SEXP sPackageDir,
SEXP sPackageName,
+ SEXP sDepends,
SEXP sCppFiles,
SEXP sCppFileBasenames,
SEXP sIncludes,
@@ -494,6 +496,14 @@
// arguments
std::string packageDir = Rcpp::as<std::string>(sPackageDir);
std::string packageName = Rcpp::as<std::string>(sPackageName);
+
+ Rcpp::CharacterVector vDepends = Rcpp::as<Rcpp::CharacterVector>(sDepends);
+ std::set<std::string> depends;
+ for (Rcpp::CharacterVector::iterator
+ it = vDepends.begin(); it != vDepends.end(); ++it) {
+ depends.insert(std::string(*it));
+ }
+
std::vector<std::string> cppFiles =
Rcpp::as<std::vector<std::string> >(sCppFiles);
std::vector<std::string> cppFileBasenames =
@@ -537,6 +547,7 @@
// Parse attributes from each file and generate code as required.
bool haveAttributes = false;
+ std::set<std::string> dependsAttribs;
for (std::size_t i=0; i<cppFiles.size(); i++) {
// parse attributes (continue if there are none)
@@ -550,6 +561,15 @@
// write functions
generators.writeFunctions(attributes, verbose);
+
+ // track depends
+ for (SourceFileAttributesParser::const_iterator
+ it = attributes.begin(); it != attributes.end(); ++it) {
+ if (it->name() == kDependsAttribute) {
+ for (size_t i = 0; i<it->params().size(); ++i)
+ dependsAttribs.insert(it->params()[i].name());
+ }
+ }
}
// write end
@@ -561,7 +581,26 @@
updated = generators.commit(includes);
else
updated = generators.remove();
-
+
+ // print warning if there are depends attributes that don't have
+ // corresponding entries in the DESCRIPTION file
+ std::vector<std::string> diff;
+ std::set_difference(dependsAttribs.begin(), dependsAttribs.end(),
+ depends.begin(), depends.end(),
+ std::back_inserter(diff));
+ if (!diff.empty()) {
+ std::string msg =
+ "The following packages are referenced using Rcpp::depends "
+ "attributes however are not listed in the Depends and LinkingTo "
+ "fields of the package DESCRIPTION file: ";
+ for (size_t i=0; i<diff.size(); i++) {
+ msg += diff[i];
+ if (i != (diff.size()-1))
+ msg += ", ";
+ }
+ showWarning(msg);
+ }
+
// verbose output
if (verbose) {
for (size_t i=0; i<updated.size(); i++)
More information about the Rcpp-commits
mailing list