MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / sourceCppContext

Function sourceCppContext

src/attributes.cpp:3554–3614  ·  view source on GitHub ↗

Create temporary build directory, generate code as necessary, and return the context required for the sourceCpp function to complete it's work

Source from the content-addressed store, hash-verified

3552// Create temporary build directory, generate code as necessary, and return
3553// the context required for the sourceCpp function to complete it's work
3554RcppExport SEXP sourceCppContext(SEXP sFile, SEXP sCode,
3555 SEXP sRebuild, SEXP sCacheDir, SEXP sPlatform) {
3556BEGIN_RCPP
3557 // parameters
3558 std::string file = Rcpp::as<std::string>(sFile);
3559 std::string code = sCode != R_NilValue ? Rcpp::as<std::string>(sCode) : "";
3560 bool rebuild = Rcpp::as<bool>(sRebuild);
3561 std::string cacheDir = Rcpp::as<std::string>(sCacheDir);
3562 Rcpp::List platform = Rcpp::as<Rcpp::List>(sPlatform);
3563
3564 // get dynlib (using cache if possible)
3565 SourceCppDynlib dynlib = !code.empty() ? dynlibCacheLookupByCode(cacheDir, code)
3566 : dynlibCacheLookupByFile(cacheDir, file);
3567
3568 // check dynlib build state
3569 bool buildRequired = false;
3570
3571 // if there is no dynlib in the cache then create a new one
3572 if (dynlib.isEmpty()) {
3573 buildRequired = true;
3574 dynlib = SourceCppDynlib(cacheDir, file, platform);
3575 }
3576
3577 // if the cached dynlib is dirty then regenerate the source
3578 else if (rebuild || dynlib.isSourceDirty()) {
3579 buildRequired = true; // #nocov
3580 dynlib.regenerateSource(cacheDir); // #nocov
3581 }
3582
3583 // if the dynlib hasn't yet been built then note that
3584 else if (!dynlib.isBuilt()) {
3585 buildRequired = true; // #nocov
3586 }
3587
3588 // save the dynlib to the cache
3589 if (!code.empty())
3590 dynlibCacheInsertCode(cacheDir, code, dynlib);
3591 else
3592 dynlibCacheInsertFile(cacheDir, file, dynlib);
3593
3594 // return context as a list
3595 using namespace Rcpp;
3596 return List::create(
3597 _["contextId"] = dynlib.contextId(),
3598 _["cppSourcePath"] = dynlib.cppSourcePath(),
3599 _["cppDependencySourcePaths"] = dynlib.cppDependencySourcePaths(),
3600 _["buildRequired"] = buildRequired,
3601 _["buildDirectory"] = dynlib.buildDirectory(),
3602 _["generatedCpp"] = dynlib.generatedCpp(),
3603 _["exportedFunctions"] = dynlib.exportedFunctions(),
3604 _["modules"] = dynlib.modules(),
3605 _["cppSourceFilename"] = dynlib.cppSourceFilename(),
3606 _["rSourceFilename"] = dynlib.rSourceFilename(),
3607 _["dynlibFilename"] = dynlib.dynlibFilename(),
3608 _["dynlibPath"] = dynlib.dynlibPath(),
3609 _["previousDynlibPath"] = dynlib.previousDynlibPath(),
3610 _["depends"] = dynlib.depends(),
3611 _["plugins"] = dynlib.plugins(),

Callers

nothing calls this directly

Calls 15

dynlibCacheLookupByCodeFunction · 0.85
dynlibCacheLookupByFileFunction · 0.85
SourceCppDynlibClass · 0.85
dynlibCacheInsertCodeFunction · 0.85
dynlibCacheInsertFileFunction · 0.85
isEmptyMethod · 0.80
isSourceDirtyMethod · 0.80
regenerateSourceMethod · 0.80
isBuiltMethod · 0.80
buildDirectoryMethod · 0.80
generatedCppMethod · 0.80

Tested by

no test coverage detected