NetdataDashboard.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # CMake module to handle fetching and installing the dashboard code
  2. #
  3. # Copyright (c) 2024 Netdata Inc.
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. include(NetdataUtil)
  6. function(handle_braindead_versioning_insanity prefix)
  7. if(IS_DIRECTORY "${prefix}/v2" AND NOT IS_DIRECTORY "${prefix}/v3")
  8. message(STATUS " Fixing incorrectly versioned paths generated by poorly written CI")
  9. file(RENAME "${prefix}/v2" "${prefix}/v3")
  10. if(IS_DIRECTORY "${prefix}/v3" AND NOT IS_DIRECTORY "${prefix}/v2")
  11. message(STATUS " Fixing incorrectly versioned paths generated by poorly written CI -- Done")
  12. else()
  13. message(FATAL_ERROR "Failed to fix incorrectly versioned paths")
  14. endif()
  15. endif()
  16. endfunction()
  17. # Bundle the dashboard code for inclusion during install.
  18. #
  19. # This is unfortunately complicated due to how we need to handle the
  20. # generation of the CMakeLists file for the dashboard code.
  21. function(bundle_dashboard)
  22. include(ExternalProject)
  23. set(dashboard_src_dir "${CMAKE_BINARY_DIR}/dashboard-src")
  24. set(dashboard_src_prefix "${dashboard_src_dir}/dist/agent")
  25. set(dashboard_bin_dir "${CMAKE_BINARY_DIR}/dashboard-bin")
  26. set(DASHBOARD_URL "https://app.netdata.cloud/agent.tar.gz" CACHE STRING
  27. "URL used to fetch the local agent dashboard code")
  28. message(STATUS "Preparing local agent dashboard code")
  29. message(STATUS " Fetching ${DASHBOARD_URL}")
  30. file(DOWNLOAD
  31. "${DASHBOARD_URL}"
  32. "${CMAKE_BINARY_DIR}/dashboard.tar.gz"
  33. TIMEOUT 180
  34. STATUS fetch_status)
  35. list(GET fetch_status 0 result)
  36. if(result)
  37. message(FATAL_ERROR "Failed to fetch dashboard code")
  38. else()
  39. message(STATUS " Fetching ${DASHBOARD_URL} -- Done")
  40. endif()
  41. message(STATUS " Extracting dashboard code")
  42. extract_gzipped_tarball(
  43. "${CMAKE_BINARY_DIR}/dashboard.tar.gz"
  44. "${dashboard_src_dir}"
  45. )
  46. message(STATUS " Extracting dashboard code -- Done")
  47. handle_braindead_versioning_insanity("${dashboard_src_prefix}")
  48. message(STATUS " Generating CMakeLists.txt file for dashboard code")
  49. set(rules "")
  50. subdirlist(dash_dirs "${dashboard_src_prefix}")
  51. foreach(dir IN LISTS dash_dirs)
  52. file(GLOB files
  53. LIST_DIRECTORIES FALSE
  54. RELATIVE "${dashboard_src_dir}"
  55. "${dashboard_src_prefix}/${dir}/*")
  56. set(rules "${rules}install(FILES ${files} COMPONENT dashboard DESTINATION ${WEB_DEST}/${dir})\n")
  57. endforeach()
  58. file(GLOB files
  59. LIST_DIRECTORIES FALSE
  60. RELATIVE "${dashboard_src_dir}"
  61. "${dashboard_src_prefix}/*")
  62. set(rules "${rules}install(FILES ${files} COMPONENT dashboard DESTINATION ${WEB_DEST})\n")
  63. file(WRITE "${dashboard_src_dir}/CMakeLists.txt" "${rules}")
  64. message(STATUS " Generating CMakeLists.txt file for dashboard code -- Done")
  65. add_subdirectory("${dashboard_src_dir}" "${dashboard_bin_dir}")
  66. message(STATUS "Preparing local agent dashboard code -- Done")
  67. endfunction()