ENH: compile codedFixedValueFvPatchScalarField into local directory only

This commit is contained in:
Mark Olesen
2011-02-22 16:25:34 +01:00
parent 141fe37a86
commit dce20ade07
5 changed files with 103 additions and 85 deletions

View File

@ -106,7 +106,7 @@ bool Foam::functionEntries::codeStream::execute
// "code" is mandatory
string code = stringOps::trimLeft(codeDict["code"]);
// Create name from the contents
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
@ -196,7 +196,9 @@ bool Foam::functionEntries::codeStream::execute
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g \\\n" + codeOptions + "\n\nLIB_LIBS =";
"EXE_INC = -g \\\n"
+ codeOptions
+ "\n\nLIB_LIBS =";
codeStreamTools writer(codeName, copyFiles, filesContents);
if (!writer.copyFilesContents(codeDir))
@ -225,8 +227,8 @@ bool Foam::functionEntries::codeStream::execute
}
}
bool dummy = true;
reduce(dummy, orOp<bool>());
// bool dummy = true;
// reduce(dummy, orOp<bool>());
if (!dlLibraryTable::open(libPath, false))
{

View File

@ -29,7 +29,7 @@ Description
generate the entry itself. So
- codeStream reads three entries: 'code', 'codeInclude' (optional),
'codeOptions' (optional)
and uses those to generate library sources inside \f constant/codeStream/
and uses those to generate library sources inside \f codeStream/
- these get compiled using 'wmake libso'
- the resulting library is loaded in executed with as arguments
\code
@ -123,7 +123,7 @@ public:
// Static data members
//- Name of the C code template to be used
const static word codeTemplateC;
static const word codeTemplateC;
//- Runtime type information

View File

@ -113,15 +113,15 @@ public:
//- Name of the code template environment variable
// Used to located the codeTemplateName
const static word codeTemplateEnvName;
static const word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
const static fileName codeTemplateDirName;
static const fileName codeTemplateDirName;
static int allowSystemOperations;
// Constructors
//- Construct null

View File

@ -79,7 +79,7 @@ public:
modified_ = false;
}
//- Read the solution dictionary
//- Read the dictionary
virtual bool read();
};

View File

@ -32,6 +32,8 @@ License
#include "dlLibraryTable.H"
#include "IFstream.H"
#include "OFstream.H"
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "codeProperties.H"
#include "stringOps.H"
@ -78,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
void Foam::codedFixedValueFvPatchScalarField::writeLibrary
(
const fileName& dir,
const fileName& codeDir,
const fileName& libPath,
const dictionary& dict
)
@ -106,25 +108,22 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
// "code" is mandatory
string code = stringOps::trimLeft(dict["code"]);
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
os << codeInclude << codeOptions << code;
sha = os.digest();
}
if (!codeStreamTools::upToDate(codeDir, sha))
{
Info<< "Creating new library in " << libPath << endl;
const fileName fileCsrc
(
codeStreamTools::findTemplate
(
codeTemplateC
)
);
const fileName fileHsrc
(
codeStreamTools::findTemplate
(
codeTemplateH
)
);
const fileName fileCsrc(codeStreamTools::findTemplate(codeTemplateC));
const fileName fileHsrc(codeStreamTools::findTemplate(codeTemplateH));
// not found!
if (fileCsrc.empty() || fileHsrc.empty())
{
FatalIOErrorIn
@ -153,17 +152,19 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
filesContents[0].first() = "Make/files";
filesContents[0].second() =
codeTemplateC + "\n\n"
"LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_;
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib"
+ redirectType_;
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g \\\n-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
"EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
+ codeOptions
+ "\n\nLIB_LIBS = ";
codeStreamTools writer(redirectType_, copyFiles, filesContents);
if (!writer.copyFilesContents(dir))
if (!writer.copyFilesContents(codeDir))
{
FatalIOErrorIn
(
@ -175,6 +176,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
<< exit(FatalIOError);
}
}
}
void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
@ -192,17 +194,31 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
<< exit(FatalIOError);
}
const fileName dir =
db().time().constantPath()/"codeStream"/redirectType_;
//Info<< "dir:" << dir << endl;
// local directory for compile/link
const fileName baseDir
(
stringOps::expandEnv("$FOAM_CASE/codeStream")
);
// code is written into redirectType_ subdir
const fileName codeDir
(
baseDir
/ redirectType_
);
//Info<< "codeDir:" << codeDir << endl;
// library is written into platforms/$WM_OPTIONS/lib subdir
const fileName libPath
(
Foam::getEnv("FOAM_USER_LIBBIN")
/ "lib"
+ redirectType_
+ ".so"
baseDir
/ stringOps::expandEnv("platforms/$WM_OPTIONS/lib")
/ "lib" + redirectType_ + ".so"
);
//Info<< "libPath:" << libPath << endl;
void* lib = dlLibraryTable::findLibrary(libPath);
@ -211,7 +227,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{
if (!lib)
{
writeLibrary(dir, libPath, dict_);
writeLibrary(codeDir, libPath, dict_);
}
}
else
@ -240,7 +256,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
}
const dictionary& codeDict = onTheFlyDict.subDict(redirectType_);
writeLibrary(dir, libPath, codeDict);
writeLibrary(codeDir, libPath, codeDict);
}
}
@ -248,7 +264,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{
if (Pstream::master())
{
const Foam::string wmakeCmd("wmake libso " + dir);
const Foam::string wmakeCmd("wmake libso " + codeDir);
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
{