Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
dynamicCode Class Reference

Tools for handling dynamic code compilation. More...

Collaboration diagram for dynamicCode:
Collaboration graph
[legend]

Public Types

typedef Tuple2< fileName, stringfileAndContent
 

Public Member Functions

 dynamicCode (const word &codeName, const word &codeDirName="")
 Construct for a specified code name and code directory name. More...
 
const wordcodeName () const
 Return the code-name. More...
 
const wordcodeDirName () const
 Return the code-dirname. More...
 
const fileNamecodeRoot () 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...
 

Detailed Description

Tools for handling dynamic code compilation.

Source files

Definition at line 56 of file dynamicCode.H.

Member Typedef Documentation

Definition at line 59 of file dynamicCode.H.

Constructor & Destructor Documentation

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 311 of file dynamicCode.C.

References dynamicCode::clear().

Here is the call graph for this function:

Member Function Documentation

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

Copy lines while expanding variables.

Definition at line 110 of file dynamicCode.C.

References Foam::exit(), Foam::FatalError, FatalErrorIn, ISstream::getLine(), IOstream::good(), Foam::stringOps::inplaceExpand(), OSstream::name(), ISstream::name(), Foam::nl, dynamicCode::resolveTemplates(), and OSstream::writeQuoted().

Referenced by dynamicCode::copyOrCreateFiles(), and dynamicCode::libraryBaseName().

Here is the call graph for this function:

Here is the caller graph for this function:

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 153 of file dynamicCode.C.

References DynamicList< T, SizeInc, SizeMult, SizeDiv >::append(), dynamicCode::codeTemplateDirName, dynamicCode::codeTemplateEnvName, Foam::findEtcFile(), forAll, Foam::getEnv(), Foam::isDir(), and Foam::isFile().

Referenced by dynamicCode::copyAndFilter(), and dynamicCode::copyOrCreateFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

bool writeCommentSHA1 ( Ostream os) const
protected

Write SHA1 value as C-comment.

Definition at line 198 of file dynamicCode.C.

References Ostream::writeQuoted().

Referenced by dynamicCode::createMakeFiles(), and dynamicCode::createMakeOptions().

Here is the call graph for this function:

Here is the caller graph for this function:

bool createMakeFiles ( ) const
protected

Copy/create Make/files prior to compilation.

Definition at line 212 of file dynamicCode.C.

References dynamicCode::codePath(), Foam::exit(), Foam::FatalError, FatalErrorIn, forAll, dynamicCode::libTargetRoot, Foam::mkDir(), Foam::nl, fileName::path(), and dynamicCode::writeCommentSHA1().

Referenced by dynamicCode::copyOrCreateFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

bool createMakeOptions ( ) const
protected

Copy/create Make/options prior to compilation.

Definition at line 252 of file dynamicCode.C.

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

Referenced by dynamicCode::copyOrCreateFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

bool writeDigest ( const SHA1Digest sha1) const
protected

Write digest to Make/SHA1Digest.

Definition at line 284 of file dynamicCode.C.

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

Referenced by dynamicCode::copyOrCreateFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Write digest to Make/SHA1Digest.

Definition at line 296 of file dynamicCode.C.

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

Here is the call graph for this function:

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

Check security for creating dynamic code.

Definition at line 57 of file dynamicCode.C.

References Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorIn, Foam::isAdministrator(), and Foam::nl.

Referenced by calcEntry::execute(), codeStream::execute(), and codedBase::updateLibrary().

Here is the call graph for this function:

Here is the caller graph for this function:

Foam::word libraryBaseName ( const fileName libPath)
static

Return the library basename without leading 'lib' or trailing '.so'.

Definition at line 98 of file dynamicCode.C.

References dynamicCode::copyAndFilter(), and fileName::name().

Referenced by codedBase::updateLibrary().

Here is the call graph for this function:

Here is the caller graph for this function:

const word& codeName ( ) const
inline

Return the code-name.

Definition at line 187 of file dynamicCode.H.

const word& codeDirName ( ) const
inline
const fileName& codeRoot ( ) const
inline

Root for dynamic code compilation.

Expanded from $FOAM_CASE/dynamicCode

Definition at line 200 of file dynamicCode.H.

Referenced by dynamicCode::codeDirName().

Here is the caller graph for this function:

fileName libSubDir ( ) const
inline

Subdirectory name for loading libraries.

Expanded from platforms/$WM_OPTIONS/lib

Definition at line 207 of file dynamicCode.H.

Referenced by dynamicCode::codeDirName().

Here is the caller graph for this function:

fileName codePath ( ) const
inline

Path for specified code name.

Corresponds to codeRoot()/codeDirName()

Definition at line 214 of file dynamicCode.H.

Referenced by dynamicCode::codeDirName(), dynamicCode::copyOrCreateFiles(), dynamicCode::createMakeFiles(), dynamicCode::createMakeOptions(), and dynamicCode::wmakeLibso().

Here is the caller graph for this function:

fileName libPath ( ) const
inline

Library path for specified code name.

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

Definition at line 221 of file dynamicCode.H.

Referenced by dynamicCode::codeDirName().

Here is the caller graph for this function:

Foam::fileName codeRelPath ( ) const

