mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: refactor codeStream code into codeStreamTools
This commit is contained in:
@ -115,29 +115,14 @@ bool Foam::functionEntries::codeStream::execute
|
||||
}
|
||||
|
||||
|
||||
// the code name = prefix + sha1
|
||||
const fileName codeName("codeStream_" + sha.str());
|
||||
// codeName = prefix + sha1
|
||||
const fileName codeName = "codeStream_" + sha.str();
|
||||
|
||||
// local directory for compile/link
|
||||
const fileName baseDir
|
||||
(
|
||||
stringOps::expandEnv("$FOAM_CASE/codeStream")
|
||||
);
|
||||
// write code into _SHA1 subdir
|
||||
const fileName codePath = codeStreamTools::codePath("_" + sha.str());
|
||||
|
||||
// code is written into _SHA1 subdir
|
||||
const fileName codeDir
|
||||
(
|
||||
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"
|
||||
);
|
||||
// write library into platforms/$WM_OPTIONS/lib subdir
|
||||
const fileName libPath = codeStreamTools::libPath(codeName);
|
||||
|
||||
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
@ -153,7 +138,7 @@ bool Foam::functionEntries::codeStream::execute
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (!codeStreamTools::upToDate(codeDir, sha))
|
||||
if (!codeStreamTools::upToDate(codePath, sha))
|
||||
{
|
||||
Info<< "Creating new library in " << libPath << endl;
|
||||
|
||||
@ -190,8 +175,7 @@ bool Foam::functionEntries::codeStream::execute
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
codeTemplateC + "\n\n"
|
||||
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib"
|
||||
+ codeName;
|
||||
+ codeStreamTools::libTarget(codeName);
|
||||
|
||||
// Write Make/options
|
||||
filesContents[1].first() = "Make/options";
|
||||
@ -201,7 +185,7 @@ bool Foam::functionEntries::codeStream::execute
|
||||
+ "\n\nLIB_LIBS =";
|
||||
|
||||
codeStreamTools writer(codeName, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(codeDir))
|
||||
if (!writer.copyFilesContents(codePath))
|
||||
{
|
||||
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;
|
||||
if (Foam::system(wmakeCmd))
|
||||
{
|
||||
|
||||
@ -49,6 +49,43 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
|
||||
|
||||
// * * * * * * * * * * * * * 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)
|
||||
{
|
||||
// try to get template from FOAM_CODESTREAM_TEMPLATES
|
||||
|
||||
@ -119,6 +119,7 @@ public:
|
||||
// Used when locating the codeTemplateName via Foam::findEtcFile
|
||||
static const fileName codeTemplateDirName;
|
||||
|
||||
|
||||
static int allowSystemOperations;
|
||||
|
||||
|
||||
@ -144,6 +145,35 @@ public:
|
||||
|
||||
// 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
|
||||
{
|
||||
return name_;
|
||||
@ -162,14 +192,6 @@ public:
|
||||
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 bool writeDigest(const fileName& dir, const SHA1Digest& sha1);
|
||||
|
||||
@ -80,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
(
|
||||
const fileName& codeDir,
|
||||
const fileName& codePath,
|
||||
const fileName& libPath,
|
||||
const dictionary& dict
|
||||
)
|
||||
@ -116,7 +116,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
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;
|
||||
|
||||
@ -152,8 +158,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
codeTemplateC + "\n\n"
|
||||
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib"
|
||||
+ redirectType_;
|
||||
+ codeStreamTools::libTarget(redirectType_);
|
||||
|
||||
// Write Make/options
|
||||
filesContents[1].first() = "Make/options";
|
||||
@ -164,7 +169,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
+ "\n\nLIB_LIBS = ";
|
||||
|
||||
codeStreamTools writer(redirectType_, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(codeDir))
|
||||
if (!writer.copyFilesContents(codePath))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
@ -194,32 +199,20 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// local directory for compile/link
|
||||
const fileName baseDir
|
||||
(
|
||||
stringOps::expandEnv("$FOAM_CASE/codeStream")
|
||||
);
|
||||
// write code into redirectType_ subdir
|
||||
const fileName codePath = codeStreamTools::codePath(redirectType_);
|
||||
|
||||
// code is written into redirectType_ subdir
|
||||
const fileName codeDir
|
||||
(
|
||||
baseDir
|
||||
/ redirectType_
|
||||
);
|
||||
// const fileName oldLibPath = codeStreamTools::libPath
|
||||
// (
|
||||
// redirectType_ + "_" + sha1_
|
||||
// );
|
||||
|
||||
// write library into platforms/$WM_OPTIONS/lib subdir
|
||||
const fileName libPath = codeStreamTools::libPath(redirectType_);
|
||||
|
||||
|
||||
//Info<< "codeDir:" << codeDir << 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;
|
||||
//Info<< "codePath:" << codePath << nl
|
||||
// << "libPath:" << libPath << endl;
|
||||
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
@ -227,7 +220,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
|
||||
{
|
||||
if (!lib)
|
||||
{
|
||||
writeLibrary(codeDir, libPath, dict_);
|
||||
writeLibrary(codePath, libPath, dict_);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -256,7 +249,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
const Foam::string wmakeCmd("wmake libso " + codeDir);
|
||||
const Foam::string wmakeCmd("wmake libso " + codePath);
|
||||
Info<< "Invoking " << wmakeCmd << endl;
|
||||
if (Foam::system(wmakeCmd))
|
||||
{
|
||||
|
||||
@ -58,7 +58,7 @@ Description
|
||||
|
||||
A special form is if the 'code' section is not supplied. In this case
|
||||
the code gets read from a (runTimeModifiable!) dictionary system/codeDict
|
||||
which would have an entry
|
||||
which would have a corresponding entry
|
||||
|
||||
\verbatim
|
||||
rampedFixedValue
|
||||
@ -82,6 +82,7 @@ SourceFiles
|
||||
#define codedFixedValueFvPatchScalarField_H
|
||||
|
||||
#include "fixedValueFvPatchFields.H"
|
||||
#include "SHA1Digest.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -100,8 +101,13 @@ class codedFixedValueFvPatchScalarField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Dictionary contents for the boundary condition
|
||||
mutable dictionary dict_;
|
||||
|
||||
//- SHA1Digest of the Dictionary contents
|
||||
// Currently unused, but useful for reloading?
|
||||
mutable SHA1Digest sha1_;
|
||||
|
||||
const word redirectType_;
|
||||
|
||||
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;
|
||||
|
||||
Reference in New Issue
Block a user