NetdataDashboard.cmake 2.8 KB

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