Path for specified code name relative to $FOAM_CASE.

Corresponds to topDirName/codeDirName()

Definition at line 329 of file dynamicCode.C.

References dynamicCode::topDirName.

Referenced by dynamicCode::codeDirName(), and dynamicCode::libRelPath().

Here is the caller graph for this function:

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 335 of file dynamicCode.C.

References dynamicCode::codeRelPath().

Referenced by dynamicCode::codeDirName(), and dynamicCode::copyOrCreateFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

fileName digestFile ( ) const
inline

Path for SHA1Digest.

Corresponds to codePath()/Make/SHA1Digest

Definition at line 239 of file dynamicCode.H.

Referenced by dynamicCode::codeDirName(), dynamicCode::upToDate(), and dynamicCode::writeDigest().

Here is the caller graph for this function:

void clear ( )

Clear files and variables.

Definition at line 341 of file dynamicCode.C.

References dynamicCode::reset().

Referenced by dynamicCode::codeDirName(), dynamicCode::dynamicCode(), and dynamicCode::reset().

Here is the call graph for this function:

Here is the caller graph for this function:

void reset ( const dynamicCodeContext context)

Clear files and reset variables to specified context.

Definition at line 358 of file dynamicCode.C.

References dynamicCode::clear(), and dynamicCode::setFilterContext().

Referenced by dynamicCode::clear(), and dynamicCode::codeDirName().

Here is the call graph for this function:

Here is the caller graph for this function:

void addCompileFile ( const fileName name)

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

Definition at line 367 of file dynamicCode.C.

Referenced by dynamicCode::codeDirName(), codedFunctionObject::prepare(), and CodedSource< Type >::prepare().

Here is the caller graph for this function:

void addCopyFile ( const fileName name)

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

Definition at line 373 of file dynamicCode.C.

References dynamicCode::addCreateFile().

Referenced by dynamicCode::codeDirName(), codedFunctionObject::prepare(), and CodedSource< Type >::prepare().

Here is the call graph for this function:

Here is the caller graph for this function:

void addCreateFile ( const fileName name,
const string contents 
)

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

Definition at line 380 of file dynamicCode.C.

References dynamicCode::setFilterContext().

Referenced by dynamicCode::addCopyFile(), and dynamicCode::codeDirName().

Here is the call graph for this function:

Here is the caller graph for this function:

void setFilterContext ( const dynamicCodeContext context)

Define filter variables for code, codeInclude, SHA1sum.

Definition at line 390 of file dynamicCode.C.

References dynamicCodeContext::code(), dynamicCodeContext::include(), dynamicCodeContext::localCode(), dynamicCode::setFilterVariable(), dynamicCodeContext::sha1(), and SHA1Digest::str().

Referenced by dynamicCode::addCreateFile(), dynamicCode::codeDirName(), and dynamicCode::reset().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Define a filter variable.

Definition at line 402 of file dynamicCode.C.

Referenced by dynamicCode::codeDirName(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), and dynamicCode::setFilterContext().

Here is the caller graph for this function:

void setMakeOptions ( const std::string &  content)

Define contents for Make/options.

Definition at line 411 of file dynamicCode.C.

Referenced by dynamicCode::codeDirName(), codedFunctionObject::prepare(), and CodedSource< Type >::prepare().

Here is the caller graph for this function:

bool upToDate ( const dynamicCodeContext context) const

Verify if the copied code is up-to-date, based on Make/SHA1Digest.

Definition at line 552 of file dynamicCode.C.

References dynamicCodeContext::sha1().

Referenced by dynamicCode::codeDirName().

Here is the call graph for this function:

Here is the caller graph for this function:

bool upToDate ( const SHA1Digest sha1) const

Verify if the copied code is up-to-date, based on Make/SHA1Digest.

Definition at line 539 of file dynamicCode.C.

References dynamicCode::digestFile(), and Foam::exists().

Here is the call graph for this function:

bool copyOrCreateFiles ( const bool  verbose = false) const
bool wmakeLibso ( ) const

Compile a libso.

Definition at line 523 of file dynamicCode.C.

References dynamicCode::codePath(), Foam::endl(), Foam::Info, and Foam::system().

Referenced by dynamicCode::codeDirName().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const char *const libTargetRoot
staticprotected
Initial value:
=
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib"

Root of the LIB target for Make/files.

Definition at line 106 of file dynamicCode.H.

Referenced by dynamicCode::createMakeFiles().

const char *const topDirName = "dynamicCode"
staticprotected

Top-level directory name for copy/compiling.

Definition at line 109 of file dynamicCode.H.

Referenced by dynamicCode::codeRelPath().

const Foam::word codeTemplateEnvName = "FOAM_CODE_TEMPLATES"
static

Name of the code template environment variable.

Used to located the codeTemplateName

Definition at line 154 of file dynamicCode.H.

Referenced by dynamicCode::copyOrCreateFiles(), and dynamicCode::resolveTemplates().

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 158 of file dynamicCode.H.

Referenced by dynamicCode::copyOrCreateFiles(), and dynamicCode::resolveTemplates().

int allowSystemOperations
static

Flag if system operations are allowed.

Definition at line 161 of file dynamicCode.H.

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


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