mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: compile codedFixedValueFvPatchScalarField into local directory only
This commit is contained in:
@ -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))
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -44,7 +44,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codeProperties Declaration
|
||||
Class codeProperties Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codeProperties
|
||||
@ -79,7 +79,7 @@ public:
|
||||
modified_ = false;
|
||||
}
|
||||
|
||||
//- Read the solution dictionary
|
||||
//- Read the dictionary
|
||||
virtual bool read();
|
||||
|
||||
};
|
||||
|
||||
@ -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,73 +108,73 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
// "code" is mandatory
|
||||
string code = stringOps::trimLeft(dict["code"]);
|
||||
|
||||
|
||||
Info<< "Creating new library in " << libPath << endl;
|
||||
|
||||
const fileName fileCsrc
|
||||
(
|
||||
codeStreamTools::findTemplate
|
||||
(
|
||||
codeTemplateC
|
||||
)
|
||||
);
|
||||
|
||||
const fileName fileHsrc
|
||||
(
|
||||
codeStreamTools::findTemplate
|
||||
(
|
||||
codeTemplateH
|
||||
)
|
||||
);
|
||||
|
||||
if (fileCsrc.empty() || fileHsrc.empty())
|
||||
// Create SHA1 digest from the contents
|
||||
SHA1Digest sha;
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Could not find one or both code templates: "
|
||||
<< codeTemplateC << ", " << codeTemplateH << nl
|
||||
<< codeStreamTools::searchedLocations()
|
||||
<< exit(FatalIOError);
|
||||
OSHA1stream os;
|
||||
os << codeInclude << codeOptions << code;
|
||||
sha = os.digest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<codeStreamTools::fileAndVars> copyFiles(2);
|
||||
copyFiles[0].file() = fileCsrc;
|
||||
copyFiles[0].set("codeInclude", codeInclude);
|
||||
copyFiles[0].set("code", code);
|
||||
|
||||
copyFiles[1].file() = fileHsrc;
|
||||
|
||||
|
||||
List<codeStreamTools::fileAndContent> filesContents(2);
|
||||
|
||||
// Write Make/files
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
codeTemplateC + "\n\n"
|
||||
"LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_;
|
||||
|
||||
// Write Make/options
|
||||
filesContents[1].first() = "Make/options";
|
||||
filesContents[1].second() =
|
||||
"EXE_INC = -g \\\n-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
|
||||
+ codeOptions
|
||||
+ "\n\nLIB_LIBS = ";
|
||||
|
||||
codeStreamTools writer(redirectType_, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(dir))
|
||||
if (!codeStreamTools::upToDate(codeDir, sha))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Failed writing " << nl
|
||||
<< copyFiles << nl
|
||||
<< filesContents
|
||||
<< exit(FatalIOError);
|
||||
Info<< "Creating new library in " << libPath << endl;
|
||||
|
||||
const fileName fileCsrc(codeStreamTools::findTemplate(codeTemplateC));
|
||||
const fileName fileHsrc(codeStreamTools::findTemplate(codeTemplateH));
|
||||
|
||||
// not found!
|
||||
if (fileCsrc.empty() || fileHsrc.empty())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Could not find one or both code templates: "
|
||||
<< codeTemplateC << ", " << codeTemplateH << nl
|
||||
<< codeStreamTools::searchedLocations()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<codeStreamTools::fileAndVars> copyFiles(2);
|
||||
copyFiles[0].file() = fileCsrc;
|
||||
copyFiles[0].set("codeInclude", codeInclude);
|
||||
copyFiles[0].set("code", code);
|
||||
|
||||
copyFiles[1].file() = fileHsrc;
|
||||
|
||||
|
||||
List<codeStreamTools::fileAndContent> filesContents(2);
|
||||
|
||||
// Write Make/files
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
codeTemplateC + "\n\n"
|
||||
"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"
|
||||
+ codeOptions
|
||||
+ "\n\nLIB_LIBS = ";
|
||||
|
||||
codeStreamTools writer(redirectType_, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(codeDir))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Failed writing " << nl
|
||||
<< copyFiles << nl
|
||||
<< filesContents
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user