STYLE: refactor codeStream code into codeStreamTools

This commit is contained in:
Mark Olesen
2011-02-22 18:22:57 +01:00
parent dce20ade07
commit 70f359bb2b
5 changed files with 108 additions and 66 deletions

View File

@ -115,29 +115,14 @@ bool Foam::functionEntries::codeStream::execute
} }
// the code name = prefix + sha1 // codeName = prefix + sha1
const fileName codeName("codeStream_" + sha.str()); const fileName codeName = "codeStream_" + sha.str();
// local directory for compile/link // write code into _SHA1 subdir
const fileName baseDir const fileName codePath = codeStreamTools::codePath("_" + sha.str());
(
stringOps::expandEnv("$FOAM_CASE/codeStream")
);
// code is written into _SHA1 subdir // write library into platforms/$WM_OPTIONS/lib subdir
const fileName codeDir const fileName libPath = codeStreamTools::libPath(codeName);
(
baseDir
/ "_" + sha.str()
);
// library is written into platforms/$WM_OPTIONS/lib subdir
const fileName libPath
(
baseDir
/ stringOps::expandEnv("platforms/$WM_OPTIONS/lib")
/ "lib" + codeName + ".so"
);
void* lib = dlLibraryTable::findLibrary(libPath); void* lib = dlLibraryTable::findLibrary(libPath);
@ -153,7 +138,7 @@ bool Foam::functionEntries::codeStream::execute
{ {
if (Pstream::master()) if (Pstream::master())
{ {
if (!codeStreamTools::upToDate(codeDir, sha)) if (!codeStreamTools::upToDate(codePath, sha))
{ {
Info<< "Creating new library in " << libPath << endl; Info<< "Creating new library in " << libPath << endl;
@ -190,8 +175,7 @@ bool Foam::functionEntries::codeStream::execute
filesContents[0].first() = "Make/files"; filesContents[0].first() = "Make/files";
filesContents[0].second() = filesContents[0].second() =
codeTemplateC + "\n\n" codeTemplateC + "\n\n"
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeStreamTools::libTarget(codeName);
+ codeName;
// Write Make/options // Write Make/options
filesContents[1].first() = "Make/options"; filesContents[1].first() = "Make/options";
@ -201,7 +185,7 @@ bool Foam::functionEntries::codeStream::execute
+ "\n\nLIB_LIBS ="; + "\n\nLIB_LIBS =";
codeStreamTools writer(codeName, copyFiles, filesContents); codeStreamTools writer(codeName, copyFiles, filesContents);
if (!writer.copyFilesContents(codeDir)) if (!writer.copyFilesContents(codePath))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
@ -214,7 +198,7 @@ bool Foam::functionEntries::codeStream::execute
} }
} }
const Foam::string wmakeCmd("wmake libso " + codeDir); const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl; Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd)) if (Foam::system(wmakeCmd))
{ {

View File

@ -49,6 +49,43 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::codeStreamTools::baseDir()
{
return stringOps::expandEnv("$FOAM_CASE/codeStream");
}
Foam::fileName Foam::codeStreamTools::libSubDir()
{
return stringOps::expandEnv("platforms/$WM_OPTIONS/lib");
}
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/" + subDirName
);
}
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
+ codeName + ".so"
);
}
Foam::string Foam::codeStreamTools::libTarget(const word& codeName)
{
return "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeName;
}
Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile) Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile)
{ {
// try to get template from FOAM_CODESTREAM_TEMPLATES // try to get template from FOAM_CODESTREAM_TEMPLATES

View File

@ -119,6 +119,7 @@ public:
// Used when locating the codeTemplateName via Foam::findEtcFile // Used when locating the codeTemplateName via Foam::findEtcFile
static const fileName codeTemplateDirName; static const fileName codeTemplateDirName;
static int allowSystemOperations; static int allowSystemOperations;
@ -144,6 +145,35 @@ public:
// Member functions // Member functions
//- Directory for compile/link (case-specific)
// Expanded from \$FOAM_CASE/codeStream
static fileName baseDir();
//- Subdirectory name for library
// Expanded from platforms/\$WM_OPTIONS/lib
static fileName libSubDir();
//- Local path for specified code name
// Expanded from \$FOAM_CASE/codeStream
static fileName codePath(const word& subDirName);
//- Local library path for specified code name
// Expanded from \$FOAM_CASE/platforms/\$WM_OPTIONS/lib
static fileName libPath(const word& codeName);
//- The library target path for Make/files
static string libTarget(const word& codeName);
//- Find a code-template via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static fileName findTemplate(const word& templateName);
//- List searched locations in a format suitable for display an error
static string searchedLocations();
const word& name() const const word& name() const
{ {
return name_; return name_;
@ -162,14 +192,6 @@ public:
bool copyFilesContents(const fileName& dir) const; bool copyFilesContents(const fileName& dir) const;
//- Find a code-template via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static fileName findTemplate(const word& templateName);
//- List searched locations in a format suitable for display an error
static string searchedLocations();
static void* findLibrary(const fileName& libPath); static void* findLibrary(const fileName& libPath);
static bool writeDigest(const fileName& dir, const SHA1Digest& sha1); static bool writeDigest(const fileName& dir, const SHA1Digest& sha1);

View File

@ -80,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
void Foam::codedFixedValueFvPatchScalarField::writeLibrary void Foam::codedFixedValueFvPatchScalarField::writeLibrary
( (
const fileName& codeDir, const fileName& codePath,
const fileName& libPath, const fileName& libPath,
const dictionary& dict const dictionary& dict
) )
@ -116,7 +116,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
sha = os.digest(); sha = os.digest();
} }
if (!codeStreamTools::upToDate(codeDir, sha)) // Info<<"old SHA1: " << sha1_ << nl
// <<"new SHA1: " << sha << endl;
// (void) codeStreamTools::upToDate(codePath, sha)
// TODO: compile on-demand
if (true)
{ {
Info<< "Creating new library in " << libPath << endl; Info<< "Creating new library in " << libPath << endl;
@ -152,8 +158,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
filesContents[0].first() = "Make/files"; filesContents[0].first() = "Make/files";
filesContents[0].second() = filesContents[0].second() =
codeTemplateC + "\n\n" codeTemplateC + "\n\n"
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeStreamTools::libTarget(redirectType_);
+ redirectType_;
// Write Make/options // Write Make/options
filesContents[1].first() = "Make/options"; filesContents[1].first() = "Make/options";
@ -164,7 +169,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
+ "\n\nLIB_LIBS = "; + "\n\nLIB_LIBS = ";
codeStreamTools writer(redirectType_, copyFiles, filesContents); codeStreamTools writer(redirectType_, copyFiles, filesContents);
if (!writer.copyFilesContents(codeDir)) if (!writer.copyFilesContents(codePath))
{ {
FatalIOErrorIn FatalIOErrorIn
( (
@ -194,32 +199,20 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
<< exit(FatalIOError); << exit(FatalIOError);
} }
// local directory for compile/link // write code into redirectType_ subdir
const fileName baseDir const fileName codePath = codeStreamTools::codePath(redirectType_);
(
stringOps::expandEnv("$FOAM_CASE/codeStream")
);
// code is written into redirectType_ subdir // const fileName oldLibPath = codeStreamTools::libPath
const fileName codeDir // (
( // redirectType_ + "_" + sha1_
baseDir // );
/ redirectType_
); // write library into platforms/$WM_OPTIONS/lib subdir
const fileName libPath = codeStreamTools::libPath(redirectType_);
//Info<< "codeDir:" << codeDir << endl; //Info<< "codePath:" << codePath << nl
// << "libPath:" << libPath << endl;
// library is written into platforms/$WM_OPTIONS/lib subdir
const fileName libPath
(
baseDir
/ stringOps::expandEnv("platforms/$WM_OPTIONS/lib")
/ "lib" + redirectType_ + ".so"
);
//Info<< "libPath:" << libPath << endl;
void* lib = dlLibraryTable::findLibrary(libPath); void* lib = dlLibraryTable::findLibrary(libPath);
@ -227,7 +220,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{ {
if (!lib) if (!lib)
{ {
writeLibrary(codeDir, libPath, dict_); writeLibrary(codePath, libPath, dict_);
} }
} }
else else
@ -256,7 +249,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
} }
const dictionary& codeDict = onTheFlyDict.subDict(redirectType_); const dictionary& codeDict = onTheFlyDict.subDict(redirectType_);
writeLibrary(codeDir, libPath, codeDict); writeLibrary(codePath, libPath, codeDict);
} }
} }
@ -264,7 +257,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{ {
if (Pstream::master()) if (Pstream::master())
{ {
const Foam::string wmakeCmd("wmake libso " + codeDir); const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl; Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd)) if (Foam::system(wmakeCmd))
{ {

View File

@ -58,7 +58,7 @@ Description
A special form is if the 'code' section is not supplied. In this case A special form is if the 'code' section is not supplied. In this case
the code gets read from a (runTimeModifiable!) dictionary system/codeDict the code gets read from a (runTimeModifiable!) dictionary system/codeDict
which would have an entry which would have a corresponding entry
\verbatim \verbatim
rampedFixedValue rampedFixedValue
@ -82,6 +82,7 @@ SourceFiles
#define codedFixedValueFvPatchScalarField_H #define codedFixedValueFvPatchScalarField_H
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchFields.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -100,8 +101,13 @@ class codedFixedValueFvPatchScalarField
{ {
// Private data // Private data
//- Dictionary contents for the boundary condition
mutable dictionary dict_; mutable dictionary dict_;
//- SHA1Digest of the Dictionary contents
// Currently unused, but useful for reloading?
mutable SHA1Digest sha1_;
const word redirectType_; const word redirectType_;
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_; mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;