check-data-dir.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. include(${CMAKE_CURRENT_LIST_DIR}/verify-snippet.cmake)
  2. include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
  3. file(GLOB snippets LIST_DIRECTORIES false ${v1}/data/*)
  4. if (NOT snippets)
  5. add_error("No snippet files generated")
  6. endif()
  7. set(FOUND_SNIPPETS "")
  8. foreach(snippet IN LISTS snippets)
  9. get_filename_component(filename "${snippet}" NAME)
  10. read_json("${snippet}" contents)
  11. # Verify snippet file is valid
  12. verify_snippet_file("${snippet}" "${contents}")
  13. # Append to list of collected snippet roles
  14. if (NOT role IN_LIST FOUND_SNIPPETS)
  15. list(APPEND FOUND_SNIPPETS ${role})
  16. endif()
  17. # Verify target
  18. string(JSON target ERROR_VARIABLE noTarget GET "${contents}" target)
  19. if (NOT target MATCHES NOTFOUND)
  20. set(targets "main;lib;customTarget;TARGET_NAME")
  21. if (NOT ${target} IN_LIST targets)
  22. json_error("${snippet}" "Unexpected target: ${target}")
  23. endif()
  24. endif()
  25. # Verify output
  26. string(JSON result GET "${contents}" result)
  27. if (NOT ${result} EQUAL 0)
  28. json_error("${snippet}" "Compile command had non-0 result")
  29. endif()
  30. # Verify contents of compile-* Snippets
  31. if (filename MATCHES "^compile-")
  32. string(JSON target GET "${contents}" target)
  33. string(JSON source GET "${contents}" source)
  34. string(JSON language GET "${contents}" language)
  35. if (NOT language MATCHES "C\\+\\+")
  36. json_error("${snippet}" "Expected C++ compile language")
  37. endif()
  38. if (NOT source MATCHES "${target}.cxx$")
  39. json_error("${snippet}" "Unexpected source file")
  40. endif()
  41. endif()
  42. # Verify contents of link-* Snippets
  43. if (filename MATCHES "^link-")
  44. string(JSON target GET "${contents}" target)
  45. string(JSON targetType GET "${contents}" targetType)
  46. string(JSON targetLabels GET "${contents}" targetLabels)
  47. if (target MATCHES "main")
  48. if (NOT targetType MATCHES "EXECUTABLE")
  49. json_error("${snippet}" "Expected EXECUTABLE, target type was ${targetType}")
  50. endif()
  51. string(JSON nlabels LENGTH "${targetLabels}")
  52. if (NOT nlabels STREQUAL 2)
  53. json_error("${snippet}" "Missing Target Labels for: ${target}")
  54. else()
  55. string(JSON label1 GET "${contents}" targetLabels 0)
  56. string(JSON label2 GET "${contents}" targetLabels 1)
  57. if (NOT label1 MATCHES "label1" OR NOT label2 MATCHES "label2")
  58. json_error("${snippet}" "Missing Target Labels for: ${target}")
  59. endif()
  60. endif()
  61. endif()
  62. if (target MATCHES "lib")
  63. if (NOT targetType MATCHES "STATIC_LIBRARY")
  64. json_error("${snippet}" "Expected STATIC_LIBRARY, target type was ${targetType}")
  65. endif()
  66. string(JSON nlabels LENGTH "${targetLabels}")
  67. if (NOT nlabels STREQUAL 1)
  68. json_error("${snippet}" "Missing Target Labels for: ${target}")
  69. else()
  70. string(JSON label ERROR_VARIABLE noLabels GET "${contents}" targetLabels 0)
  71. if (NOT label MATCHES "label3")
  72. json_error("${snippet}" "Missing Target Labels for: ${target}")
  73. endif()
  74. endif()
  75. endif()
  76. endif()
  77. # Verify contents of custom-* Snippets
  78. if (filename MATCHES "^custom-")
  79. string(JSON outputs GET "${contents}" outputs)
  80. if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2")
  81. json_error("${snippet}" "Custom command missing outputs")
  82. endif()
  83. endif()
  84. # Verify contents of test-* Snippets
  85. if (filename MATCHES "^test-")
  86. string(JSON testName GET "${contents}" testName)
  87. if (NOT testName STREQUAL "test")
  88. json_error("${snippet}" "Unexpected testName: ${testName}")
  89. endif()
  90. endif()
  91. # Verify that Config is Debug
  92. if (filename MATCHES "^test|^compile|^link")
  93. string(JSON config GET "${contents}" config)
  94. if (NOT config STREQUAL "Debug")
  95. json_error(${snippet} "Unexpected config: ${config}")
  96. endif()
  97. endif()
  98. # Verify command args were passed
  99. if (filename MATCHES "^cmakeBuild|^ctest")
  100. string(JSON command GET "${contents}" command)
  101. if (NOT command MATCHES "Debug")
  102. json_error(${snippet} "Command value missing passed arguments")
  103. endif()
  104. endif()
  105. endforeach()
  106. # Verify that listed snippets match expected roles
  107. set(EXPECTED_SNIPPETS configure generate)
  108. if (ARGS_BUILD)
  109. list(APPEND EXPECTED_SNIPPETS compile link custom cmakeBuild)
  110. endif()
  111. if (ARGS_TEST)
  112. list(APPEND EXPECTED_SNIPPETS ctest test)
  113. endif()
  114. if (ARGS_INSTALL)
  115. list(APPEND EXPECTED_SNIPPETS cmakeInstall)
  116. if (ARGS_INSTALL_PARALLEL)
  117. list(APPEND EXPECTED_SNIPPETS install)
  118. endif()
  119. endif()
  120. foreach(role IN LISTS EXPECTED_SNIPPETS)
  121. list(FIND FOUND_SNIPPETS "${role}" found)
  122. if (found EQUAL -1)
  123. add_error("No snippet files of role \"${role}\" were found in ${v1}")
  124. endif()
  125. endforeach()
  126. foreach(role IN LISTS FOUND_SNIPPETS)
  127. list(FIND EXPECTED_SNIPPETS "${role}" found)
  128. if (${found} EQUAL -1)
  129. add_error("Found unexpected snippet file of role \"${role}\" in ${v1}")
  130. endif()
  131. endforeach()
  132. # Verify test/install artifacts
  133. if (ARGS_INSTALL AND NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/install)
  134. add_error("ctest --instrument launcher failed to install the project")
  135. endif()
  136. if (ARGS_TEST AND NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/Testing)
  137. add_error("ctest --instrument launcher failed to test the project")
  138. endif()