[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 15:35:15 PDT 2024


https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/5] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc32..b97fa715f9e67f 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+    llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/5] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67f..ebd0675cd55014 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
     llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/5] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd55014..6ec35acfc2db3a 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

>From b7484828d96d23dd7d2d88ee8d44f5aad6e23140 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 3 Jul 2024 13:37:17 -0700
Subject: [PATCH 4/5] revert change in .cpp, make attempt at fixing cmake

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt   | 10 ++++++++--
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp |  9 +--------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b0..31ff0aca72b88f 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,15 +25,16 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
   set(src "${src_dir}/${file}")
   set(dst "${dst_dir}/${file}")
+  message(here)
   add_custom_command(OUTPUT ${dst}
     DEPENDS ${src}
     COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+    message(here2)
     COMMENT "Copying ${file} to ${dst_dir}"
   )
   list(APPEND out_files ${dst})
@@ -44,7 +45,12 @@ foreach(f ${assets})
   install(FILES ${asset_dir}/${f}
     DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
     COMPONENT clang-doc)
-  copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+   foreach(config ${CMAKE_CONFIGURATION_TYPES})
+     set(resource_dir "${CMAKE_BINARY_DIR}/${config}/share/clang-doc")
+     message(resource_dir="${resource_dir}")
+     copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+   endforeach(config)
+   copy_files_to_dst(${asset_dir} "${CMAKE_BINARY_DIR}/share/clang-doc" ${f})
 endforeach(f)
 
 add_custom_target(copy-clang-doc-assets
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6ec35acfc2db3a..6198a6e0cdcc32 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,14 +167,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg;
-  llvm::sys::path::native(AssetsPath, tempCopyDbg);
-  llvm::sys::path::append(tempCopyDbg, "Debug");
-  // The executable that ran clangDoc may be in the Debug directory.
-  if (!llvm::sys::fs::is_directory(tempCopyDbg))
-    llvm::sys::path::append(AssetsPath, "..");
-  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 59f187f1c10126c37a9d120bf8ee177371ce352d Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 3 Jul 2024 15:34:55 -0700
Subject: [PATCH 5/5] copy works now!

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index 31ff0aca72b88f..fc2059ff5c3231 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -30,13 +30,10 @@ set(out_files)
 function(copy_files_to_dst src_dir dst_dir file)
   set(src "${src_dir}/${file}")
   set(dst "${dst_dir}/${file}")
-  message(here)
-  add_custom_command(OUTPUT ${dst}
-    DEPENDS ${src}
-    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
-    message(here2)
-    COMMENT "Copying ${file} to ${dst_dir}"
-  )
+  if (NOT EXISTS ${dst_dir})
+    file(MAKE_DIRECTORY ${dst_dir})
+  endif()
+  configure_file(${src} ${dst} COPYONLY)
   list(APPEND out_files ${dst})
   set(out_files ${out_files} PARENT_SCOPE)
 endfunction(copy_files_to_dst)
@@ -47,7 +44,6 @@ foreach(f ${assets})
     COMPONENT clang-doc)
    foreach(config ${CMAKE_CONFIGURATION_TYPES})
      set(resource_dir "${CMAKE_BINARY_DIR}/${config}/share/clang-doc")
-     message(resource_dir="${resource_dir}")
      copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
    endforeach(config)
    copy_files_to_dst(${asset_dir} "${CMAKE_BINARY_DIR}/share/clang-doc" ${f})



More information about the cfe-commits mailing list