Skip to content

Commit

Permalink
bug_674442 CREATE_FOLDERS should not create unused folders
Browse files Browse the repository at this point in the history
Also known as issue #4672

The folders are still created but in case the folders are empty after the doxygen run the directories are removed.
  • Loading branch information
albert-github committed Jun 12, 2021
1 parent 8c8a034 commit f366804
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dir.cpp
Expand Up @@ -200,6 +200,13 @@ bool Dir::exists() const
return fi.exists() && fi.isDir();
}

bool Dir::isEmpty(const std::string subdir) const
{
fs::path pth = path();
pth /= subdir;
return fs::is_empty(pth);
}

bool Dir::isRelative() const
{
return isRelativePath(p->path.string());
Expand Down
1 change: 1 addition & 0 deletions src/dir.h
Expand Up @@ -78,6 +78,7 @@ class Dir final

DirIterator iterator() const;

bool Dir::isEmpty(const std::string subdir) const;
bool exists() const;
std::string filePath(const std::string &path,bool acceptsAbsPath=true) const;
bool exists(const std::string &path,bool acceptsAbsPath=true) const;
Expand Down
7 changes: 7 additions & 0 deletions src/docbookgen.cpp
Expand Up @@ -313,6 +313,13 @@ void DocbookGenerator::init()

createSubDirs(d);
}
void DocbookGenerator::cleanup()
{
QCString dname = Config_getString(DOCBOOK_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}


void DocbookGenerator::startFile(const QCString &name,const QCString &,const QCString &,int)
{
Expand Down
1 change: 1 addition & 0 deletions src/docbookgen.h
Expand Up @@ -99,6 +99,7 @@ class DocbookGenerator : public OutputGenerator
virtual std::unique_ptr<OutputGenerator> clone() const;

static void init();
void cleanup();

OutputType type() const { return Docbook; }

Expand Down
2 changes: 2 additions & 0 deletions src/doxygen.cpp
Expand Up @@ -12144,6 +12144,8 @@ void generateOutput()
g_s.end();
}

g_outputList->cleanup();

int cacheParam;
msg("lookup cache used %zu/%zu hits=%" PRIu64 " misses=%" PRIu64 "\n",
Doxygen::lookupCache->size(),
Expand Down
8 changes: 8 additions & 0 deletions src/htmlgen.cpp
Expand Up @@ -971,6 +971,7 @@ void HtmlGenerator::init()
{
mgr.copyResource("svgpan.js",dname);
}

if (!Config_getBool(DISABLE_INDEX) && Config_getBool(HTML_DYNAMIC_MENUS))
{
mgr.copyResource("menu.js",dname);
Expand All @@ -990,6 +991,13 @@ void HtmlGenerator::init()
}
}

void HtmlGenerator::cleanup()
{
QCString dname = Config_getString(HTML_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}

/// Additional initialization after indices have been created
void HtmlGenerator::writeTabData()
{
Expand Down
1 change: 1 addition & 0 deletions src/htmlgen.h
Expand Up @@ -73,6 +73,7 @@ class HtmlGenerator : public OutputGenerator

virtual OutputType type() const { return Html; }
static void init();
void cleanup();
static void writeStyleSheetFile(TextStream &t);
static void writeHeaderFile(TextStream &t, const QCString &cssname);
static void writeFooterFile(TextStream &t);
Expand Down
7 changes: 7 additions & 0 deletions src/latexgen.cpp
Expand Up @@ -494,6 +494,13 @@ void LatexGenerator::init()
createSubDirs(d);
}

void LatexGenerator::cleanup()
{
QCString dname = Config_getString(LATEX_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}

static void writeDefaultStyleSheet(TextStream &t)
{
t << ResourceMgr::instance().getAsString("doxygen.sty");
Expand Down
1 change: 1 addition & 0 deletions src/latexgen.h
Expand Up @@ -86,6 +86,7 @@ class LatexGenerator : public OutputGenerator
virtual std::unique_ptr<OutputGenerator> clone() const;

static void init();
void cleanup();
static void writeStyleSheetFile(TextStream &t);
static void writeHeaderFile(TextStream &t);
static void writeFooterFile(TextStream &t);
Expand Down
7 changes: 7 additions & 0 deletions src/mangen.cpp
Expand Up @@ -115,6 +115,13 @@ void ManGenerator::init()
createSubDirs(d);
}

void ManGenerator::cleanup()
{
QCString dname = Config_getString(MAN_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}

static QCString buildFileName(const QCString &name)
{
QCString fileName;
Expand Down
1 change: 1 addition & 0 deletions src/mangen.h
Expand Up @@ -35,6 +35,7 @@ class ManGenerator : public OutputGenerator
void writeDoc(DocNode *,const Definition *,const MemberDef *,int);

static void init();
void cleanup();
void startFile(const QCString &name,const QCString &manName,const QCString &title,int);
void writeSearchInfo() {}
void writeFooter(const QCString &) {}
Expand Down
2 changes: 2 additions & 0 deletions src/outputgen.h
Expand Up @@ -497,6 +497,8 @@ class OutputGenerator : public BaseOutputDocInterface
virtual void writeLabel(const QCString &,bool) = 0;
virtual void endLabels() = 0;

virtual void cleanup() = 0;

protected:
TextStream m_t;
private:
Expand Down
3 changes: 3 additions & 0 deletions src/outputlist.h
Expand Up @@ -475,6 +475,9 @@ class OutputList : public OutputDocInterface
void endLabels()
{ forall(&OutputGenerator::endLabels); }

void cleanup()
{ forall(&OutputGenerator::cleanup); }

void startFontClass(const QCString &c)
{ forall(&OutputGenerator::startFontClass,c); }
void endFontClass()
Expand Down
7 changes: 7 additions & 0 deletions src/rtfgen.cpp
Expand Up @@ -207,6 +207,13 @@ void RTFGenerator::init()
createSubDirs(d);
}

void RTFGenerator::cleanup()
{
QCString dname = Config_getString(RTF_OUTPUT);
Dir d(dname.str());
clearSubDirs(d);
}

static QCString makeIndexName(const QCString &s,int i)
{
QCString result=s;
Expand Down
1 change: 1 addition & 0 deletions src/rtfgen.h
Expand Up @@ -32,6 +32,7 @@ class RTFGenerator : public OutputGenerator
virtual std::unique_ptr<OutputGenerator> clone() const;

static void init();
void cleanup();
static void writeStyleSheetFile(TextStream &t);
static void writeExtensionsFile(TextStream &t);
OutputType type() const { return RTF; }
Expand Down
26 changes: 26 additions & 0 deletions src/util.cpp
Expand Up @@ -3702,6 +3702,32 @@ void createSubDirs(const Dir &d)
}
}

void clearSubDirs(const Dir &d)
{
if (Config_getBool(CREATE_SUBDIRS))
{
// remove empty subdirectories
for (int l1=0;l1<16;l1++)
{
QCString subdir;
subdir.sprintf("d%x",l1);
for (int l2=0;l2<256;l2++)
{
QCString subsubdir;
subsubdir.sprintf("d%x/d%02x",l1,l2);
if (d.exists(subsubdir.str()) && d.isEmpty(subsubdir.str()))
{
d.rmdir(subsubdir.str());
}
}
if (d.exists(subdir.str()) && d.isEmpty(subdir.str()))
{
d.rmdir(subdir.str());
}
}
}
}

/*! Input is a scopeName, output is the scopename split into a
* namespace part (as large as possible) and a classname part.
*/
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -321,6 +321,7 @@ void addDirPrefix(QCString &fileName);
QCString relativePathToRoot(const QCString &name);

void createSubDirs(const Dir &d);
void clearSubDirs(const Dir &d);

QCString stripPath(const QCString &s);

Expand Down
1 change: 1 addition & 0 deletions src/xmlgen.cpp
Expand Up @@ -2021,6 +2021,7 @@ void generateXML()
}

writeCombineScript();
clearSubDirs(xmlDir);
}


0 comments on commit f366804

Please sign in to comment.