[Rcpp-commits] r4187 - in pkg/Rcpp: . R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 11 16:36:51 CET 2013
Author: jjallaire
Date: 2013-01-11 16:36:51 +0100 (Fri, 11 Jan 2013)
New Revision: 4187
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/R/Attributes.R
pkg/Rcpp/src/attributes.cpp
Log:
initial support for Rcpp::plugins attribute
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2013-01-05 00:35:33 UTC (rev 4186)
+++ pkg/Rcpp/ChangeLog 2013-01-11 15:36:51 UTC (rev 4187)
@@ -1,3 +1,8 @@
+2014-01-11 JJ Allaire <jj at rstudio.org>
+
+ * R/Attributes.R: initial support for Rcpp::plugins attribute
+ * src/attributes.cpp: initial support for Rcpp::plugins attribute
+
2014-01-04 JJ Allaire <jj at rstudio.org>
* R/Attributes.R: null check on pkginfo depends field
Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R 2013-01-05 00:35:33 UTC (rev 4186)
+++ pkg/Rcpp/R/Attributes.R 2013-01-11 15:36:51 UTC (rev 4187)
@@ -398,11 +398,44 @@
# Setup the build environment based on the specified dependencies. Returns an
# opaque object that can be passed to .restoreEnvironment to reverse whatever
# changes that were made
-.setupBuildEnvironment <- function(depends, sourceFile) {
+.setupBuildEnvironment <- function(depends, plugins, sourceFile) {
# discover dependencies
buildEnv <- list()
linkingToPackages <- c("Rcpp")
+
+ # update dependencies from a plugin
+ setDependenciesFromPlugin <- function(plugin) {
+
+ # get the plugin settings
+ settings <- plugin()
+
+ # merge environment variables
+ pluginEnv <- settings$env
+ for (name in names(pluginEnv)) {
+ # if it doesn't exist already just set it
+ if (is.null(buildEnv[[name]])) {
+ buildEnv[[name]] <<- pluginEnv[[name]]
+ }
+ # if it's not identical then append
+ else if (!identical(buildEnv[[name]],
+ pluginEnv[[name]])) {
+ buildEnv[[name]] <<- paste(buildEnv[[name]],
+ pluginEnv[[name]]);
+ }
+ else {
+ # it already exists and it's the same value, this
+ # likely means it's a flag-type variable so we
+ # do nothing rather than appending it
+ }
+ }
+
+ # capture any LinkingTo elements defined by the plugin
+ linkingToPackages <<- unique(c(linkingToPackages,
+ settings$LinkingTo))
+ }
+
+ # add packages to linkingTo and introspect for plugins
for (package in depends) {
# add a LinkingTo for this package
@@ -410,37 +443,19 @@
# see if the package exports a plugin
plugin <- .getInlinePlugin(package)
- if (!is.null(plugin)) {
-
- # get the plugin settings
- settings <- plugin()
-
- # merge environment variables
- pluginEnv <- settings$env
- for (name in names(pluginEnv)) {
- # if it doesn't exist already just set it
- if (is.null(buildEnv[[name]])) {
- buildEnv[[name]] <- pluginEnv[[name]]
- }
- # if it's not identical then append
- else if (!identical(buildEnv[[name]],
- pluginEnv[[name]])) {
- buildEnv[[name]] <- paste(buildEnv[[name]],
- pluginEnv[[name]]);
- }
- else {
- # it already exists and it's the same value, this
- # likely means it's a flag-type variable so we
- # do nothing rather than appending it
- }
- }
-
- # capture any LinkingTo elements defined by the plugin
- linkingToPackages <- unique(c(linkingToPackages,
- settings$LinkingTo))
- }
+ if (!is.null(plugin))
+ setDependenciesFromPlugin(plugin)
}
+ # process plugins
+ for (pluginName in plugins) {
+ plugin <- tryCatch(eval(parse(text=pluginName)),
+ error = function(e) NULL)
+ if (!is.function(plugin))
+ stop("Inline plugin '", pluginName, "' could not be found.")
+ setDependenciesFromPlugin(plugin)
+ }
+
# if there is no buildEnv from a plugin then use the Rcpp plugin
if (length(buildEnv) == 0) {
buildEnv <- Rcpp:::inlineCxxPlugin()$env
Modified: pkg/Rcpp/src/attributes.cpp
===================================================================
--- pkg/Rcpp/src/attributes.cpp 2013-01-05 00:35:33 UTC (rev 4186)
+++ pkg/Rcpp/src/attributes.cpp 2013-01-11 15:36:51 UTC (rev 4187)
@@ -96,6 +96,7 @@
// Known attribute names & parameters
const char * const kExportAttribute = "export";
const char * const kDependsAttribute = "depends";
+ const char * const kPluginsAttribute = "plugins";
const char * const kInterfacesAttribute = "interfaces";
const char * const kInterfaceR = "r";
const char * const kInterfaceCpp = "cpp";
@@ -1185,6 +1186,7 @@
const {
return name == kExportAttribute ||
name == kDependsAttribute ||
+ name == kPluginsAttribute ||
name == kInterfacesAttribute;
}
@@ -2320,15 +2322,22 @@
// discover exported functions, and dependencies
exportedFunctions_.clear();
depends_.clear();
+ plugins_.clear();
for (SourceFileAttributesParser::const_iterator
it = sourceAttributes.begin(); it != sourceAttributes.end(); ++it) {
+
if (it->name() == kExportAttribute && !it->function().empty())
exportedFunctions_.push_back(it->exportedName());
else if (it->name() == kDependsAttribute) {
for (size_t i = 0; i<it->params().size(); ++i)
depends_.push_back(it->params()[i].name());
- }
+ }
+
+ else if (it->name() == kPluginsAttribute) {
+ for (size_t i = 0; i<it->params().size(); ++i)
+ plugins_.push_back(it->params()[i].name());
+ }
}
// capture embededded R
@@ -2380,6 +2389,8 @@
const std::vector<std::string>& depends() const { return depends_; };
+ const std::vector<std::string>& plugins() const { return plugins_; };
+
const std::vector<std::string>& embeddedR() const { return embeddedR_; }
private:
@@ -2437,6 +2448,7 @@
std::string dynlibExt_;
std::vector<std::string> exportedFunctions_;
std::vector<std::string> depends_;
+ std::vector<std::string> plugins_;
std::vector<std::string> embeddedR_;
};
@@ -2558,6 +2570,7 @@
_["dynlibPath"] = pDynlib->dynlibPath(),
_["previousDynlibPath"] = pDynlib->previousDynlibPath(),
_["depends"] = pDynlib->depends(),
+ _["plugins"] = pDynlib->plugins(),
_["embeddedR"] = pDynlib->embeddedR());
END_RCPP
}
More information about the Rcpp-commits
mailing list