Skip to content

Commit

Permalink
delayed creation and update of .md5 files after successful creation o…
Browse files Browse the repository at this point in the history
…f output files
  • Loading branch information
Thomas Haller committed May 14, 2019
1 parent 577e3a1 commit 9dda0c6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
88 changes: 48 additions & 40 deletions src/dot.cpp
Expand Up @@ -764,11 +764,10 @@ static void calculateMd5Signature(QGString const & theGraph, QCString & sigStr)
}

/*! Checks if a file "baseName".md5 exists. If so the contents
* are compared with \a md5. If equal FALSE is returned. If the .md5
* file does not exist or its contents are not equal to \a md5,
* a new .md5 is generated with the \a md5 string as contents.
* are compared with \a md5. If equal FALSE is returned.
* The .md5 is created or updated after successful creation of the output file.
*/
static bool checkAndUpdateMd5Signature(const QCString &baseName,
static bool checkMd5Signature(const QCString &baseName,
const QCString &md5)
{
QFile f(baseName+".md5");
Expand All @@ -786,12 +785,6 @@ static bool checkAndUpdateMd5Signature(const QCString &baseName,
}
}
f.close();
// create checksum file
if (f.open(IO_WriteOnly))
{
f.writeBlock(md5.data(),32);
f.close();
}
return TRUE;
}

Expand Down Expand Up @@ -830,12 +823,12 @@ int DotNodeList::compareValues(const DotNode *n1,const DotNode *n2) const

//--------------------------------------------------------------------

