[Rcpp-commits] r3913 - in pkg/Rcpp: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 7 20:13:08 CET 2012


Author: jjallaire
Date: 2012-11-07 20:13:08 +0100 (Wed, 07 Nov 2012)
New Revision: 3913

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/R/Attributes.R
Log:
derive depends from package LinkingTo

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-07 17:25:05 UTC (rev 3912)
+++ pkg/Rcpp/ChangeLog	2012-11-07 19:13:08 UTC (rev 3913)
@@ -1,5 +1,6 @@
 2012-11-07  JJ Allaire <jj at rstudio.org>
 
+        * R/Attributes.R: derive depends from package LinkingTo
         * src/Attributes.cpp: validate exported C++ functions before calling;
         use static rather than inline for stubs to avoid call-site bloat;
         improved error message when package hpp already exists; import Rcpp

Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R	2012-11-07 17:25:05 UTC (rev 3912)
+++ pkg/Rcpp/R/Attributes.R	2012-11-07 19:13:08 UTC (rev 3913)
@@ -22,7 +22,7 @@
                       env = globalenv(), 
                       rebuild = FALSE,
                       showOutput = verbose,
-                      verbose = getOption("verbose")) {
+                      verbose = getOption("verbose")) { 
     
     # resolve code into a file if necessary
     if (!missing(code)) {
@@ -32,8 +32,10 @@
         close(con)
     }
     
+    # resolve the file path
+    file <- normalizePath(file, winslash = "/")
+     
     # get the context (does code generation as necessary)
-    file <- normalizePath(file, winslash = "/")
     context <- .Call("sourceCppContext", PACKAGE="Rcpp", file, code, .Platform)
     
     # perform a build if necessary
@@ -47,11 +49,14 @@
         succeeded <- FALSE
         output <- NULL
         
+        # build dependency list
+        depends <- .getSourceCppDependencies(context$depends, file)
+        
         # validate packages (error if package not found)
-        .validatePackages(context$depends, context$cppSourceFilename)
+        .validatePackages(depends, context$cppSourceFilename)
         
         # temporarily modify environment for the build
-        envRestore <- .setupBuildEnvironment(context$depends)
+        envRestore <- .setupBuildEnvironment(depends)
         
         # temporarily setwd to build directory
         cwd <- getwd()
@@ -144,7 +149,7 @@
     if (!is.null(plugin)) {
         depends <- paste(plugin, sep=", ")
         scaffolding <- paste("// [[Rcpp::depends(", depends, ")]]", sep="")
-        scaffolding <- c(scaffolding, "", .rcppExportsIncludes(plugin), 
+        scaffolding <- c(scaffolding, "", .rcppExportsIncludes(depends), 
                          recursive=T)
     }
     else {
@@ -246,6 +251,19 @@
 }
 
 
+.getSourceCppDependencies <- function(depends, sourceFile) {
+    
+    # add package LinkingTo dependencies if the source file is in a package
+    descFile <- file.path(dirname(sourceFile), "..", "DESCRIPTION")
+    if (file.exists(descFile)) {
+        DESCRIPTION <- read.dcf(descFile, all = TRUE)
+        linkingTo <- .parseLinkingTo(DESCRIPTION$LinkingTo)
+        unique(c(depends, linkingTo))
+    } else {
+        depends
+    }
+}
+
 # Error if a package is not currently available
 .validatePackages <- function(depends, sourceFilename) {
     unavailable <- depends[!depends %in% .packages(all.available=TRUE)]
@@ -437,8 +455,7 @@
     # Look for Rcpp inline plugins within the list or LinkedTo packages
     include.before <- character()
     include.after <- character()
-    linkingToPackages <- strsplit(linkingTo, "\\s*\\,")[[1]]
-    linkingToPackages <- gsub("\\s", "", linkingToPackages)
+    linkingToPackages <- .parseLinkingTo(linkingTo)
     for (package in linkingToPackages) {
         
         # We already handle Rcpp internally
@@ -499,5 +516,13 @@
     list(before = before, after = after)
 }
 
+# Parse a LinkingTo field into a character vector
+.parseLinkingTo <- function(linkingTo) {
+    
+    if (is.null(linkingTo))
+        return (character())
+    
+    linkingTo <- strsplit(linkingTo, "\\s*\\,")[[1]]
+    gsub("\\s", "", linkingTo)
+}
 
-



More information about the Rcpp-commits mailing list