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,11 +104,7 @@ 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
- };
107
+ enum OutputFormatTy { md, yaml, html, mhtml };
118
108
119
109
static llvm::cl::opt<OutputFormatTy>
120
110
FormatEnum (" format" , llvm::cl::desc(" Format for outputted docs." ),
@@ -123,7 +113,9 @@ static llvm::cl::opt<OutputFormatTy>
123
113
clEnumValN(OutputFormatTy::md, " md" ,
124
114
" Documentation in MD format." ),
125
115
clEnumValN(OutputFormatTy::html, " html" ,
126
- " Documentation in HTML format." )),
116
+ " Documentation in HTML format." ),
117
+ clEnumValN(OutputFormatTy::mhtml, " mhtml" ,
118
+ " Documentation in mHTML format" )),
127
119
llvm::cl::init(OutputFormatTy::yaml),
128
120
llvm::cl::cat(ClangDocCategory));
129
121
@@ -135,6 +127,8 @@ static std::string getFormatString() {
135
127
return " md" ;
136
128
case OutputFormatTy::html:
137
129
return " html" ;
130
+ case OutputFormatTy::mhtml:
131
+ return " mhtml" ;
138
132
}
139
133
llvm_unreachable (" Unknown OutputFormatTy" );
140
134
}
@@ -178,13 +172,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
178
172
llvm::SmallString<128 > AssetsPath;
179
173
AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
180
174
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" );
175
+ llvm::SmallString<128 > DefaultStylesheet =
176
+ appendPathNative (AssetsPath, " clang-doc-default-stylesheet.css" );
177
+ llvm::SmallString<128 > IndexJS = appendPathNative (AssetsPath, " index.js" );
188
178
189
179
if (!llvm::sys::fs::is_regular_file (IndexJS))
190
180
return llvm::createStringError (llvm::inconvertibleErrorCode (),
@@ -215,6 +205,30 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
215
205
return getDefaultAssetFiles (Argv0, CDCtx);
216
206
}
217
207
208
+ static llvm::Error getMustacheHtmlFiles (const char *Argv0,
209
+ clang::doc::ClangDocContext &CDCtx) {
210
+ bool IsDir = llvm::sys::fs::is_directory (UserAssetPath);
211
+ if (!UserAssetPath.empty () && !IsDir)
212
+ llvm::outs () << " Asset path supply is not a directory: " << UserAssetPath
213
+ << " falling back to default\n " ;
214
+ if (IsDir) {
215
+ getMustacheHtmlFiles (UserAssetPath, CDCtx);
216
+ return llvm::Error::success ();
217
+ }
218
+ void *MainAddr = (void *)(intptr_t )getExecutablePath;
219
+ std::string ClangDocPath = getExecutablePath (Argv0, MainAddr);
220
+ llvm::SmallString<128 > NativeClangDocPath;
221
+ llvm::sys::path::native (ClangDocPath, NativeClangDocPath);
222
+
223
+ llvm::SmallString<128 > AssetsPath;
224
+ AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
225
+ llvm::sys::path::append (AssetsPath, " .." , " share" , " clang-doc" );
226
+
227
+ getMustacheHtmlFiles (AssetsPath, CDCtx);
228
+
229
+ return llvm::Error::success ();
230
+ }
231
+
218
232
// / Make the output of clang-doc deterministic by sorting the children of
219
233
// / namespaces and records.
220
234
static void
@@ -290,6 +304,13 @@ Example usage for a project using a compile commands database:
290
304
}
291
305
}
292
306
307
+ if (Format == " mhtml" ) {
308
+ if (auto Err = getMustacheHtmlFiles (argv[0 ], CDCtx)) {
309
+ llvm::errs () << toString (std::move (Err)) << " \n " ;
310
+ return 1 ;
311
+ }
312
+ }
313
+
293
314
// Mapping phase
294
315
llvm::outs () << " Mapping decls...\n " ;
295
316
auto Err =
0 commit comments