Skip to content

Commit be64902

Browse files
fpelliccionialandefreitas
authored andcommitted
feat: tagfiles
fix #650
1 parent dee9fdf commit be64902

File tree

10 files changed

+528
-17
lines changed

10 files changed

+528
-17
lines changed

docs/mrdocs.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@
244244
"title": "System include paths",
245245
"type": "array"
246246
},
247+
"tagfile": {
248+
"default": "<output>/reference.tag.xml",
249+
"description": "Specifies the full path (filename) where the generated tagfile should be saved. If left empty, no tagfile will be generated.",
250+
"title": "Path for the tagfile",
251+
"type": "string"
252+
},
247253
"use-system-stdlib": {
248254
"default": false,
249255
"description": "True if the compiler has to use just the system standard library. When set to true, the compiler uses the system standard library instead of the standard library provided by the compiler.",

include/mrdocs/Corpus.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class MRDOCS_VISIBLE
143143
The type of the first argument is determined
144144
by the `InfoKind` of the `Info` object.
145145
146+
@param I The Info to visit.
146147
@param info The Info to visit.
147148
@param f The function to invoke.
148149
@param args The arguments to pass to the function.
@@ -202,6 +203,14 @@ class MRDOCS_VISIBLE
202203
getFullyQualifiedName(
203204
const Info& I,
204205
std::string& temp) const;
206+
207+
std::string
208+
getFullyQualifiedName(const Info& I) const
209+
{
210+
std::string temp;
211+
return getFullyQualifiedName(I, temp);
212+
}
213+
205214
};
206215

207216
//------------------------------------------------

include/mrdocs/Generator.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ class MRDOCS_VISIBLE
182182
Corpus const& corpus) const;
183183
};
184184

185+
/** Return the full path for single page output.
186+
187+
This function determines the full path for a single-page output file
188+
based on the provided `outputPath` and file `extension`.
189+
190+
If the `outputPath` already exists:
191+
- If it is a directory, appends the default file name with the provided extension.
192+
- If it is a file, uses the provided `outputPath` directly.
193+
194+
If the `outputPath` does not exist:
195+
- If it ends with a '/', assumes it is a directory and appends the default file name.
196+
- Otherwise, it returns an error because the path is ambiguous.
197+
198+
@return The full path or an error if the `outputPath` is ambiguous.
199+
200+
@param outputPath The specified output path, which can be a directory or file.
201+
@param extension The file extension to use for single-page output.
202+
*/
203+
Expected<std::string>
204+
getSinglePageFullPath(
205+
std::string_view outputPath,
206+
std::string_view extension);
207+
185208
} // mrdocs
186209
} // clang
187210

src/lib/Gen/hbs/HandlebarsGenerator.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
#include "Builder.hpp"
1616
#include "MultiPageVisitor.hpp"
1717
#include "SinglePageVisitor.hpp"
18+
19+
#include "lib/Lib/TagfileWriter.hpp"
20+
#include "lib/Support/RawOstream.hpp"
21+
22+
#include <llvm/ADT/SmallString.h>
23+
#include <llvm/Support/FileSystem.h>
24+
#include <llvm/Support/Path.h>
25+
1826
#include <mrdocs/Support/Path.hpp>
27+
28+
#include <fstream>
1929
#include <sstream>
2030

2131
namespace clang {
@@ -79,7 +89,21 @@ build(
7989
{
8090
if (!corpus.config->multipage)
8191
{
82-
return Generator::build(outputPath, corpus);
92+
auto e = Generator::build(outputPath, corpus);
93+
if (e.has_value() && !corpus.config->tagfile.empty())
94+
{
95+
// Generate tagfile if specified
96+
auto const singlePagePath = getSinglePageFullPath(outputPath, fileExtension());
97+
MRDOCS_CHECK_OR(singlePagePath, Unexpected(singlePagePath.error()));
98+
HandlebarsCorpus hbsCorpus = createDomCorpus(*this, corpus);
99+
MRDOCS_TRY(auto tagFileWriter, TagfileWriter::create(
100+
hbsCorpus,
101+
corpus.config->tagfile,
102+
files::getFileName(*singlePagePath)));
103+
tagFileWriter.build();
104+
}
105+
106+
return e;
83107
}
84108

85109
// Create corpus and executors
@@ -93,6 +117,16 @@ build(
93117
// Wait for all executors to finish and check errors
94118
auto errors = ex.wait();
95119
MRDOCS_CHECK_OR(errors.empty(), Unexpected(errors));
120+
121+
if (! corpus.config->tagfile.empty())
122+
{
123+
MRDOCS_TRY(auto tagFileWriter, TagfileWriter::create(
124+
domCorpus,
125+
corpus.config->tagfile,
126+
outputPath));
127+
tagFileWriter.build();
128+
}
129+
96130
return {};
97131
}
98132

src/lib/Gen/xml/XMLTags.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ void
193193
XMLTags::
194194
nest(int levels)
195195
{
196+
if (!nesting_)
197+
return;
198+
196199
if(levels > 0)
197200
{
198201
indent_.append(levels * 2, ' ');

src/lib/Gen/xml/XMLTags.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class XMLTags
186186
public:
187187
std::string indent_;
188188
llvm::raw_ostream& os_;
189+
bool nesting_ = true;
189190

190191
explicit
191192
XMLTags(
@@ -201,6 +202,7 @@ class XMLTags
201202
void write(dom::String const&,
202203
llvm::StringRef value = {}, Attributes = {});
203204
void close(dom::String const&);
205+
void nesting(bool enable) noexcept { nesting_ = enable; }
204206

205207
void nest(int levels);
206208
};

src/lib/Lib/ConfigOptions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@
148148
"default": "<mrdocs-root>/share/mrdocs/addons",
149149
"relativeto": "<config-dir>"
150150
},
151+
{
152+
"name": "tagfile",
153+
"brief": "Path for the tagfile",
154+
"details": "Specifies the full path (filename) where the generated tagfile should be saved. If left empty, no tagfile will be generated.",
155+
"type": "file-path",
156+
"default": "<output>/reference.tag.xml",
157+
"relativeto": "<output>",
158+
"must-exist": false
159+
},
151160
{
152161
"name": "legible-names",
153162
"brief": "Use legible names",

0 commit comments

Comments
 (0)