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

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 15:28:44 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/7] 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 6198a6e0cdcc3..b97fa715f9e67 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/7] 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 b97fa715f9e67..ebd0675cd5501 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/7] 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 ebd0675cd5501..6ec35acfc2db3 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/7] 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 e93a5728d6b6b..31ff0aca72b88 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 6ec35acfc2db3..6198a6e0cdcc3 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/7] 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 31ff0aca72b88..fc2059ff5c323 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})

>From e7857ce42edeeeb9440fe01b42b0a31f8d36e52b Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Mon, 8 Jul 2024 13:37:18 -0700
Subject: [PATCH 6/7] remove copy to top level build dir

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index fc2059ff5c323..d635e35f449d9 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -46,7 +46,6 @@ foreach(f ${assets})
      set(resource_dir "${CMAKE_BINARY_DIR}/${config}/share/clang-doc")
      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

>From 3b583505efd242811404ea2ae4137b119629dbdd Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Mon, 8 Jul 2024 15:28:28 -0700
Subject: [PATCH 7/7] singleconfig should place asset files under toplevel dir

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

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index d635e35f449d9..77c620b50addd 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -42,10 +42,15 @@ foreach(f ${assets})
   install(FILES ${asset_dir}/${f}
     DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
     COMPONENT clang-doc)
-   foreach(config ${CMAKE_CONFIGURATION_TYPES})
-     set(resource_dir "${CMAKE_BINARY_DIR}/${config}/share/clang-doc")
-     copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
-   endforeach(config)
+  if ("${CMAKE_CONFIGURATION_TYPES}" STREQUAL "")
+	set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
+	copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+  else()
+    foreach(config ${CMAKE_CONFIGURATION_TYPES})
+        set(resource_dir "${CMAKE_BINARY_DIR}/${config}/share/clang-doc")
+        copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+    endforeach(config)
+   endif()
 endforeach(f)
 
 add_custom_target(copy-clang-doc-assets



More information about the cfe-commits mailing list