Tools for handling dynamic code compilation. More...
Public Types | |
typedef Tuple2< fileName, string > | fileAndContent |
Public Member Functions | |
dynamicCode (const word &codeName, const word &codeDirName="") | |
Construct for a specified code name and code directory name. More... | |
dynamicCode (const dynamicCode &)=delete | |
Disallow default bitwise copy construction. More... | |
const word & | codeName () const |
Return the code-name. More... | |
const word & | codeDirName () const |
Return the code-dirname. More... | |
const fileName & | codeRoot () const |
Root for dynamic code compilation. More... | |
fileName | libSubDir () const |
Subdirectory name for loading libraries. More... | |
fileName | codePath () const |
Path for specified code name. More... | |
fileName | libPath () const |
Library path for specified code name. More... | |
fileName | codeRelPath () const |
Path for specified code name relative to $FOAM_CASE. More... | |
fileName | libRelPath () const |
Library path for specified code name relative to $FOAM_CASE. More... | |
fileName | digestFile () const |
Path for SHA1Digest. More... | |
void | clear () |
Clear files and variables. More... | |
void | reset (const dynamicCodeContext &) |
Clear files and reset variables to specified context. More... | |
void | addCompileFile (const fileName &name) |
Add a file template name, which will be found and filtered. More... | |
void | addCopyFile (const fileName &name) |
Add a file template name, which will be found and filtered. More... | |
void | addCreateFile (const fileName &name, const string &contents) |
Add a file to create with its contents. Will not be filtered. More... | |
void | setFilterVariable (const word &key, const std::string &value) |
Define a filter variable. More... | |
void | setMakeOptions (const std::string &content) |
Define contents for Make/options. More... | |
bool | upToDate (const dynamicCodeContext &context) const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest. More... | |
bool | upToDate (const SHA1Digest &sha1) const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest. More... | |
bool | copyOrCreateFiles (const bool verbose=false) const |
Copy/create files prior to compilation. More... | |
bool | wmakeLibso () const |
Compile a libso. More... | |
void | operator= (const dynamicCode &)=delete |
Disallow default bitwise assignment. More... | |
Static Public Member Functions | |
static void | checkSecurity (const char *title, const dictionary &) |
Check security for creating dynamic code. More... | |
static word | libraryBaseName (const fileName &libPath) |
Return the library basename without leading 'lib' or trailing '.so'. More... | |
static fileName | resolveTemplate (const fileName &templateName) |
Resolve code-template via the codeTemplateEnvName. More... | |
Static Public Attributes | |
static const word | codeTemplateEnvName = "FOAM_CODE_TEMPLATES" |
Name of the code template environment variable. More... | |
static const fileName | codeTemplateDirName = "codeTemplates/dynamicCode" |
Name of the code template sub-directory. More... | |
static int | allowSystemOperations |
Flag if system operations are allowed. More... | |
Protected Member Functions | |
bool | writeCommentSHA1 (Ostream &) const |
Write SHA1 value as C-comment. More... | |
bool | createMakeFiles () const |
Copy/create Make/files prior to compilation. More... | |
bool | createMakeOptions () const |
Copy/create Make/options prior to compilation. More... | |
bool | writeDigest (const SHA1Digest &) const |
Write digest to Make/SHA1Digest. More... | |
bool | writeDigest (const std::string &) const |
Write digest to Make/SHA1Digest. More... | |
Static Protected Member Functions | |
static void | copyAndFilter (ISstream &, OSstream &, const HashTable< string > &mapping) |
Copy lines while expanding variables. More... | |
static bool | resolveTemplates (const UList< fileName > &templateNames, DynamicList< fileName > &resolvedFiles, DynamicList< fileName > &badFiles) |
Resolve code-templates via the codeTemplateEnvName. More... | |
Static Protected Attributes | |
static const char *const | libTargetRoot |
Root of the LIB target for Make/files. More... | |
static const char *const | topDirName = "dynamicCode" |
Top-level directory name for copy/compiling. More... | |
Tools for handling dynamic code compilation.
Definition at line 56 of file dynamicCode.H.
typedef Tuple2<fileName, string> fileAndContent |
Definition at line 61 of file dynamicCode.H.
dynamicCode | ( | const word & | codeName, |
const word & | codeDirName = "" |
||
) |
Construct for a specified code name and code directory name.
Defaults to using the code name for the code directory name
Definition at line 323 of file dynamicCode.C.
References dynamicCode::clear().
|
delete |
Disallow default bitwise copy construction.
|
staticprotected |
Copy lines while expanding variables.
Definition at line 105 of file dynamicCode.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, ISstream::getLine(), IOstream::good(), Foam::stringOps::inplaceExpand(), OSstream::name(), ISstream::name(), Foam::nl, dynamicCode::resolveTemplate(), and OSstream::writeQuoted().
Referenced by dynamicCode::copyOrCreateFiles(), and dynamicCode::libraryBaseName().
|
staticprotected |
Resolve code-templates via the codeTemplateEnvName.
alternatively in the codeTemplateDirName via Foam::findEtcFile
Definition at line 171 of file dynamicCode.C.
References DynamicList< T, SizeInc, SizeMult, SizeDiv >::append(), dynamicCode::codeTemplateDirName, dynamicCode::codeTemplateEnvName, Foam::file, Foam::findEtcFile(), forAll, Foam::getEnv(), Foam::isDir(), and Foam::isFile().
Referenced by dynamicCode::copyOrCreateFiles(), and dynamicCode::resolveTemplate().
|
protected |
Write SHA1 value as C-comment.
Definition at line 216 of file dynamicCode.C.
References Ostream::writeQuoted().
Referenced by dynamicCode::createMakeFiles(), and dynamicCode::createMakeOptions().
|
protected |
Copy/create Make/files prior to compilation.
Definition at line 230 of file dynamicCode.C.
References dynamicCode::codePath(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, forAll, dynamicCode::libTargetRoot, Foam::mkDir(), Foam::name(), Foam::nl, fileName::path(), and dynamicCode::writeCommentSHA1().
Referenced by dynamicCode::copyOrCreateFiles().
|
protected |
Copy/create Make/options prior to compilation.
Definition at line 267 of file dynamicCode.C.
References dynamicCode::codePath(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::mkDir(), Foam::nl, fileName::path(), and dynamicCode::writeCommentSHA1().
Referenced by dynamicCode::copyOrCreateFiles().
|
protected |
Write digest to Make/SHA1Digest.
Definition at line 296 of file dynamicCode.C.
References dynamicCode::digestFile(), Foam::file, Foam::mkDir(), Foam::nl, fileName::path(), and SHA1Digest::write().
Referenced by dynamicCode::copyOrCreateFiles().
|
protected |
Write digest to Make/SHA1Digest.
Definition at line 308 of file dynamicCode.C.
References dynamicCode::digestFile(), Foam::file, Foam::mkDir(), Foam::nl, and fileName::path().
|
static |
Check security for creating dynamic code.
Definition at line 58 of file dynamicCode.C.
References Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::isAdministrator(), and Foam::nl.
Referenced by codedBase::updateLibrary().
|
static |
Return the library basename without leading 'lib' or trailing '.so'.
Definition at line 93 of file dynamicCode.C.
References dynamicCode::copyAndFilter(), and fileName::name().
Referenced by codedBase::updateLibrary().
|
inline |
Return the code-name.
Definition at line 185 of file dynamicCode.H.
Referenced by codedBase::updateLibrary().
|
inline |
Return the code-dirname.
Definition at line 191 of file dynamicCode.H.
References dynamicCode::addCompileFile(), dynamicCode::addCopyFile(), dynamicCode::addCreateFile(), dynamicCode::clear(), dynamicCode::codePath(), dynamicCode::codeRelPath(), dynamicCode::codeRoot(), dynamicCode::copyOrCreateFiles(), dynamicCode::digestFile(), dynamicCode::libPath(), dynamicCode::libRelPath(), dynamicCode::libSubDir(), Foam::name(), dynamicCode::operator=(), dynamicCode::reset(), dynamicCode::resolveTemplate(), dynamicCode::setFilterVariable(), dynamicCode::setMakeOptions(), dynamicCode::upToDate(), and dynamicCode::wmakeLibso().
|
inline |
Root for dynamic code compilation.
Expanded from $FOAM_CASE/dynamicCode
Definition at line 198 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName().
|
inline |
Subdirectory name for loading libraries.
Expanded from platforms/$WM_OPTIONS/lib
Definition at line 205 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName().
|
inline |
Path for specified code name.
Corresponds to codeRoot()/codeDirName()
Definition at line 212 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName(), dynamicCode::copyOrCreateFiles(), dynamicCode::createMakeFiles(), dynamicCode::createMakeOptions(), and dynamicCode::wmakeLibso().
|
inline |
Library path for specified code name.
Corresponds to codeRoot()/libSubDir()/lib<codeName>.so
Definition at line 219 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName(), codedBase::description(), and codedBase::updateLibrary().
Foam::fileName codeRelPath | ( | ) | const |
Path for specified code name relative to $FOAM_CASE.
Corresponds to topDirName/codeDirName()
Definition at line 341 of file dynamicCode.C.
References dynamicCode::topDirName.
Referenced by dynamicCode::codeDirName(), and dynamicCode::libRelPath().
Foam::fileName libRelPath | ( | ) | const |
Library path for specified code name relative to $FOAM_CASE.
Corresponds to dynamicCode/codeDirName()/libSubDir()/lib<codeName>.so
Definition at line 347 of file dynamicCode.C.
References dynamicCode::codeRelPath().
Referenced by dynamicCode::codeDirName(), dynamicCode::copyOrCreateFiles(), and codedBase::description().
|
inline |
Path for SHA1Digest.
Corresponds to codePath()/Make/SHA1Digest
Definition at line 235 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName(), dynamicCode::upToDate(), and dynamicCode::writeDigest().
|
static |
Resolve code-template via the codeTemplateEnvName.
alternatively in the codeTemplateDirName via Foam::findEtcFile
Definition at line 143 of file dynamicCode.C.
References dynamicCode::codeTemplateDirName, dynamicCode::codeTemplateEnvName, Foam::file, Foam::findEtcFile(), Foam::getEnv(), Foam::isDir(), Foam::isFile(), and dynamicCode::resolveTemplates().
Referenced by dynamicCode::codeDirName(), and dynamicCode::copyAndFilter().
void clear | ( | ) |
Clear files and variables.
Definition at line 353 of file dynamicCode.C.
References dynamicCode::reset().
Referenced by dynamicCode::codeDirName(), dynamicCode::dynamicCode(), and dynamicCode::reset().
void reset | ( | const dynamicCodeContext & | context | ) |
Clear files and reset variables to specified context.
Definition at line 370 of file dynamicCode.C.
References dynamicCode::clear(), dynamicCodeContext::code(), forAllConstIter(), dynamicCode::setFilterVariable(), dynamicCodeContext::sha1(), and SHA1Digest::str().
Referenced by dynamicCode::clear(), dynamicCode::codeDirName(), and codedBase::description().
void addCompileFile | ( | const fileName & | name | ) |
Add a file template name, which will be found and filtered.
Definition at line 385 of file dynamicCode.C.
Referenced by dynamicCode::codeDirName().
void addCopyFile | ( | const fileName & | name | ) |
Add a file template name, which will be found and filtered.
Definition at line 391 of file dynamicCode.C.
References dynamicCode::addCreateFile().
Referenced by dynamicCode::codeDirName().
Add a file to create with its contents. Will not be filtered.
Definition at line 398 of file dynamicCode.C.
References dynamicCode::setFilterVariable().
Referenced by dynamicCode::addCopyFile(), and dynamicCode::codeDirName().
void setFilterVariable | ( | const word & | key, |
const std::string & | value | ||
) |
Define a filter variable.
Definition at line 408 of file dynamicCode.C.
Referenced by dynamicCode::addCreateFile(), dynamicCode::codeDirName(), and dynamicCode::reset().
void setMakeOptions | ( | const std::string & | content | ) |
Define contents for Make/options.
Definition at line 417 of file dynamicCode.C.
Referenced by dynamicCode::codeDirName().
bool upToDate | ( | const dynamicCodeContext & | context | ) | const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
Definition at line 549 of file dynamicCode.C.
References dynamicCodeContext::sha1().
Referenced by dynamicCode::codeDirName(), and codedBase::description().
bool upToDate | ( | const SHA1Digest & | sha1 | ) | const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
Definition at line 536 of file dynamicCode.C.
References dynamicCode::digestFile(), Foam::exists(), and Foam::file.
bool copyOrCreateFiles | ( | const bool | verbose = false | ) | const |
Copy/create files prior to compilation.
Definition at line 423 of file dynamicCode.C.
References dynamicCode::codePath(), dynamicCode::codeTemplateDirName, dynamicCode::codeTemplateEnvName, dynamicCode::copyAndFilter(), dynamicCode::createMakeFiles(), dynamicCode::createMakeOptions(), UList< T >::empty(), Foam::endl(), Foam::exit(), Foam::stringOps::expand(), Foam::FatalError, FatalErrorInFunction, forAll, IOstream::good(), Foam::Info, dynamicCode::libRelPath(), Foam::mkDir(), fileName::name(), Foam::nl, fileName::path(), dynamicCode::resolveTemplates(), and dynamicCode::writeDigest().
Referenced by dynamicCode::codeDirName(), and codedBase::description().
bool wmakeLibso | ( | ) | const |
Compile a libso.
Definition at line 520 of file dynamicCode.C.
References dynamicCode::codePath(), Foam::endl(), Foam::Info, and Foam::system().
Referenced by dynamicCode::codeDirName(), and codedBase::description().
|
delete |
Disallow default bitwise assignment.
Referenced by dynamicCode::codeDirName().
|
staticprotected |
Root of the LIB target for Make/files.
Definition at line 101 of file dynamicCode.H.
Referenced by dynamicCode::createMakeFiles().
|
staticprotected |
Top-level directory name for copy/compiling.
Definition at line 104 of file dynamicCode.H.
Referenced by dynamicCode::codeRelPath().
|
static |
Name of the code template environment variable.
Used to located the codeTemplateName
Definition at line 149 of file dynamicCode.H.
Referenced by dynamicCode::copyOrCreateFiles(), dynamicCode::resolveTemplate(), and dynamicCode::resolveTemplates().
|
static |
Name of the code template sub-directory.
Used when locating the codeTemplateName via Foam::findEtcFile
Definition at line 153 of file dynamicCode.H.
Referenced by dynamicCode::copyOrCreateFiles(), dynamicCode::resolveTemplate(), and dynamicCode::resolveTemplates().
|
static |
Flag if system operations are allowed.
Definition at line 156 of file dynamicCode.H.
Referenced by argList::parse(), and systemCall::read().