Skip to content

Commit 94b2979

Browse files
committed
[clang][clang-doc] fix asset option
1 parent 39e0647 commit 94b2979

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,17 @@ std::string getFormatString() {
133133
// GetMainExecutable (since some platforms don't support taking the
134134
// address of main, and some platforms can't implement GetMainExecutable
135135
// without being given the address of a function in the main executable).
136-
std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
136+
std::string getExecutablePath(const char *Argv0, void *MainAddr) {
137137
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
138138
}
139139

140-
llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
140+
llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
141141
std::error_code Code;
142+
llvm::SmallString<128> FilePath = llvm::SmallString<128>(UserAssetPath);
142143
for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code),
143144
DirEnd = llvm::sys::fs::directory_iterator();
144145
!Code && DirIt != DirEnd; DirIt.increment(Code)) {
145-
llvm::SmallString<128> FilePath = llvm::SmallString<128>(DirIt->path());
146-
if (!Code) {
147-
return llvm::createFileError(FilePath, Code);
148-
}
146+
FilePath = llvm::SmallString<128>(DirIt->path());
149147
if (llvm::sys::fs::is_regular_file(FilePath)) {
150148
if (llvm::sys::path::extension(FilePath) == ".css") {
151149
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
@@ -155,13 +153,16 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
155153
}
156154
}
157155
}
156+
if (Code) {
157+
return llvm::createFileError(FilePath, Code);
158+
}
158159
return llvm::Error::success();
159160
}
160161

161-
llvm::Error GetDefaultAssetFiles(const char *Argv0,
162+
llvm::Error getDefaultAssetFiles(const char *Argv0,
162163
clang::doc::ClangDocContext &CDCtx) {
163-
void *MainAddr = (void *)(intptr_t)GetExecutablePath;
164-
std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
164+
void *MainAddr = (void *)(intptr_t)getExecutablePath;
165+
std::string ClangDocPath = getExecutablePath(Argv0, MainAddr);
165166
llvm::SmallString<128> NativeClangDocPath;
166167
llvm::sys::path::native(ClangDocPath, NativeClangDocPath);
167168

@@ -178,14 +179,14 @@ llvm::Error GetDefaultAssetFiles(const char *Argv0,
178179

179180
if (!llvm::sys::fs::is_regular_file(IndexJS)) {
180181
return llvm::createStringError(llvm::inconvertibleErrorCode(),
181-
"error default index.js file at " + IndexJS +
182-
"\n");
182+
"error default index.js file missing at " +
183+
IndexJS + "\n");
183184
}
184185

185186
if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) {
186187
return llvm::createStringError(
187188
llvm::inconvertibleErrorCode(),
188-
"error default clang-doc-default-stylesheet.css file at " +
189+
"error default clang-doc-default-stylesheet.css file missing at " +
189190
DefaultStylesheet + "\n");
190191
}
191192

@@ -198,17 +199,17 @@ llvm::Error GetDefaultAssetFiles(const char *Argv0,
198199
return llvm::Error::success();
199200
}
200201

201-
llvm::Error GetHTMLAssetFiles(const char *Argv0,
202+
llvm::Error getHtmlAssetFiles(const char *Argv0,
202203
clang::doc::ClangDocContext &CDCtx) {
203204
if (!UserAssetPath.empty() &&
204205
!llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
205206
llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
206207
<< " falling back to default\n";
207208
}
208209
if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
209-
return GetAssetFiles(CDCtx);
210+
return getAssetFiles(CDCtx);
210211
}
211-
return GetDefaultAssetFiles(Argv0, CDCtx);
212+
return getDefaultAssetFiles(Argv0, CDCtx);
212213
}
213214

214215
int main(int argc, const char **argv) {
@@ -262,7 +263,7 @@ Example usage for a project using a compile commands database:
262263
{"index.js", "index_json.js"}};
263264

264265
if (Format == "html") {
265-
auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
266+
auto Err = getHtmlAssetFiles(argv[0], CDCtx);
266267
if (Err) {
267268
llvm::errs() << toString(std::move(Err)) << "\n";
268269
return 1;

0 commit comments

Comments
 (0)