| 3265 | } |
| 3266 | |
| 3267 | void regenerateSource(const std::string& cacheDir) { |
| 3268 | |
| 3269 | // create new dynlib filename |
| 3270 | previousDynlibFilename_ = dynlibFilename_; |
| 3271 | dynlibFilename_ = "sourceCpp_" + uniqueToken(cacheDir) + dynlibExt_; |
| 3272 | |
| 3273 | // copy the source file to the build dir |
| 3274 | Rcpp::Function filecopy = Rcpp::Environment::base_env()["file.copy"]; |
| 3275 | filecopy(cppSourcePath_, generatedCppSourcePath(), true, Rcpp::_["copy.mode"] = false); |
| 3276 | |
| 3277 | // parse attributes |
| 3278 | SourceFileAttributesParser sourceAttributes(cppSourcePath_, "", true); |
| 3279 | |
| 3280 | // generate cpp for attributes and append them |
| 3281 | std::ostringstream ostr; |
| 3282 | // always include Rcpp.h in case the user didn't |
| 3283 | ostr << std::endl << std::endl; |
| 3284 | ostr << "#include <Rcpp.h>" << std::endl; |
| 3285 | // initialize references to global Rostreams |
| 3286 | initializeGlobals(ostr); |
| 3287 | generateCpp(ostr, sourceAttributes, true, false, contextId_); |
| 3288 | generatedCpp_ = ostr.str(); |
| 3289 | std::ofstream cppOfs(generatedCppSourcePath().c_str(), |
| 3290 | std::ofstream::out | std::ofstream::app); |
| 3291 | if (cppOfs.fail()) |
| 3292 | throw Rcpp::file_io_error(generatedCppSourcePath()); // #nocov |
| 3293 | cppOfs << generatedCpp_; |
| 3294 | cppOfs.close(); |
| 3295 | |
| 3296 | // generate R for attributes and write it into the build directory |
| 3297 | std::ofstream rOfs(generatedRSourcePath().c_str(), |
| 3298 | std::ofstream::out | std::ofstream::trunc); |
| 3299 | if (rOfs.fail()) |
| 3300 | throw Rcpp::file_io_error(generatedRSourcePath()); // #nocov |
| 3301 | |
| 3302 | // DLLInfo - hide using . and ensure uniqueness using contextId |
| 3303 | std::string dllInfo = "`." + contextId_ + "_DLLInfo`"; |
| 3304 | rOfs << dllInfo << " <- dyn.load('" << dynlibPath() << "')" |
| 3305 | << std::endl << std::endl; |
| 3306 | |
| 3307 | // Generate R functions |
| 3308 | generateR(rOfs, sourceAttributes, dllInfo); |
| 3309 | |
| 3310 | // remove the DLLInfo |
| 3311 | rOfs << std::endl << "rm(" << dllInfo << ")" |
| 3312 | << std::endl; |
| 3313 | |
| 3314 | rOfs.close(); |
| 3315 | |
| 3316 | // discover exported functions and dependencies |
| 3317 | exportedFunctions_.clear(); |
| 3318 | depends_.clear(); |
| 3319 | plugins_.clear(); |
| 3320 | for (SourceFileAttributesParser::const_iterator |
| 3321 | it = sourceAttributes.begin(); it != sourceAttributes.end(); ++it) { |
| 3322 | |
| 3323 | if (it->name() == kExportAttribute && !it->function().empty()) |
| 3324 | exportedFunctions_.push_back(it->exportedName()); |
no test coverage detected