@@ -81,6 +81,12 @@ static llvm::cl::list<std::string> UserStylesheets(
81
81
llvm::cl::desc (" CSS stylesheets to extend the default styles." ),
82
82
llvm::cl::cat(ClangDocCategory));
83
83
84
+ static llvm::cl::opt<std::string>
85
+ UserAssetPath (" asset" ,
86
+ llvm::cl::desc (" User supplied asset path for html output to "
87
+ " override the default css and js files" ),
88
+ llvm::cl::cat(ClangDocCategory));
89
+
84
90
static llvm::cl::opt<std::string> SourceRoot (" source-root" , llvm::cl::desc(R"(
85
91
Directory where processed files are stored.
86
92
Links to definition locations will only be
@@ -131,12 +137,54 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
131
137
return llvm::sys::fs::getMainExecutable (Argv0, MainAddr);
132
138
}
133
139
140
+ void GetAssetFiles (clang::doc::ClangDocContext CDCtx) {
141
+ std::error_code Code;
142
+ for (auto DirIt = llvm::sys::fs::directory_iterator (
143
+ std::string (UserAssetPath), Code),
144
+ dir_end = llvm::sys::fs::directory_iterator ();
145
+ !Code && DirIt != dir_end; DirIt.increment (Code)) {
146
+ llvm::SmallString<128 > filePath = llvm::SmallString<128 >(DirIt->path ());
147
+ if (llvm::sys::fs::is_regular_file (filePath)) {
148
+ if (filePath.ends_with (" .css" )) {
149
+ CDCtx.UserStylesheets .push_back (std::string (filePath));
150
+ } else if (filePath.ends_with (" .js" )) {
151
+ CDCtx.FilesToCopy .push_back (std::string (filePath));
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ void GetDefaultAssetFiles (const char *Argv0,
158
+ clang::doc::ClangDocContext CDCtx) {
159
+ void *MainAddr = (void *)(intptr_t )GetExecutablePath;
160
+ std::string ClangDocPath = GetExecutablePath (Argv0, MainAddr);
161
+ llvm::SmallString<128 > NativeClangDocPath;
162
+ llvm::sys::path::native (ClangDocPath, NativeClangDocPath);
163
+
164
+ llvm::SmallString<128 > AssetsPath;
165
+ AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
166
+ llvm::sys::path::append (AssetsPath, " .." , " share" , " clang" );
167
+ llvm::SmallString<128 > DefaultStylesheet;
168
+ llvm::sys::path::native (AssetsPath, DefaultStylesheet);
169
+ llvm::sys::path::append (DefaultStylesheet,
170
+ " clang-doc-default-stylesheet.css" );
171
+ llvm::SmallString<128 > IndexJS;
172
+ llvm::sys::path::native (AssetsPath, IndexJS);
173
+ llvm::sys::path::append (IndexJS, " index.js" );
174
+ CDCtx.UserStylesheets .insert (CDCtx.UserStylesheets .begin (),
175
+ std::string (DefaultStylesheet));
176
+ CDCtx.FilesToCopy .emplace_back (IndexJS.str ());
177
+
178
+ llvm::outs () << " No default asset path found using default asset path: "
179
+ << AssetsPath << " \n " ;
180
+ }
181
+
134
182
int main (int argc, const char **argv) {
135
183
llvm::sys::PrintStackTraceOnErrorSignal (argv[0 ]);
136
184
std::error_code OK;
137
185
138
186
const char *Overview =
139
- R"( Generates documentation from source code and comments.
187
+ R"( Generates documentation from source code and comments.
140
188
141
189
Example usage for files without flags (default):
142
190
@@ -182,23 +230,12 @@ Example usage for a project using a compile commands database:
182
230
{" index.js" , " index_json.js" }};
183
231
184
232
if (Format == " html" ) {
185
- void *MainAddr = (void *)(intptr_t )GetExecutablePath;
186
- std::string ClangDocPath = GetExecutablePath (argv[0 ], MainAddr);
187
- llvm::SmallString<128 > NativeClangDocPath;
188
- llvm::sys::path::native (ClangDocPath, NativeClangDocPath);
189
- llvm::SmallString<128 > AssetsPath;
190
- AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
191
- llvm::sys::path::append (AssetsPath, " .." , " share" , " clang" );
192
- llvm::SmallString<128 > DefaultStylesheet;
193
- llvm::sys::path::native (AssetsPath, DefaultStylesheet);
194
- llvm::sys::path::append (DefaultStylesheet,
195
- " clang-doc-default-stylesheet.css" );
196
- llvm::SmallString<128 > IndexJS;
197
- llvm::sys::path::native (AssetsPath, IndexJS);
198
- llvm::sys::path::append (IndexJS, " index.js" );
199
- CDCtx.UserStylesheets .insert (CDCtx.UserStylesheets .begin (),
200
- std::string (DefaultStylesheet));
201
- CDCtx.FilesToCopy .emplace_back (IndexJS.str ());
233
+ if (!UserAssetPath.empty () &&
234
+ llvm::sys::fs::is_directory (std::string (UserAssetPath))) {
235
+ GetAssetFiles (CDCtx);
236
+ } else {
237
+ GetDefaultAssetFiles (argv[0 ], CDCtx);
238
+ }
202
239
}
203
240
204
241
// Mapping phase
0 commit comments