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... | |
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 | setFilterContext (const dynamicCodeContext &) |
Define filter variables for code, codeInclude, SHA1sum. 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... | |
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 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... | |
Private Member Functions | |
dynamicCode (const dynamicCode &) | |
Disallow default bitwise copy construct. More... | |
void | operator= (const dynamicCode &) |
Disallow default bitwise assignment. More... | |
Private Attributes | |
fileName | codeRoot_ |
Root for dynamic code compilation. More... | |
const fileName | libSubDir_ |
Subdirectory name for loading libraries. More... | |
word | codeName_ |
Name for code. More... | |
word | codeDirName_ |
Name for code subdirectory. More... | |
DynamicList< fileName > | compileFiles_ |
Files to copy and filter. More... | |
DynamicList< fileName > | copyFiles_ |
Files to copy and filter. More... | |
DynamicList< fileAndContent > | createFiles_ |
Direct contents for files. More... | |
HashTable< string > | filterVars_ |
Variables to use during filtering. More... | |
std::string | makeOptions_ |
Contents for Make/options. More... | |
Tools for handling dynamic code compilation.
Definition at line 56 of file dynamicCode.H.
typedef Tuple2<fileName, string> fileAndContent |
Definition at line 59 of file dynamicCode.H.
|
private |
Disallow default bitwise copy construct.
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 293 of file dynamicCode.C.
References dynamicCode::clear(), dynamicCode::codeDirName_, and dynamicCode::codeName_.
|
private |
Disallow default bitwise assignment.
|
staticprotected |
Copy lines while expanding variables.
Definition at line 104 of file dynamicCode.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, ISstream::getLine(), IOstream::good(), Foam::stringOps::inplaceExpand(), OSstream::name(), ISstream::name(), Foam::nl, and OSstream::writeQuoted().
|
staticprotected |
Resolve code-templates via the codeTemplateEnvName.
alternatively in the codeTemplateDirName via Foam::findEtcFile
Definition at line 141 of file dynamicCode.C.
References DynamicList::append(), Foam::findEtcFile(), forAll, Foam::getEnv(), Foam::isDir(), and Foam::isFile().
|
protected |
Write SHA1 value as C-comment.
Definition at line 186 of file dynamicCode.C.
References Ostream::writeQuoted().
|
protected |
Copy/create Make/files prior to compilation.
Definition at line 200 of file dynamicCode.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, forAll, IOstream::good(), Foam::mkDir(), Foam::nl, fileName::path(), and OSstream::writeQuoted().
|
protected |
Copy/create Make/options prior to compilation.
Definition at line 237 of file dynamicCode.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, IOstream::good(), Foam::mkDir(), Foam::nl, fileName::path(), and OSstream::writeQuoted().
|
protected |
Write digest to Make/SHA1Digest.
Definition at line 266 of file dynamicCode.C.
References IOstream::good(), Foam::mkDir(), Foam::nl, fileName::path(), and SHA1Digest::write().
|
protected |
Write digest to Make/SHA1Digest.
Definition at line 278 of file dynamicCode.C.
References IOstream::good(), Foam::mkDir(), Foam::nl, fileName::path(), and OSstream::writeQuoted().
|
static |
Check security for creating dynamic code.
Definition at line 57 of file dynamicCode.C.
References dict, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::isAdministrator(), and Foam::nl.
|
static |
Return the library basename without leading 'lib' or trailing '.so'.
Definition at line 92 of file dynamicCode.C.
References dynamicCode::libPath(), and fileName::name().
|
inline |
Return the code-name.
Definition at line 187 of file dynamicCode.H.
References dynamicCode::codeName_.
Referenced by codeStream::getFunction(), and codedBase::updateLibrary().
|
inline |
Return the code-dirname.
Definition at line 193 of file dynamicCode.H.
References dynamicCode::codeDirName_.
|
inline |
Root for dynamic code compilation.
Expanded from $FOAM_CASE/dynamicCode
Definition at line 200 of file dynamicCode.H.
|
inline |
Subdirectory name for loading libraries.
Expanded from platforms/$WM_OPTIONS/lib
Definition at line 207 of file dynamicCode.H.
|
inline |
Path for specified code name.
Corresponds to codeRoot()/codeDirName()
Definition at line 214 of file dynamicCode.H.
|
inline |
Library path for specified code name.
Corresponds to codeRoot()/libSubDir()/lib<codeName>.so
Definition at line 221 of file dynamicCode.H.
Referenced by codedBase::createLibrary(), codeStream::getFunction(), dynamicCode::libraryBaseName(), and codedBase::updateLibrary().
Foam::fileName codeRelPath | ( | ) | const |
Path for specified code name relative to $FOAM_CASE.
Corresponds to topDirName/codeDirName()
Definition at line 311 of file dynamicCode.C.
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 317 of file dynamicCode.C.
Referenced by codedBase::createLibrary(), and codeStream::getFunction().
|
inline |
Path for SHA1Digest.
Corresponds to codePath()/Make/SHA1Digest
Definition at line 239 of file dynamicCode.H.
void clear | ( | ) |
Clear files and variables.
Definition at line 323 of file dynamicCode.C.
Referenced by dynamicCode::dynamicCode().
void reset | ( | const dynamicCodeContext & | context | ) |
Clear files and reset variables to specified context.
Definition at line 340 of file dynamicCode.C.
References clear().
Referenced by codedBase::createLibrary(), and codeStream::getFunction().
void addCompileFile | ( | const fileName & | name | ) |
Add a file template name, which will be found and filtered.
Definition at line 349 of file dynamicCode.C.
References Foam::name().
Referenced by codeStream::getFunction(), codedFunctionObject::prepare(), codedFixedValuePointPatchField< Type >::prepare(), codedFixedValueFvPatchField< Type >::prepare(), codedMixedFvPatchField< Type >::prepare(), and CodedSource< Type >::prepare().
void addCopyFile | ( | const fileName & | name | ) |
Add a file template name, which will be found and filtered.
Definition at line 355 of file dynamicCode.C.
References Foam::name().
Referenced by codedFunctionObject::prepare(), codedFixedValuePointPatchField< Type >::prepare(), codedFixedValueFvPatchField< Type >::prepare(), codedMixedFvPatchField< Type >::prepare(), and CodedSource< Type >::prepare().
Add a file to create with its contents. Will not be filtered.
Definition at line 362 of file dynamicCode.C.
References Foam::name().
void setFilterContext | ( | const dynamicCodeContext & | context | ) |
Define filter variables for code, codeInclude, SHA1sum.
Definition at line 372 of file dynamicCode.C.
References dynamicCodeContext::code(), dynamicCodeContext::include(), dynamicCodeContext::localCode(), dynamicCodeContext::sha1(), and SHA1Digest::str().
void setFilterVariable | ( | const word & | key, |
const std::string & | value | ||
) |
Define a filter variable.
Definition at line 384 of file dynamicCode.C.
Referenced by codedFunctionObject::prepare(), codedFixedValuePointPatchField< Type >::prepare(), codedFixedValueFvPatchField< Type >::prepare(), codedMixedFvPatchField< Type >::prepare(), CodedSource< Type >::prepare(), codedFixedValuePointPatchField< Type >::setFieldTemplates(), codedFixedValueFvPatchField< Type >::setFieldTemplates(), and codedMixedFvPatchField< Type >::setFieldTemplates().
void setMakeOptions | ( | const std::string & | content | ) |
Define contents for Make/options.
Definition at line 393 of file dynamicCode.C.
Referenced by codeStream::getFunction(), codedFunctionObject::prepare(), codedFixedValuePointPatchField< Type >::prepare(), codedFixedValueFvPatchField< Type >::prepare(), codedMixedFvPatchField< Type >::prepare(), and CodedSource< Type >::prepare().
bool upToDate | ( | const dynamicCodeContext & | context | ) | const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
Definition at line 523 of file dynamicCode.C.
References dynamicCodeContext::sha1().
Referenced by codedBase::createLibrary(), and codeStream::getFunction().
bool upToDate | ( | const SHA1Digest & | sha1 | ) | const |
Verify if the copied code is up-to-date, based on Make/SHA1Digest.
Definition at line 510 of file dynamicCode.C.
References Foam::exists().
bool copyOrCreateFiles | ( | const bool | verbose = false | ) | const |
Copy/create files prior to compilation.
Definition at line 399 of file dynamicCode.C.
References Foam::endl(), Foam::exit(), Foam::stringOps::expand(), Foam::FatalError, FatalErrorInFunction, forAll, IOstream::good(), Foam::Info, Foam::mkDir(), fileName::name(), Foam::nl, fileName::path(), and OSstream::writeQuoted().
Referenced by codedBase::createLibrary(), and codeStream::getFunction().
bool wmakeLibso | ( | ) | const |
Compile a libso.
Definition at line 494 of file dynamicCode.C.
References Foam::endl(), Foam::Info, and Foam::system().
Referenced by codedBase::createLibrary(), and codeStream::getFunction().
|
private |
Root for dynamic code compilation.
Definition at line 65 of file dynamicCode.H.
|
private |
Subdirectory name for loading libraries.
Definition at line 68 of file dynamicCode.H.
|
private |
Name for code.
Definition at line 71 of file dynamicCode.H.
Referenced by dynamicCode::codeName(), and dynamicCode::dynamicCode().
|
private |
Name for code subdirectory.
Definition at line 74 of file dynamicCode.H.
Referenced by dynamicCode::codeDirName(), and dynamicCode::dynamicCode().
|
private |
Files to copy and filter.
Definition at line 77 of file dynamicCode.H.
|
private |
Files to copy and filter.
Definition at line 80 of file dynamicCode.H.
|
private |
Direct contents for files.
Definition at line 83 of file dynamicCode.H.
Variables to use during filtering.
Definition at line 86 of file dynamicCode.H.
|
private |
Contents for Make/options.
Definition at line 89 of file dynamicCode.H.
|
staticprotected |
Root of the LIB target for Make/files.
Definition at line 106 of file dynamicCode.H.
|
staticprotected |
Top-level directory name for copy/compiling.
Definition at line 109 of file dynamicCode.H.
|
static |
Name of the code template environment variable.
Used to located the codeTemplateName
Definition at line 154 of file dynamicCode.H.
|
static |
Name of the code template sub-directory.
Used when locating the codeTemplateName via Foam::findEtcFile
Definition at line 158 of file dynamicCode.H.
|
static |
Flag if system operations are allowed.
Definition at line 161 of file dynamicCode.H.
Referenced by argList::parse(), and systemCall::read().
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.