[PATCH] D66268: [clang-doc] Fix use of source-root flag

Diego Astiazarán via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 14 18:28:37 PDT 2019


DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, ilya-biryukov.

The value, if any, of --source-root flag was not being used.
This has been fixed and the logic was moved to the ClangDocContext contructor.


https://reviews.llvm.org/D66268

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===================================================================
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -203,17 +203,11 @@
                                   tooling::ArgumentInsertPosition::END),
         ArgAdjuster);
 
-  llvm::SmallString<128> SourceRootDir;
-  // Check if the --source-root flag has a value
-  if (SourceRoot.empty())
-    // If it's empty the current path is used as the default
-    llvm::sys::fs::current_path(SourceRootDir);
-
   clang::doc::ClangDocContext CDCtx = {
       Exec->get()->getExecutionContext(),
       PublicOnly,
       OutDirectory,
-      SourceRootDir.str(),
+      SourceRoot,
       RepositoryUrl,
       {UserStylesheets.begin(), UserStylesheets.end()},
       {"index.js", "index_json.js"}};
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -257,8 +257,12 @@
                                  std::vector<std::string> UserStylesheets,
                                  std::vector<std::string> JsScripts)
     : ECtx(ECtx), PublicOnly(PublicOnly), OutDirectory(OutDirectory),
-      SourceRoot(SourceRoot), UserStylesheets(UserStylesheets),
-      JsScripts(JsScripts) {
+      UserStylesheets(UserStylesheets), JsScripts(JsScripts) {
+  llvm::SmallString<128> SourceRootDir(SourceRoot);
+  if (SourceRoot.empty())
+    // If no SourceRoot was provided the current path is used as the default
+    llvm::sys::fs::current_path(SourceRootDir);
+  this->SourceRoot = SourceRootDir.str();
   if (!RepositoryUrl.empty()) {
     this->RepositoryUrl = RepositoryUrl;
     if (!RepositoryUrl.empty() && RepositoryUrl.find("http://") != 0 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66268.215302.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190815/f7bd2b8e/attachment.bin>


More information about the cfe-commits mailing list