Class that manages generation of source code for the sourceCpp dynlib
| 3150 | |
| 3151 | // Class that manages generation of source code for the sourceCpp dynlib |
| 3152 | class SourceCppDynlib { |
| 3153 | public: |
| 3154 | SourceCppDynlib() {} |
| 3155 | |
| 3156 | SourceCppDynlib(const std::string& cacheDir, |
| 3157 | const std::string& cppSourcePath, |
| 3158 | Rcpp::List platform) |
| 3159 | : cppSourcePath_(cppSourcePath) |
| 3160 | |
| 3161 | { |
| 3162 | // get cpp source file info |
| 3163 | FileInfo cppSourceFilenameInfo(cppSourcePath_); |
| 3164 | if (!cppSourceFilenameInfo.exists()) |
| 3165 | throw Rcpp::file_not_found(cppSourcePath_); // #nocov |
| 3166 | |
| 3167 | // record the base name of the source file |
| 3168 | Rcpp::Function basename = Rcpp::Environment::base_env()["basename"]; |
| 3169 | cppSourceFilename_ = Rcpp::as<std::string>(basename(cppSourcePath_)); |
| 3170 | |
| 3171 | // get platform info |
| 3172 | fileSep_ = Rcpp::as<std::string>(platform["file.sep"]); |
| 3173 | dynlibExt_ = Rcpp::as<std::string>(platform["dynlib.ext"]); |
| 3174 | |
| 3175 | // generate temp directory |
| 3176 | Rcpp::Function tempfile = Rcpp::Environment::base_env()["tempfile"]; |
| 3177 | buildDirectory_ = Rcpp::as<std::string>(tempfile("sourcecpp_", cacheDir)); |
| 3178 | std::replace(buildDirectory_.begin(), buildDirectory_.end(), '\\', '/'); |
| 3179 | Rcpp::Function dircreate = Rcpp::Environment::base_env()["dir.create"]; |
| 3180 | dircreate(buildDirectory_); |
| 3181 | |
| 3182 | // generate a random context id |
| 3183 | contextId_ = "sourceCpp_" + uniqueToken(cacheDir); |
| 3184 | |
| 3185 | // regenerate the source code |
| 3186 | regenerateSource(cacheDir); |
| 3187 | } |
| 3188 | |
| 3189 | // create from list |
| 3190 | explicit SourceCppDynlib(const Rcpp::List& dynlib) |
| 3191 | { |
| 3192 | using namespace Rcpp; |
| 3193 | |
| 3194 | cppSourcePath_ = as<std::string>(dynlib["cppSourcePath"]); |
| 3195 | generatedCpp_ = as<std::string>(dynlib["generatedCpp"]); |
| 3196 | cppSourceFilename_ = as<std::string>(dynlib["cppSourceFilename"]); |
| 3197 | contextId_ = as<std::string>(dynlib["contextId"]); |
| 3198 | buildDirectory_ = as<std::string>(dynlib["buildDirectory"]); |
| 3199 | fileSep_ = as<std::string>(dynlib["fileSep"]); |
| 3200 | dynlibFilename_ = as<std::string>(dynlib["dynlibFilename"]); |
| 3201 | previousDynlibFilename_ = as<std::string>(dynlib["previousDynlibFilename"]); |
| 3202 | dynlibExt_ = as<std::string>(dynlib["dynlibExt"]); |
| 3203 | exportedFunctions_ = as<std::vector<std::string> >(dynlib["exportedFunctions"]); |
| 3204 | modules_ = as<std::vector<std::string> >(dynlib["modules"]); |
| 3205 | depends_ = as<std::vector<std::string> >(dynlib["depends"]); |
| 3206 | plugins_ = as<std::vector<std::string> >(dynlib["plugins"]); |
| 3207 | embeddedR_ = as<std::vector<std::string> >(dynlib["embeddedR"]); |
| 3208 | List sourceDependencies = as<List>(dynlib["sourceDependencies"]); |
| 3209 | for (R_xlen_t i = 0; i<sourceDependencies.length(); i++) { |
no outgoing calls
no test coverage detected