18
18
// ===----------------------------------------------------------------------===//
19
19
20
20
#include " BitcodeReader.h"
21
- #include " BitcodeWriter.h"
22
21
#include " ClangDoc.h"
23
22
#include " Generators.h"
24
23
#include " Representation.h"
25
- #include " clang/AST/AST.h"
26
- #include " clang/AST/Decl.h"
27
- #include " clang/ASTMatchers/ASTMatchFinder.h"
24
+ #include " support/Utils.h"
28
25
#include " clang/ASTMatchers/ASTMatchersInternal.h"
29
- #include " clang/Driver/Options.h"
30
- #include " clang/Frontend/FrontendActions.h"
31
26
#include " clang/Tooling/AllTUsExecution.h"
32
27
#include " clang/Tooling/CommonOptionsParser.h"
33
28
#include " clang/Tooling/Execution.h"
34
- #include " clang/Tooling/Tooling.h"
35
29
#include " llvm/ADT/APFloat.h"
36
30
#include " llvm/Support/CommandLine.h"
37
31
#include " llvm/Support/Error.h"
@@ -110,22 +104,19 @@ static llvm::cl::opt<std::string> RepositoryCodeLinePrefix(
110
104
llvm::cl::desc (" Prefix of line code for repository." ),
111
105
llvm::cl::cat(ClangDocCategory));
112
106
113
- enum OutputFormatTy {
114
- md,
115
- yaml,
116
- html,
117
- };
118
-
119
- static llvm::cl::opt<OutputFormatTy>
120
- FormatEnum (" format" , llvm::cl::desc(" Format for outputted docs." ),
121
- llvm::cl::values(clEnumValN(OutputFormatTy::yaml, " yaml" ,
122
- " Documentation in YAML format." ),
123
- clEnumValN(OutputFormatTy::md, " md" ,
124
- " Documentation in MD format." ),
125
- clEnumValN(OutputFormatTy::html, " html" ,
126
- " Documentation in HTML format." )),
127
- llvm::cl::init(OutputFormatTy::yaml),
128
- llvm::cl::cat(ClangDocCategory));
107
+ enum OutputFormatTy { md, yaml, html, mustache };
108
+
109
+ static llvm::cl::opt<OutputFormatTy> FormatEnum (
110
+ " format" , llvm::cl::desc(" Format for outputted docs." ),
111
+ llvm::cl::values(clEnumValN(OutputFormatTy::yaml, " yaml" ,
112
+ " Documentation in YAML format." ),
113
+ clEnumValN(OutputFormatTy::md, " md" ,
114
+ " Documentation in MD format." ),
115
+ clEnumValN(OutputFormatTy::html, " html" ,
116
+ " Documentation in HTML format." ),
117
+ clEnumValN(OutputFormatTy::mustache, " mustache" ,
118
+ " Documentation in mustache HTML format" )),
119
+ llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
129
120
130
121
static std::string getFormatString () {
131
122
switch (FormatEnum) {
@@ -135,6 +126,8 @@ static std::string getFormatString() {
135
126
return " md" ;
136
127
case OutputFormatTy::html:
137
128
return " html" ;
129
+ case OutputFormatTy::mustache:
130
+ return " mustache" ;
138
131
}
139
132
llvm_unreachable (" Unknown OutputFormatTy" );
140
133
}
@@ -178,13 +171,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
178
171
llvm::SmallString<128 > AssetsPath;
179
172
AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
180
173
llvm::sys::path::append (AssetsPath, " .." , " share" , " clang-doc" );
181
- llvm::SmallString<128 > DefaultStylesheet;
182
- llvm::sys::path::native (AssetsPath, DefaultStylesheet);
183
- llvm::sys::path::append (DefaultStylesheet,
184
- " clang-doc-default-stylesheet.css" );
185
- llvm::SmallString<128 > IndexJS;
186
- llvm::sys::path::native (AssetsPath, IndexJS);
187
- llvm::sys::path::append (IndexJS, " index.js" );
174
+ llvm::SmallString<128 > DefaultStylesheet =
175
+ appendPathNative (AssetsPath, " clang-doc-default-stylesheet.css" );
176
+ llvm::SmallString<128 > IndexJS = appendPathNative (AssetsPath, " index.js" );
188
177
189
178
if (!llvm::sys::fs::is_regular_file (IndexJS))
190
179
return llvm::createStringError (llvm::inconvertibleErrorCode (),
@@ -215,6 +204,30 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
215
204
return getDefaultAssetFiles (Argv0, CDCtx);
216
205
}
217
206
207
+ static llvm::Error getMustacheHtmlFiles (const char *Argv0,
208
+ clang::doc::ClangDocContext &CDCtx) {
209
+ bool IsDir = llvm::sys::fs::is_directory (UserAssetPath);
210
+ if (!UserAssetPath.empty () && !IsDir)
211
+ llvm::outs () << " Asset path supply is not a directory: " << UserAssetPath
212
+ << " falling back to default\n " ;
213
+ if (IsDir) {
214
+ getMustacheHtmlFiles (UserAssetPath, CDCtx);
215
+ return llvm::Error::success ();
216
+ }
217
+ void *MainAddr = (void *)(intptr_t )getExecutablePath;
218
+ std::string ClangDocPath = getExecutablePath (Argv0, MainAddr);
219
+ llvm::SmallString<128 > NativeClangDocPath;
220
+ llvm::sys::path::native (ClangDocPath, NativeClangDocPath);
221
+
222
+ llvm::SmallString<128 > AssetsPath;
223
+ AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
224
+ llvm::sys::path::append (AssetsPath, " .." , " share" , " clang-doc" );
225
+
226
+ getMustacheHtmlFiles (AssetsPath, CDCtx);
227
+
228
+ return llvm::Error::success ();
229
+ }
230
+
218
231
// / Make the output of clang-doc deterministic by sorting the children of
219
232
// / namespaces and records.
220
233
static void
@@ -290,6 +303,13 @@ Example usage for a project using a compile commands database:
290
303
}
291
304
}
292
305
306
+ if (Format == " mustache" ) {
307
+ if (auto Err = getMustacheHtmlFiles (argv[0 ], CDCtx)) {
308
+ llvm::errs () << toString (std::move (Err)) << " \n " ;
309
+ return 1 ;
310
+ }
311
+ }
312
+
293
313
// Mapping phase
294
314
llvm::outs () << " Mapping decls...\n " ;
295
315
auto Err =
0 commit comments