Loading...
Searching...
No Matches
dynamicCode Class Reference

Tools for handling dynamic code compilation. More...

#include <dynamicCode.H>

Collaboration diagram for dynamicCode:

Public Member Functions

 dynamicCode (const dynamicCode &)=delete
 No copy construct.
void operator= (const dynamicCode &)=delete
 No copy assignment.
 dynamicCode (const word &codeName, const word &codeDirName="")
 Construct for a specified code name and code directory name.
const wordcodeName () const noexcept
 Return the code-name.
const wordcodeDirName () const noexcept
 Return the code-dirname.
const fileNamecodeRoot () const noexcept
 Root for dynamic code compilation.
const fileNamelibSubDir () const noexcept
 Subdirectory name for loading libraries.
fileName codePath () const
 Path for specified code name.
fileName codeRelPath () const
 Path for specified code name relative to <case>.
fileName libPath () const
 Library path for specified code name.
fileName libRelPath () const
 Library path for specified code name relative to <case>.
fileName digestFile () const
 Path for SHA1Digest.
void clear ()
 Clear files and variables.
void reset (const dynamicCodeContext &)
 Clear files and reset variables to specified context.
void addCompileFile (const fileName &name)
 Add a file template name, which will be found and filtered.
void addCopyFile (const fileName &name)
 Add a file template name, which will be found and filtered.
void addCreateFile (const fileName &name, const std::string &contents)
 Add a file to create with its contents. Will not be filtered.
void setFilterContext (const dynamicCodeContext &)
 Define filter variables for code, codeInclude, SHA1sum.
void setFilterVariable (const word &key, const std::string &value)
 Define a filter variable.
void setMakeOptions (const std::string &content)
 Define contents for Make/options.
bool upToDate (const dynamicCodeContext &context) const
 Verify if the copied code is up-to-date, based on Make/SHA1Digest.
bool upToDate (const SHA1Digest &sha1) const
 Verify if the copied code is up-to-date, based on Make/SHA1Digest.
bool copyOrCreateFiles (const bool verbose=false) const
 Copy/create files prior to compilation.
bool wmakeLibso () const
 Compile a libso.
template<class Type>
void setFieldTemplates ()
 Define a filter variables TemplateType and FieldType.

Static Public Member Functions

static void checkSecurity (const char *title, const dictionary &)
 Check security for creating dynamic code.
static void waitForFile (const fileName &file, const dictionary &contextDict)
 Wait for libPath() file to appear on sub-ranks.

Static Public Attributes

static const word codeTemplateEnvName = "FOAM_CODE_TEMPLATES"
 Name of the code template environment variable.
static const fileName codeTemplateDirName = "codeTemplates/dynamicCode"
 Name of the code template sub-directory.
static int allowSystemOperations
 Flag if system operations are allowed.

Protected Member Functions

bool writeCommentSHA1 (Ostream &) const
 Write SHA1 value as C-comment.
bool createMakeFiles () const
 Copy/create Make/files prior to compilation.
bool createMakeOptions () const
 Copy/create Make/options prior to compilation.
bool writeDigest (const SHA1Digest &) const
 Write digest to Make/SHA1Digest.
bool writeDigest (const std::string &) const
 Write digest to Make/SHA1Digest.

Static Protected Member Functions

static void copyAndFilter (ISstream &, OSstream &, const HashTable< string > &mapping)
 Copy lines while expanding variables.
static bool resolveTemplates (const UList< fileName > &templateNames, DynamicList< fileName > &resolvedFiles, DynamicList< fileName > &badFiles)
 Resolve code-templates via the codeTemplateEnvName.

Static Protected Attributes

static const char *const targetLibDir = "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib"
 Directory for library targets for Make/files.
static const char *const topDirName = "dynamicCode"
 Top-level directory name for copy/compiling.

Detailed Description

Tools for handling dynamic code compilation.

Source files

Definition at line 56 of file dynamicCode.H.

Constructor & Destructor Documentation

◆ dynamicCode() [1/2]

dynamicCode ( const dynamicCode & )
delete

No copy construct.

References dynamicCode().