DotRunner::DotRunner(const QCString &file,const QCString &path,
bool checkResult,const QCString &imageName)
DotRunner::DotRunner(const QCString& baseName, const QCString& path, const QCString& md5Hash,
bool checkResult, const QCString& imageName)
: m_dotExe(Config_getString(DOT_PATH)+"dot"),
m_file(file), m_path(path),
m_baseName(baseName), m_path(path),
m_checkResult(checkResult), m_imageName(imageName),
m_imgExt(getDotImageExtension())
m_imgExt(getDotImageExtension()), m_md5Hash(md5Hash)
{
static bool dotCleanUp = Config_getBool(DOT_CLEANUP);
static bool dotMultiTargets = Config_getBool(DOT_MULTI_TARGETS);
Expand Down Expand Up @@ -866,14 +859,14 @@ bool DotRunner::run()
DotConstString *s;
if (m_multiTargets)
{
dotArgs=QCString("\"")+m_file.data()+"\"";
dotArgs=QCString("\"")+m_baseName.data()+".dot\"";
for (li.toFirst();(s=li.current());++li)
{
dotArgs+=' ';
dotArgs+=s->data();
}
if ((exitCode=portable_system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error;
dotArgs=QCString("\"")+m_file.data()+"\"";
dotArgs=QCString("\"")+m_baseName.data()+".dot\"";
bool redo = FALSE;
for (li.toFirst();(s=li.current());++li)
{
Expand All @@ -898,7 +891,7 @@ bool DotRunner::run()
{
for (li.toFirst();(s=li.current());++li)
{
dotArgs=QCString("\"")+m_file.data()+"\" "+s->data();
dotArgs=QCString("\"")+m_baseName.data()+".dot\" "+s->data();
if ((exitCode=portable_system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error;
if (s->pdfData())
{
Expand All @@ -924,9 +917,18 @@ bool DotRunner::run()
{
//printf("removing dot file %s\n",m_file.data());
//QDir(path).remove(file);
m_cleanupItem.file.set(m_file.data());
m_cleanupItem.file.set((QCString(m_baseName.data()) + ".dot").data());
m_cleanupItem.path.set(m_path.data());
}
if (!m_md5Hash.isEmpty()) {
// create checksum file
QFile f(QCString(m_baseName.data())+".md5");
if (f.open(IO_WriteOnly))
{
f.writeBlock(m_md5Hash.data(),32);
f.close();
}
}
return TRUE;
error:
err("Problems running dot: exit code=%d, command='%s', arguments='%s'\n",
Expand Down Expand Up @@ -2404,7 +2406,7 @@ void DotGfxHierarchyTable::createGraph(DotNode *n,FTextStream &out,
calculateMd5Signature(theGraph, sigStr);

bool regenerate=FALSE;
if (checkAndUpdateMd5Signature(absBaseName,sigStr) ||
if (checkMd5Signature(absBaseName,sigStr) ||
!checkDeliverables(absImgName,absMapName))
{
regenerate=TRUE;
Expand All @@ -2416,7 +2418,7 @@ void DotGfxHierarchyTable::createGraph(DotNode *n,FTextStream &out,
t << theGraph;
f.close();

DotRunner *dotRun = new DotRunner(dotName,d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName,d.absPath().data(),sigStr,TRUE,absImgName);
dotRun->addJob(imgFmt,absImgName);
dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);
Expand Down Expand Up @@ -3190,12 +3192,13 @@ static bool updateDotGraph(DotNode *root,
const QCString &rank,
bool renderParents,
bool backArrows,
QCString & md5,
const QCString &title=QCString()
)
{
QCString theGraph;
// TODO: write graph to theGraph, then compute md5 checksum
QCString md5 = computeMd5Signature(
md5 = computeMd5Signature(
root,gt,format,rank,renderParents,
backArrows,title,theGraph);
QFile f(baseName+".dot");
Expand All @@ -3204,7 +3207,7 @@ static bool updateDotGraph(DotNode *root,
FTextStream t(&f);
t << theGraph;
}
return checkAndUpdateMd5Signature(baseName,md5); // graph needs to be regenerated
return checkMd5Signature(baseName,md5); // graph needs to be regenerated
}

QCString DotClassGraph::writeGraph(FTextStream &out,
Expand Down Expand Up @@ -3253,13 +3256,15 @@ QCString DotClassGraph::writeGraph(FTextStream &out,
QCString absImgName = absBaseName+"."+imgExt;

bool regenerate = FALSE;
QCString md5;
if (updateDotGraph(m_startNode,
m_graphType,
absBaseName,
graphFormat,
m_lrRank ? "LR" : "",
m_graphType==DotNode::Inheritance,
TRUE,
md5,
m_startNode->label()
) ||
!checkDeliverables(graphFormat==GOF_BITMAP ? absImgName :
Expand All @@ -3270,16 +3275,16 @@ QCString DotClassGraph::writeGraph(FTextStream &out,
regenerate=TRUE;
if (graphFormat==GOF_BITMAP) // run dot to create a bitmap image
{
DotRunner *dotRun = new DotRunner(absDotName,
d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName,
d.absPath().data(), md5, TRUE,absImgName);
dotRun->addJob(imgFmt,absImgName);
if (generateImageMap) dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);

}
else if (graphFormat==GOF_EPS) // run dot to create a .eps image
{
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), md5, FALSE);
if (usePDFLatex)
{
dotRun->addJob("pdf",absPdfName,absBaseName);
Expand Down Expand Up @@ -3599,13 +3604,15 @@ QCString DotInclDepGraph::writeGraph(FTextStream &out,
QCString absImgName = absBaseName+"."+imgExt;

bool regenerate = FALSE;
QCString md5;
if (updateDotGraph(m_startNode,
DotNode::Dependency,
absBaseName,
graphFormat,
"", // lrRank
FALSE, // renderParents
m_inverse, // backArrows
md5,
m_startNode->label()
) ||
!checkDeliverables(graphFormat==GOF_BITMAP ? absImgName :
Expand All @@ -3617,14 +3624,14 @@ QCString DotInclDepGraph::writeGraph(FTextStream &out,
if (graphFormat==GOF_BITMAP)
{
// run dot to create a bitmap image
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), md5, TRUE, absImgName);
dotRun->addJob(imgFmt,absImgName);
if (generateImageMap) dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);
}
else if (graphFormat==GOF_EPS)
{
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), md5, FALSE);
if (usePDFLatex)
{
dotRun->addJob("pdf",absPdfName,absBaseName);
Expand Down Expand Up @@ -3914,14 +3921,15 @@ QCString DotCallGraph::writeGraph(FTextStream &out, GraphOutputFormat graphForma
QCString absImgName = absBaseName+"."+imgExt;

bool regenerate = FALSE;

QCString md5;
if (updateDotGraph(m_startNode,
DotNode::CallGraph,
absBaseName,
graphFormat,
m_inverse ? "RL" : "LR", // lrRank
FALSE, // renderParents
m_inverse, // backArrows
md5,
m_startNode->label()
) ||
!checkDeliverables(graphFormat==GOF_BITMAP ? absImgName :
Expand All @@ -3933,7 +3941,7 @@ QCString DotCallGraph::writeGraph(FTextStream &out, GraphOutputFormat graphForma
if (graphFormat==GOF_BITMAP)
{
// run dot to create a bitmap image
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), md5, TRUE, absImgName);
dotRun->addJob(imgFmt,absImgName);
if (generateImageMap) dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);
Expand All @@ -3942,7 +3950,7 @@ QCString DotCallGraph::writeGraph(FTextStream &out, GraphOutputFormat graphForma
else if (graphFormat==GOF_EPS)
{
// run dot to create a .eps image
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), md5, FALSE);
if (usePDFLatex)
{
dotRun->addJob("pdf",absPdfName,absBaseName);
Expand Down Expand Up @@ -4077,7 +4085,7 @@ QCString DotDirDeps::writeGraph(FTextStream &out,
QCString sigStr(33);
calculateMd5Signature(theGraph, sigStr);
bool regenerate=FALSE;
if (checkAndUpdateMd5Signature(absBaseName,sigStr) ||
if (checkMd5Signature(absBaseName,sigStr) ||
!checkDeliverables(graphFormat==GOF_BITMAP ? absImgName :
usePDFLatex ? absPdfName : absEpsName,
graphFormat==GOF_BITMAP && generateImageMap ? absMapName : QCString())
Expand All @@ -4097,14 +4105,14 @@ QCString DotDirDeps::writeGraph(FTextStream &out,
if (graphFormat==GOF_BITMAP)
{
// run dot to create a bitmap image
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), sigStr, TRUE, absImgName);
dotRun->addJob(imgFmt,absImgName);
if (generateImageMap) dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);
}
else if (graphFormat==GOF_EPS)
{
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(), sigStr, FALSE);
if (usePDFLatex)
{
dotRun->addJob("pdf",absPdfName,absBaseName);
Expand Down Expand Up @@ -4223,7 +4231,7 @@ void generateGraphLegend(const char *path)
QCString imgFmt = Config_getEnum(DOT_IMAGE_FORMAT);
QCString imgName = "graph_legend."+imgExt;
QCString absImgName = absBaseName+"."+imgExt;
if (checkAndUpdateMd5Signature(absBaseName,sigStr) ||
if (checkMd5Signature(absBaseName,sigStr) ||
!checkDeliverables(absImgName))
{
QFile dotFile(absDotName);
Expand All @@ -4239,7 +4247,7 @@ void generateGraphLegend(const char *path)

// run dot to generate the a bitmap image from the graph

DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),TRUE,absImgName);
DotRunner *dotRun = new DotRunner(absBaseName, d.absPath().data(),sigStr,TRUE,absImgName);
dotRun->addJob(imgFmt,absImgName);
DotManager::instance()->addRun(dotRun);
}
Expand Down Expand Up @@ -4274,7 +4282,7 @@ void writeDotGraphFromFile(const char *inFile,const char *outDir,
QCString absImgName = d.absPath().utf8()+"/"+imgName;
QCString absOutFile = d.absPath().utf8()+"/"+outFile;

DotRunner dotRun(inFile,d.absPath().data(),FALSE,absImgName);
DotRunner dotRun(inFile,d.absPath().data(),QCString(),FALSE,absImgName);
if (format==GOF_BITMAP)
dotRun.addJob(imgFmt,absImgName);
else // format==GOF_EPS
Expand Down Expand Up @@ -4329,7 +4337,7 @@ void writeDotImageMapFromFile(FTextStream &t,
QCString imgName = baseName+"."+imgExt;
QCString absOutFile = d.absPath().utf8()+"/"+mapName;

DotRunner dotRun(inFile,d.absPath().data(),FALSE);
DotRunner dotRun(baseName,d.absPath().data(),QCString(),FALSE);
dotRun.addJob(MAP_CMD,absOutFile);
dotRun.preventCleanUp();
if (!dotRun.run())
Expand Down Expand Up @@ -4641,7 +4649,7 @@ QCString DotGroupCollaboration::writeGraph( FTextStream &t,
QCString absPdfName = absBaseName+".pdf";
QCString absEpsName = absBaseName+".eps";
bool regenerate=FALSE;
if (checkAndUpdateMd5Signature(absBaseName,sigStr) ||
if (checkMd5Signature(absBaseName,sigStr) ||
!checkDeliverables(graphFormat==GOF_BITMAP ? absImgName :
usePDFLatex ? absPdfName : absEpsName,
graphFormat==GOF_BITMAP /*&& generateImageMap*/ ? absMapName : QCString())
Expand All @@ -4659,15 +4667,15 @@ QCString DotGroupCollaboration::writeGraph( FTextStream &t,

if (graphFormat==GOF_BITMAP) // run dot to create a bitmap image
{
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName,d.absPath().data(),sigStr,FALSE);
dotRun->addJob(imgFmt,absImgName);
if (writeImageMap) dotRun->addJob(MAP_CMD,absMapName);
DotManager::instance()->addRun(dotRun);

}
else if (graphFormat==GOF_EPS)
{
DotRunner *dotRun = new DotRunner(absDotName,d.absPath().data(),FALSE);
DotRunner *dotRun = new DotRunner(absBaseName,d.absPath().data(),sigStr,FALSE);
if (usePDFLatex)
{
dotRun->addJob("pdf",absPdfName,absBaseName);
Expand Down
7 changes: 4 additions & 3 deletions src/dot.h
Expand Up @@ -393,8 +393,8 @@ class DotRunner
};

/** Creates a runner for a dot \a file. */
DotRunner(const QCString &file,const QCString &fontPath,bool checkResult,
const QCString &imageName = QCString());
DotRunner(const QCString& baseName, const QCString& path, const QCString& md5Hash,
bool checkResult, const QCString &imageName = QCString());

/** Adds an additional job to the run.
* Performing multiple jobs one file can be faster.
Expand All @@ -415,13 +415,14 @@ class DotRunner
QList<DotConstString> m_jobs;
DotConstString m_postArgs;
DotConstString m_postCmd;
DotConstString m_file;
DotConstString m_baseName;
DotConstString m_path;
bool m_checkResult;
DotConstString m_imageName;
DotConstString m_imgExt;
bool m_cleanUp;
CleanupItem m_cleanupItem;
DotConstString m_md5Hash;
};

/** Helper class to insert a set of map file into an output file */
Expand Down

0 comments on commit 9dda0c6

Please sign in to comment.