[clang-tools-extra] [clang-doc][cmake] Copy assets to build directory (PR #95187)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 13 09:59:13 PDT 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/95187

>From 753c6d43e44911cc7478738f1fc5d95d5780dbda Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Wed, 12 Jun 2024 01:05:59 +0000
Subject: [PATCH 1/2] [clang-doc][cmake] Copy assets to build directory

While we copy the asset files, like index.js, into the
correct location in the install step, tests do not have
access to those resources in the build directory.

This patch copies the contents of the clang-doc/assets
directory into the build folder, so that they can be
used in testing.

Pull Request: https://github.com/llvm/llvm-project/pull/95185
---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index fb8317b272932..c2425747562b9 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,3 +25,11 @@ install(FILES ../assets/clang-doc-default-stylesheet.css
 install(FILES ../assets/index.js
   DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
   COMPONENT clang-doc)
+
+add_custom_target(copy-clang-doc-assets
+  COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang"
+  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets"
+  COMMENT "Copying Clang-Doc Assets"
+  )
+set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets")
+add_dependencies(clang-doc copy-clang-doc-assets)

>From d250a9ace3c06bcac64816b98c87a5b424e14e03 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 13 Jun 2024 16:52:12 +0000
Subject: [PATCH 2/2] Use helper utility to copy files

---
 .../clang-doc/tool/CMakeLists.txt             | 43 +++++++++++++++----
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index c2425747562b9..40db9dbd1c5b1 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -18,18 +18,43 @@ target_link_libraries(clang-doc
   clangDoc
   )
 
-install(FILES ../assets/clang-doc-default-stylesheet.css
-  DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
-  COMPONENT clang-doc)
 
-install(FILES ../assets/index.js
-  DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
-  COMPONENT clang-doc)
+set(assets
+  index.js
+  clang-doc-default-stylesheet.css
+)
+
+set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
+set(resource_dir "${CMAKE_BINARY_DIR}/share/clang")
+set(out_files)
+
+function(copy_files_to_dst src_dir dst_dir file msg)
+  set(src "${src_dir}/${file}")
+  set(dst "${dst_dir}/${file}")
+  # set a default message if one isn't supplied
+  if("${msg}" STREQUAL "")
+    set(msg "Copying ${file} to ${dst_dir}")
+  endif()
+
+  add_custom_command(OUTPUT ${dst}
+    DEPENDS ${src}
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+    COMMENT "${msg}"
+  )
+  list(APPEND out_files ${dst})
+  set(out_files ${out_files} PARENT_SCOPE)
+endfunction(copy_files_to_dst)
+
+foreach(f ${assets})
+  install(FILES ${asset_dir}/${f}
+    DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
+    COMPONENT clang-doc)
+  copy_files_to_dst(${asset_dir} ${resource_dir} ${f} "")
+endforeach(f)
 
 add_custom_target(copy-clang-doc-assets
-  COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang"
-  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets"
+  DEPENDS ${out_files}
   COMMENT "Copying Clang-Doc Assets"
-  )
+)
 set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets")
 add_dependencies(clang-doc copy-clang-doc-assets)



More information about the cfe-commits mailing list