Referenced by dynamicCode(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamicCode() [2/2]

dynamicCode ( const word & codeName,
const word & codeDirName = "" )
explicit

Construct for a specified code name and code directory name.

Defaults to using the code name for the code directory name

Definition at line 284 of file dynamicCode.C.

References clear(), codeDirName(), codeName(), and topDirName.

Here is the call graph for this function:

Member Function Documentation

◆ copyAndFilter()

void copyAndFilter ( ISstream & is,
OSstream & os,
const HashTable< string > & mapping )
staticprotected

Copy lines while expanding variables.

Definition at line 95 of file dynamicCode.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, ISstream::getLine(), IOstream::good(), Foam::stringOps::inplaceExpand(), ISstream::name(), Foam::nl, and os().

Referenced by copyOrCreateFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveTemplates()

bool resolveTemplates ( const UList< fileName > & templateNames,
DynamicList< fileName > & resolvedFiles,
DynamicList< fileName > & badFiles )
staticprotected

Resolve code-templates via the codeTemplateEnvName.

alternatively in the codeTemplateDirName via Foam::findEtcFile

Definition at line 132 of file dynamicCode.C.

References codeTemplateDirName, codeTemplateEnvName, Foam::findEtcFile(), Foam::getEnv(), Foam::isDir(), Foam::isFile(), and DynamicList< T, SizeMin >::push_back().

Referenced by copyOrCreateFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeCommentSHA1()

bool writeCommentSHA1 ( Ostream & os) const
protected

Write SHA1 value as C-comment.

Definition at line 176 of file dynamicCode.C.

References os().

Referenced by createMakeFiles(), and createMakeOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createMakeFiles()

bool createMakeFiles ( ) const
protected

Copy/create Make/files prior to compilation.

Definition at line 190 of file dynamicCode.C.

References codePath(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::mkDir(), Foam::nl, os(), fileName::path(), targetLibDir, and writeCommentSHA1().

Referenced by copyOrCreateFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createMakeOptions()

bool createMakeOptions ( ) const
protected

Copy/create Make/options prior to compilation.

Definition at line 228 of file dynamicCode.C.

References codePath(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::mkDir(), Foam::nl, os(), fileName::path(), and writeCommentSHA1().

Referenced by copyOrCreateFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDigest() [1/2]

bool writeDigest ( const SHA1Digest & sha1) const
protected

Write digest to Make/SHA1Digest.

Definition at line 257 of file dynamicCode.C.

References digestFile(), Foam::mkDir(), Foam::nl, os(), fileName::path(), and SHA1Digest::write().

Referenced by copyOrCreateFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDigest() [2/2]

bool writeDigest ( const std::string & sha1) const
protected

Write digest to Make/SHA1Digest.

Definition at line 269 of file dynamicCode.C.

References digestFile(), Foam::mkDir(), Foam::nl, os(), and fileName::path().

Here is the call graph for this function:

◆ checkSecurity()

void checkSecurity ( const char * title,
const dictionary & dict )
static

Check security for creating dynamic code.

Definition at line 58 of file dynamicCode.C.

References allowSystemOperations, Foam::foamVersion::api, dict, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::isAdministrator(), and Foam::nl.

Referenced by codeStream::evaluate(), and codedBase::updateLibrary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

void operator= ( const dynamicCode & )
delete

No copy assignment.

References codeDirName(), codeName(), and dynamicCode().

Here is the call graph for this function:

◆ codeName()

const word & codeName ( ) const
inlinenoexcept

Return the code-name.

Definition at line 236 of file dynamicCode.H.

References Foam::noexcept.

Referenced by dynamicCode(), codeStream::getFunction(), operator=(), and codedBase::updateLibrary().

Here is the caller graph for this function:

◆ codeDirName()

const word & codeDirName ( ) const
inlinenoexcept

Return the code-dirname.

Definition at line 241 of file dynamicCode.H.

References Foam::noexcept.

Referenced by dynamicCode(), and operator=().

Here is the caller graph for this function:

◆ codeRoot()

const fileName & codeRoot ( ) const
inlinenoexcept

Root for dynamic code compilation.

Expanded from <case>/dynamicCode

Definition at line 248 of file dynamicCode.H.

References Foam::noexcept.

◆ libSubDir()

const fileName & libSubDir ( ) const
inlinenoexcept

Subdirectory name for loading libraries.

Expanded from platforms/$WM_OPTIONS/lib

Definition at line 255 of file dynamicCode.H.

References Foam::noexcept.

◆ codePath()

fileName codePath ( ) const
inline

Path for specified code name.

Corresponds to codeRoot()/codeDirName()

Definition at line 262 of file dynamicCode.H.

Referenced by copyOrCreateFiles(), createMakeFiles(), createMakeOptions(), and wmakeLibso().

Here is the caller graph for this function:

◆ codeRelPath()

Foam::fileName codeRelPath ( ) const

Path for specified code name relative to <case>.

Corresponds to topDirName/codeDirName()

Definition at line 302 of file dynamicCode.C.

References topDirName.

Referenced by libRelPath().

Here is the caller graph for this function:

◆ libPath()

Foam::fileName libPath ( ) const

Library path for specified code name.

Corresponds to codeRoot()/libSubDir()/lib<codeName>.so

Definition at line 308 of file dynamicCode.C.

References dlLibraryTable::fullname().

Referenced by codeStream::getFunction(), and codedBase::updateLibrary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libRelPath()

Foam::fileName libRelPath ( ) const

Library path for specified code name relative to <case>.

Corresponds to dynamicCode/codeDirName()/libSubDir()/lib<codeName>.so

Definition at line 314 of file dynamicCode.C.

References codeRelPath(), and dlLibraryTable::fullname().

Referenced by copyOrCreateFiles(), and codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ digestFile()

fileName digestFile ( ) const
inline

Path for SHA1Digest.

Corresponds to codePath()/Make/SHA1Digest

Definition at line 295 of file dynamicCode.H.

Referenced by upToDate(), writeDigest(), and writeDigest().

Here is the caller graph for this function:

◆ clear()

void clear ( )

Clear files and variables.

Definition at line 320 of file dynamicCode.C.

Referenced by dynamicCode().

Here is the caller graph for this function:

◆ reset()

void reset ( const dynamicCodeContext & context)

Clear files and reset variables to specified context.

Definition at line 336 of file dynamicCode.C.

References clear(), and setFilterContext().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCompileFile()

void addCompileFile ( const fileName & name)

Add a file template name, which will be found and filtered.

Definition at line 346 of file dynamicCode.C.

References Foam::name().

Referenced by codeStream::getFunction(), codedMixedFvPatchField< Type >::prepare(), codedPoints0MotionSolver::prepare(), CodedFunction1< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), and CodedField< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCopyFile()

void addCopyFile ( const fileName & name)

Add a file template name, which will be found and filtered.

Definition at line 352 of file dynamicCode.C.

References Foam::name().

Referenced by codedMixedFvPatchField< Type >::prepare(), codedPoints0MotionSolver::prepare(), CodedFunction1< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), and CodedField< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCreateFile()

void addCreateFile ( const fileName & name,
const std::string & contents )

Add a file to create with its contents. Will not be filtered.

Definition at line 358 of file dynamicCode.C.

References Foam::name().

Here is the call graph for this function:

◆ setFilterContext()

void setFilterContext ( const dynamicCodeContext & context)

Define filter variables for code, codeInclude, SHA1sum.

Definition at line 368 of file dynamicCode.C.

References dynamicCodeContext::code(), dynamicCodeContext::include(), dynamicCodeContext::localCode(), dynamicCodeContext::sha1(), and SHA1::str().

Referenced by reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFilterVariable()

void setFilterVariable ( const word & key,
const std::string & value )

◆ setMakeOptions()

void setMakeOptions ( const std::string & content)

◆ upToDate() [1/2]

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(), and upToDate().

Referenced by codeStream::getFunction(), and upToDate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upToDate() [2/2]

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 digestFile(), and Foam::exists().

Here is the call graph for this function:

◆ copyOrCreateFiles()

bool copyOrCreateFiles ( const bool verbose = false) const

◆ wmakeLibso()

bool wmakeLibso ( ) const

Compile a libso.

Definition at line 488 of file dynamicCode.C.

References codePath(), Foam::endl(), Foam::Info, Foam::infoDetailLevel, Foam::InfoErr, os(), and Foam::system().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitForFile()

void waitForFile ( const fileName & file,
const dictionary & contextDict )
static

Wait for libPath() file to appear on sub-ranks.

Returns immediately if non-parallel or IOobject::fileModificationSkew is not set

Definition at line 531 of file dynamicCode.C.

References UPstream::broadcast, DebugPout, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, IOobject::fileModificationSkew, Foam::fileSize(), IOobject::maxFileModificationPolls, UPstream::myProcNo(), Foam::nl, UPstream::parRun(), and Foam::sleep().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFieldTemplates()

template<class Type>
void setFieldTemplates ( )
inline

Define a filter variables TemplateType and FieldType.

Definition at line 385 of file dynamicCode.H.

References setFilterVariable().

Referenced by codedMixedFvPatchField< Type >::prepare(), CodedFunction1< Type >::prepare(), and CodedField< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ targetLibDir

const char *const targetLibDir = "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib"
staticprotected

Directory for library targets for Make/files.

Definition at line 113 of file dynamicCode.H.

Referenced by createMakeFiles().

◆ topDirName

const char *const topDirName = "dynamicCode"
staticprotected

Top-level directory name for copy/compiling.

Definition at line 118 of file dynamicCode.H.

Referenced by codeRelPath(), and dynamicCode().

◆ codeTemplateEnvName

const Foam::word codeTemplateEnvName = "FOAM_CODE_TEMPLATES"
static

Name of the code template environment variable.

Used to located the codeTemplateName

Definition at line 181 of file dynamicCode.H.

Referenced by copyOrCreateFiles(), and resolveTemplates().

◆ codeTemplateDirName

const Foam::fileName codeTemplateDirName = "codeTemplates/dynamicCode"
static

Name of the code template sub-directory.

Used when locating the codeTemplateName via Foam::findEtcFile

Definition at line 188 of file dynamicCode.H.

Referenced by copyOrCreateFiles(), and resolveTemplates().

◆ allowSystemOperations

int allowSystemOperations
static

Flag if system operations are allowed.

Definition at line 193 of file dynamicCode.H.

Referenced by checkSecurity(), argList::parse(), and systemCall::read().


The documentation for this class was generated from the following files: