You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

685 lines
22 KiB

  1. From 019ed04331695bb6f5c5fff70dfced34c4ba9012 Mon Sep 17 00:00:00 2001
  2. From: Daniel Mensinger <daniel@mensinger-ka.de>
  3. Date: Thu, 16 Jul 2020 20:29:34 +0200
  4. Subject: [PATCH 1/3] mdata: Generate mesondata.py from */data folders
  5. ---
  6. mesonbuild/mesondata.py | 374 ++++++++++++++++++++++++++++++++++++++++
  7. tools/gen_data.py | 139 +++++++++++++++
  8. 2 files changed, 513 insertions(+)
  9. create mode 100644 mesonbuild/mesondata.py
  10. create mode 100755 tools/gen_data.py
  11. diff --git a/mesonbuild/mesondata.py b/mesonbuild/mesondata.py
  12. new file mode 100644
  13. index 0000000000..1f223c251b
  14. --- /dev/null
  15. +++ b/mesonbuild/mesondata.py
  16. @@ -0,0 +1,374 @@
  17. +# Copyright 2020 The Meson development team
  18. +
  19. +# Licensed under the Apache License, Version 2.0 (the "License");
  20. +# you may not use this file except in compliance with the License.
  21. +# You may obtain a copy of the License at
  22. +
  23. +# http://www.apache.org/licenses/LICENSE-2.0
  24. +
  25. +# Unless required by applicable law or agreed to in writing, software
  26. +# distributed under the License is distributed on an "AS IS" BASIS,
  27. +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. +# See the License for the specific language governing permissions and
  29. +# limitations under the License.
  30. +
  31. +
  32. +####
  33. +#### WARNING: This is an automatically generated file! Do not edit!
  34. +#### Generated by tools/gen_data.py
  35. +####
  36. +
  37. +
  38. +from pathlib import Path
  39. +import typing as T
  40. +
  41. +if T.TYPE_CHECKING:
  42. + from .environment import Environment
  43. +
  44. +######################
  45. +# BEGIN Data section #
  46. +######################
  47. +
  48. +file_0_data_CMakeListsLLVM_txt = '''\
  49. +cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} )
  50. +
  51. +set(PACKAGE_FOUND FALSE)
  52. +
  53. +while(TRUE)
  54. + find_package(LLVM REQUIRED CONFIG QUIET)
  55. +
  56. + # ARCHS has to be set via the CMD interface
  57. + if(LLVM_FOUND OR "${ARCHS}" STREQUAL "")
  58. + break()
  59. + endif()
  60. +
  61. + list(GET ARCHS 0 CMAKE_LIBRARY_ARCHITECTURE)
  62. + list(REMOVE_AT ARCHS 0)
  63. +endwhile()
  64. +
  65. +if(LLVM_FOUND)
  66. + set(PACKAGE_FOUND TRUE)
  67. +
  68. + foreach(mod IN LISTS LLVM_MESON_MODULES)
  69. + # Reset variables
  70. + set(out_mods)
  71. + set(real_mods)
  72. +
  73. + # Generate a lower and upper case version
  74. + string(TOLOWER "${mod}" mod_L)
  75. + string(TOUPPER "${mod}" mod_U)
  76. +
  77. + # Get the mapped components
  78. + llvm_map_components_to_libnames(out_mods ${mod} ${mod_L} ${mod_U})
  79. + list(SORT out_mods)
  80. + list(REMOVE_DUPLICATES out_mods)
  81. +
  82. + # Make sure that the modules exist
  83. + foreach(i IN LISTS out_mods)
  84. + if(TARGET ${i})
  85. + list(APPEND real_mods ${i})
  86. + endif()
  87. + endforeach()
  88. +
  89. + # Set the output variables
  90. + set(MESON_LLVM_TARGETS_${mod} ${real_mods})
  91. + foreach(i IN LISTS real_mods)
  92. + set(MESON_TARGET_TO_LLVM_${i} ${mod})
  93. + endforeach()
  94. + endforeach()
  95. +
  96. + # Check the following variables:
  97. + # LLVM_PACKAGE_VERSION
  98. + # LLVM_VERSION
  99. + # LLVM_VERSION_STRING
  100. + if(NOT DEFINED PACKAGE_VERSION)
  101. + if(DEFINED LLVM_PACKAGE_VERSION)
  102. + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
  103. + elseif(DEFINED LLVM_VERSION)
  104. + set(PACKAGE_VERSION "${LLVM_VERSION}")
  105. + elseif(DEFINED LLVM_VERSION_STRING)
  106. + set(PACKAGE_VERSION "${LLVM_VERSION_STRING}")
  107. + endif()
  108. + endif()
  109. +
  110. + # Check the following variables:
  111. + # LLVM_LIBRARIES
  112. + # LLVM_LIBS
  113. + set(libs)
  114. + if(DEFINED LLVM_LIBRARIES)
  115. + set(libs LLVM_LIBRARIES)
  116. + elseif(DEFINED LLVM_LIBS)
  117. + set(libs LLVM_LIBS)
  118. + endif()
  119. +
  120. + # Check the following variables:
  121. + # LLVM_INCLUDE_DIRS
  122. + # LLVM_INCLUDES
  123. + # LLVM_INCLUDE_DIR
  124. + set(includes)
  125. + if(DEFINED LLVM_INCLUDE_DIRS)
  126. + set(includes LLVM_INCLUDE_DIRS)
  127. + elseif(DEFINED LLVM_INCLUDES)
  128. + set(includes LLVM_INCLUDES)
  129. + elseif(DEFINED LLVM_INCLUDE_DIR)
  130. + set(includes LLVM_INCLUDE_DIR)
  131. + endif()
  132. +
  133. + # Check the following variables:
  134. + # LLVM_DEFINITIONS
  135. + set(definitions)
  136. + if(DEFINED LLVM_DEFINITIONS)
  137. + set(definitions LLVM_DEFINITIONS)
  138. + endif()
  139. +
  140. + set(PACKAGE_INCLUDE_DIRS "${${includes}}")
  141. + set(PACKAGE_DEFINITIONS "${${definitions}}")
  142. + set(PACKAGE_LIBRARIES "${${libs}}")
  143. +endif()
  144. +'''
  145. +
  146. +file_1_data_CMakePathInfo_txt = '''\
  147. +cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION})
  148. +
  149. +set(TMP_PATHS_LIST)
  150. +list(APPEND TMP_PATHS_LIST ${CMAKE_PREFIX_PATH})
  151. +list(APPEND TMP_PATHS_LIST ${CMAKE_FRAMEWORK_PATH})
  152. +list(APPEND TMP_PATHS_LIST ${CMAKE_APPBUNDLE_PATH})
  153. +list(APPEND TMP_PATHS_LIST $ENV{CMAKE_PREFIX_PATH})
  154. +list(APPEND TMP_PATHS_LIST $ENV{CMAKE_FRAMEWORK_PATH})
  155. +list(APPEND TMP_PATHS_LIST $ENV{CMAKE_APPBUNDLE_PATH})
  156. +list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_PREFIX_PATH})
  157. +list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_FRAMEWORK_PATH})
  158. +list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_APPBUNDLE_PATH})
  159. +
  160. +set(LIB_ARCH_LIST)
  161. +if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
  162. + file(GLOB implicit_dirs RELATIVE /lib /lib/*-linux-gnu* )
  163. + foreach(dir ${implicit_dirs})
  164. + if("${dir}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}")
  165. + list(APPEND LIB_ARCH_LIST "${dir}")
  166. + endif()
  167. + endforeach()
  168. +endif()
  169. +
  170. +# "Export" these variables:
  171. +set(MESON_ARCH_LIST ${LIB_ARCH_LIST})
  172. +set(MESON_PATHS_LIST ${TMP_PATHS_LIST})
  173. +set(MESON_CMAKE_ROOT ${CMAKE_ROOT})
  174. +set(MESON_CMAKE_SYSROOT ${CMAKE_SYSROOT})
  175. +set(MESON_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH})
  176. +
  177. +message(STATUS ${TMP_PATHS_LIST})
  178. +'''
  179. +
  180. +file_2_data_CMakeLists_txt = '''\
  181. +# fail noisily if attempt to use this file without setting:
  182. +# cmake_minimum_required(VERSION ${CMAKE_VERSION})
  183. +# project(... LANGUAGES ...)
  184. +
  185. +cmake_policy(SET CMP0000 NEW)
  186. +
  187. +set(PACKAGE_FOUND FALSE)
  188. +set(_packageName "${NAME}")
  189. +string(TOUPPER "${_packageName}" PACKAGE_NAME)
  190. +
  191. +while(TRUE)
  192. + find_package("${NAME}" QUIET COMPONENTS ${COMPS})
  193. +
  194. + # ARCHS has to be set via the CMD interface
  195. + if(${_packageName}_FOUND OR ${PACKAGE_NAME}_FOUND OR "${ARCHS}" STREQUAL "")
  196. + break()
  197. + endif()
  198. +
  199. + list(GET ARCHS 0 CMAKE_LIBRARY_ARCHITECTURE)
  200. + list(REMOVE_AT ARCHS 0)
  201. +endwhile()
  202. +
  203. +if(${_packageName}_FOUND OR ${PACKAGE_NAME}_FOUND)
  204. + set(PACKAGE_FOUND TRUE)
  205. +
  206. + # Check the following variables:
  207. + # FOO_VERSION
  208. + # Foo_VERSION
  209. + # FOO_VERSION_STRING
  210. + # Foo_VERSION_STRING
  211. + if(NOT DEFINED PACKAGE_VERSION)
  212. + if(DEFINED ${_packageName}_VERSION)
  213. + set(PACKAGE_VERSION "${${_packageName}_VERSION}")
  214. + elseif(DEFINED ${PACKAGE_NAME}_VERSION)
  215. + set(PACKAGE_VERSION "${${PACKAGE_NAME}_VERSION}")
  216. + elseif(DEFINED ${_packageName}_VERSION_STRING)
  217. + set(PACKAGE_VERSION "${${_packageName}_VERSION_STRING}")
  218. + elseif(DEFINED ${PACKAGE_NAME}_VERSION_STRING)
  219. + set(PACKAGE_VERSION "${${PACKAGE_NAME}_VERSION_STRING}")
  220. + endif()
  221. + endif()
  222. +
  223. + # Check the following variables:
  224. + # FOO_LIBRARIES
  225. + # Foo_LIBRARIES
  226. + # FOO_LIBS
  227. + # Foo_LIBS
  228. + set(libs)
  229. + if(DEFINED ${_packageName}_LIBRARIES)
  230. + set(libs ${_packageName}_LIBRARIES)
  231. + elseif(DEFINED ${PACKAGE_NAME}_LIBRARIES)
  232. + set(libs ${PACKAGE_NAME}_LIBRARIES)
  233. + elseif(DEFINED ${_packageName}_LIBS)
  234. + set(libs ${_packageName}_LIBS)
  235. + elseif(DEFINED ${PACKAGE_NAME}_LIBS)
  236. + set(libs ${PACKAGE_NAME}_LIBS)
  237. + endif()
  238. +
  239. + # Check the following variables:
  240. + # FOO_INCLUDE_DIRS
  241. + # Foo_INCLUDE_DIRS
  242. + # FOO_INCLUDES
  243. + # Foo_INCLUDES
  244. + # FOO_INCLUDE_DIR
  245. + # Foo_INCLUDE_DIR
  246. + set(includes)
  247. + if(DEFINED ${_packageName}_INCLUDE_DIRS)
  248. + set(includes ${_packageName}_INCLUDE_DIRS)
  249. + elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIRS)
  250. + set(includes ${PACKAGE_NAME}_INCLUDE_DIRS)
  251. + elseif(DEFINED ${_packageName}_INCLUDES)
  252. + set(includes ${_packageName}_INCLUDES)
  253. + elseif(DEFINED ${PACKAGE_NAME}_INCLUDES)
  254. + set(includes ${PACKAGE_NAME}_INCLUDES)
  255. + elseif(DEFINED ${_packageName}_INCLUDE_DIR)
  256. + set(includes ${_packageName}_INCLUDE_DIR)
  257. + elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIR)
  258. + set(includes ${PACKAGE_NAME}_INCLUDE_DIR)
  259. + endif()
  260. +
  261. + # Check the following variables:
  262. + # FOO_DEFINITIONS
  263. + # Foo_DEFINITIONS
  264. + set(definitions)
  265. + if(DEFINED ${_packageName}_DEFINITIONS)
  266. + set(definitions ${_packageName}_DEFINITIONS)
  267. + elseif(DEFINED ${PACKAGE_NAME}_DEFINITIONS)
  268. + set(definitions ${PACKAGE_NAME}_DEFINITIONS)
  269. + endif()
  270. +
  271. + set(PACKAGE_INCLUDE_DIRS "${${includes}}")
  272. + set(PACKAGE_DEFINITIONS "${${definitions}}")
  273. + set(PACKAGE_LIBRARIES "${${libs}}")
  274. +endif()
  275. +'''
  276. +
  277. +file_3_data_preload_cmake = '''\
  278. +if(MESON_PS_LOADED)
  279. + return()
  280. +endif()
  281. +
  282. +set(MESON_PS_LOADED ON)
  283. +
  284. +# Dummy macros that have a special meaning in the meson code
  285. +macro(meson_ps_execute_delayed_calls)
  286. +endmacro()
  287. +
  288. +macro(meson_ps_reload_vars)
  289. +endmacro()
  290. +
  291. +# Helper macro to inspect the current CMake state
  292. +macro(meson_ps_inspect_vars)
  293. + set(MESON_PS_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  294. + set(MESON_PS_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  295. + meson_ps_execute_delayed_calls()
  296. +endmacro()
  297. +
  298. +
  299. +# Override some system functions with custom code and forward the args
  300. +# to the original function
  301. +macro(add_custom_command)
  302. + meson_ps_inspect_vars()
  303. + _add_custom_command(${ARGV})
  304. +endmacro()
  305. +
  306. +macro(add_custom_target)
  307. + meson_ps_inspect_vars()
  308. + _add_custom_target(${ARGV})
  309. +endmacro()
  310. +
  311. +macro(set_property)
  312. + meson_ps_inspect_vars()
  313. + _set_property(${ARGV})
  314. +endmacro()
  315. +
  316. +function(set_source_files_properties)
  317. + set(FILES)
  318. + set(I 0)
  319. + set(PROPERTIES OFF)
  320. +
  321. + while(I LESS ARGC)
  322. + if(NOT PROPERTIES)
  323. + if("${ARGV${I}}" STREQUAL "PROPERTIES")
  324. + set(PROPERTIES ON)
  325. + else()
  326. + list(APPEND FILES "${ARGV${I}}")
  327. + endif()
  328. +
  329. + math(EXPR I "${I} + 1")
  330. + else()
  331. + set(ID_IDX ${I})
  332. + math(EXPR PROP_IDX "${ID_IDX} + 1")
  333. +
  334. + set(ID "${ARGV${ID_IDX}}")
  335. + set(PROP "${ARGV${PROP_IDX}}")
  336. +
  337. + set_property(SOURCE ${FILES} PROPERTY "${ID}" "${PROP}")
  338. + math(EXPR I "${I} + 2")
  339. + endif()
  340. + endwhile()
  341. +endfunction()
  342. +
  343. +set(MESON_PS_DELAYED_CALLS add_custom_command;add_custom_target;set_property)
  344. +meson_ps_reload_vars()
  345. +'''
  346. +
  347. +
  348. +####################
  349. +# END Data section #
  350. +####################
  351. +
  352. +class DataFile:
  353. + def __init__(self, path: Path, sha256sum: str, data: str) -> None:
  354. + self.path = path
  355. + self.sha256sum = sha256sum
  356. + self.data = data
  357. +
  358. + def write_once(self, path: Path) -> None:
  359. + if not path.exists():
  360. + path.write_text(self.data)
  361. +
  362. + def write_to_private(self, env: 'Environment') -> Path:
  363. + out_file = Path(env.scratch_dir) / 'data' / self.path.name
  364. + out_file.parent.mkdir(exist_ok=True)
  365. + self.write_once(out_file)
  366. + return out_file
  367. +
  368. +
  369. +mesondata = {
  370. + 'dependencies/data/CMakeListsLLVM.txt': DataFile(
  371. + Path('dependencies/data/CMakeListsLLVM.txt'),
  372. + '412cec3315597041a978d018cdaca282dcd47693793540da88ae2f80d0cbd7cd',
  373. + file_0_data_CMakeListsLLVM_txt,
  374. + ),
  375. + 'dependencies/data/CMakePathInfo.txt': DataFile(
  376. + Path('dependencies/data/CMakePathInfo.txt'),
  377. + '90da8b443982d9c87139b7dc84228eb58cab4315764949637208f25e2bda7db2',
  378. + file_1_data_CMakePathInfo_txt,
  379. + ),
  380. + 'dependencies/data/CMakeLists.txt': DataFile(
  381. + Path('dependencies/data/CMakeLists.txt'),
  382. + '71a2d58381f912bbfb1c8709884d34d721f682edf2fca001e1f582f0bffd0da7',
  383. + file_2_data_CMakeLists_txt,
  384. + ),
  385. + 'cmake/data/preload.cmake': DataFile(
  386. + Path('cmake/data/preload.cmake'),
  387. + '064d047b18a5c919ad016b838bed50c5d40aebe9e53da0e70eff9d52a2c1ca1f',
  388. + file_3_data_preload_cmake,
  389. + ),
  390. +}
  391. diff --git a/tools/gen_data.py b/tools/gen_data.py
  392. new file mode 100755
  393. index 0000000000..2cc05a44e7
  394. --- /dev/null
  395. +++ b/tools/gen_data.py
  396. @@ -0,0 +1,139 @@
  397. +#!/usr/bin/env python3
  398. +
  399. +# Copyright 2020 Daniel Mensinger
  400. +
  401. +# Licensed under the Apache License, Version 2.0 (the "License");
  402. +# you may not use this file except in compliance with the License.
  403. +# You may obtain a copy of the License at
  404. +
  405. +# http://www.apache.org/licenses/LICENSE-2.0
  406. +
  407. +# Unless required by applicable law or agreed to in writing, software
  408. +# distributed under the License is distributed on an "AS IS" BASIS,
  409. +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  410. +# See the License for the specific language governing permissions and
  411. +# limitations under the License.
  412. +
  413. +import sys
  414. +import hashlib
  415. +import textwrap
  416. +import re
  417. +from pathlib import Path
  418. +from datetime import datetime
  419. +import typing as T
  420. +
  421. +class DataFile:
  422. + file_counter = 0
  423. +
  424. + def __init__(self, path: Path, root: Path):
  425. + self.path = path
  426. + self.id = self.path.relative_to(root)
  427. + self.data_str = f'file_{DataFile.file_counter}_data_' + re.sub('[^a-zA-Z0-9]', '_', self.path.name)
  428. + DataFile.file_counter += 1
  429. +
  430. + b = self.path.read_bytes()
  431. + self.data = b.decode()
  432. + self.sha256sum = hashlib.sha256(b).hexdigest()
  433. +
  434. + def __repr__(self) -> str:
  435. + return f'<{type(self).__name__}: [{self.sha256sum}] {self.id}>'
  436. +
  437. +def main() -> int:
  438. + root_dir = Path(__file__).resolve().parents[1]
  439. + mesonbuild_dir = root_dir / 'mesonbuild'
  440. + out_file = mesonbuild_dir / 'mesondata.py'
  441. +
  442. + data_dirs = mesonbuild_dir.glob('**/data')
  443. +
  444. + data_files: T.List[DataFile] = []
  445. +
  446. + for d in data_dirs:
  447. + for p in d.iterdir():
  448. + data_files += [DataFile(p, mesonbuild_dir)]
  449. +
  450. + print(f'Found {len(data_files)} data files')
  451. +
  452. + # Generate the data script
  453. + data = ''
  454. +
  455. + data += textwrap.dedent(f'''\
  456. + # Copyright {datetime.today().year} The Meson development team
  457. +
  458. + # Licensed under the Apache License, Version 2.0 (the "License");
  459. + # you may not use this file except in compliance with the License.
  460. + # You may obtain a copy of the License at
  461. +
  462. + # http://www.apache.org/licenses/LICENSE-2.0
  463. +
  464. + # Unless required by applicable law or agreed to in writing, software
  465. + # distributed under the License is distributed on an "AS IS" BASIS,
  466. + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  467. + # See the License for the specific language governing permissions and
  468. + # limitations under the License.
  469. +
  470. +
  471. + ####
  472. + #### WARNING: This is an automatically generated file! Do not edit!
  473. + #### Generated by {Path(__file__).resolve().relative_to(root_dir)}
  474. + ####
  475. +
  476. +
  477. + from pathlib import Path
  478. + import typing as T
  479. +
  480. + if T.TYPE_CHECKING:
  481. + from .environment import Environment
  482. +
  483. + ######################
  484. + # BEGIN Data section #
  485. + ######################
  486. +
  487. + ''')
  488. +
  489. + for i in data_files:
  490. + data += f"{i.data_str} = '''\\\n{i.data}'''\n\n"
  491. +
  492. + data += textwrap.dedent(f'''
  493. + ####################
  494. + # END Data section #
  495. + ####################
  496. +
  497. + class DataFile:
  498. + def __init__(self, path: Path, sha256sum: str, data: str) -> None:
  499. + self.path = path
  500. + self.sha256sum = sha256sum
  501. + self.data = data
  502. +
  503. + def write_once(self, path: Path) -> None:
  504. + if not path.exists():
  505. + path.write_text(self.data)
  506. +
  507. + def write_to_private(self, env: 'Environment') -> Path:
  508. + out_file = Path(env.scratch_dir) / 'data' / self.path.name
  509. + out_file.parent.mkdir(exist_ok=True)
  510. + self.write_once(out_file)
  511. + return out_file
  512. +
  513. +
  514. + mesondata = {{
  515. + ''')
  516. +
  517. + for i in data_files:
  518. + data += textwrap.indent(textwrap.dedent(f"""\
  519. + '{i.id}': DataFile(
  520. + Path('{i.id}'),
  521. + '{i.sha256sum}',
  522. + {i.data_str},
  523. + ),
  524. + """), ' ')
  525. +
  526. + data += textwrap.dedent('''\
  527. + }
  528. + ''')
  529. +
  530. + print(f'Updating {out_file}')
  531. + out_file.write_text(data)
  532. + return 0
  533. +
  534. +if __name__ == '__main__':
  535. + sys.exit(main())
  536. From 05ddd6543d4c4fc33b4c64f26291e73f49733f71 Mon Sep 17 00:00:00 2001
  537. From: Daniel Mensinger <daniel@mensinger-ka.de>
  538. Date: Thu, 16 Jul 2020 20:33:57 +0200
  539. Subject: [PATCH 2/3] mdata: remove setuptools and use mesondata instead
  540. ---
  541. mesonbuild/cmake/interpreter.py | 5 ++---
  542. mesonbuild/dependencies/base.py | 6 ++----
  543. setup.py | 5 -----
  544. 4 files changed, 4 insertions(+), 16 deletions(-)
  545. diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
  546. index 05169478e8..f404109cf6 100644
  547. --- a/mesonbuild/cmake/interpreter.py
  548. +++ b/mesonbuild/cmake/interpreter.py
  549. @@ -15,8 +15,6 @@
  550. # This class contains the basic functionality needed to run any interpreter
  551. # or an interpreter-based tool.
  552. -import pkg_resources
  553. -
  554. from .common import CMakeException, CMakeTarget, TargetOptions
  555. from .client import CMakeClient, RequestCMakeInputs, RequestConfigure, RequestCompute, RequestCodeModel
  556. from .fileapi import CMakeFileAPI
  557. @@ -25,6 +23,7 @@
  558. from .. import mlog, mesonlib
  559. from ..environment import Environment
  560. from ..mesonlib import MachineChoice, OrderedSet, version_compare
  561. +from ..mesondata import mesondata
  562. from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header
  563. from enum import Enum
  564. from functools import lru_cache
  565. @@ -814,7 +813,7 @@ def configure(self, extra_cmake_options: T.List[str]) -> None:
  566. raise CMakeException('Unable to find CMake')
  567. self.trace = CMakeTraceParser(cmake_exe.version(), self.build_dir, permissive=True)
  568. - preload_file = pkg_resources.resource_filename('mesonbuild', 'cmake/data/preload.cmake')
  569. + preload_file = mesondata['cmake/data/preload.cmake'].write_to_private(self.env)
  570. # Prefere CMAKE_PROJECT_INCLUDE over CMAKE_TOOLCHAIN_FILE if possible,
  571. # since CMAKE_PROJECT_INCLUDE was actually designed for code injection.
  572. diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
  573. index 23701da957..4c9c9fe18a 100644
  574. --- a/mesonbuild/dependencies/base.py
  575. +++ b/mesonbuild/dependencies/base.py
  576. @@ -29,8 +29,6 @@
  577. from enum import Enum
  578. from pathlib import Path, PurePath
  579. -import pkg_resources
  580. -
  581. from .. import mlog
  582. from .. import mesonlib
  583. from ..compilers import clib_langs
  584. @@ -40,6 +38,7 @@
  585. from ..mesonlib import MachineChoice, MesonException, OrderedSet, PerMachine
  586. from ..mesonlib import Popen_safe, version_compare_many, version_compare, listify, stringlistify, extract_as_list, split_args
  587. from ..mesonlib import Version, LibType
  588. +from ..mesondata import mesondata
  589. if T.TYPE_CHECKING:
  590. from ..compilers.compilers import CompilerType # noqa: F401
  591. @@ -1512,8 +1511,7 @@ def _setup_cmake_dir(self, cmake_file: str) -> str:
  592. build_dir = self._get_build_dir()
  593. # Insert language parameters into the CMakeLists.txt and write new CMakeLists.txt
  594. - # Per the warning in pkg_resources, this is *not* a path and os.path and Pathlib are *not* safe to use here.
  595. - cmake_txt = pkg_resources.resource_string('mesonbuild', 'dependencies/data/' + cmake_file).decode()
  596. + cmake_txt = mesondata['dependencies/data/' + cmake_file].data
  597. # In general, some Fortran CMake find_package() also require C language enabled,
  598. # even if nothing from C is directly used. An easy Fortran example that fails
  599. diff --git a/setup.py b/setup.py
  600. index 1f95be70c8..145f19c522 100644
  601. --- a/setup.py
  602. +++ b/setup.py
  603. @@ -37,10 +37,6 @@
  604. 'mesonbuild.scripts',
  605. 'mesonbuild.templates',
  606. 'mesonbuild.wrap']
  607. -package_data = {
  608. - 'mesonbuild.dependencies': ['data/CMakeLists.txt', 'data/CMakeListsLLVM.txt', 'data/CMakePathInfo.txt'],
  609. - 'mesonbuild.cmake': ['data/run_ctgt.py', 'data/preload.cmake'],
  610. -}
  611. data_files = []
  612. if sys.platform != 'win32':
  613. # Only useful on UNIX-like systems
  614. @@ -51,6 +47,5 @@
  615. setup(name='meson',
  616. version=version,
  617. packages=packages,
  618. - package_data=package_data,
  619. entry_points=entries,
  620. data_files=data_files,)
  621. From 393d6e133d9abd584a2fc414971628e84ea48b7c Mon Sep 17 00:00:00 2001
  622. From: Daniel Mensinger <daniel@mensinger-ka.de>
  623. Date: Thu, 16 Jul 2020 20:34:15 +0200
  624. Subject: [PATCH 3/3] mdata: Add test to ensure mesondata.py is up-to-date
  625. ---
  626. run_unittests.py | 32 ++++++++++++++++++++++++++++++++
  627. 1 file changed, 32 insertions(+)
  628. diff --git a/run_unittests.py b/run_unittests.py
  629. index 820b705b54..2c03a3e75c 100755
  630. --- a/run_unittests.py
  631. +++ b/run_unittests.py
  632. @@ -1485,6 +1485,38 @@ def test_all_functions_defined_in_ast_interpreter(self):
  633. astint = AstInterpreter('.', '', '')
  634. self.assertEqual(set(interp.funcs.keys()), set(astint.funcs.keys()))
  635. + def test_mesondata_is_up_to_date(self):
  636. + from mesonbuild.mesondata import mesondata
  637. + err_msg = textwrap.dedent('''
  638. +
  639. + ###########################################################
  640. + ### mesonbuild.mesondata is not up-to-date ###
  641. + ### Please regenerate it by running tools/gen_data.py ###
  642. + ###########################################################
  643. +
  644. + ''')
  645. +
  646. + root_dir = Path(__file__).resolve().parent
  647. + mesonbuild_dir = root_dir / 'mesonbuild'
  648. +
  649. + data_dirs = mesonbuild_dir.glob('**/data')
  650. + data_files = [] # type: T.List[T.Tuple(str, str)]
  651. +
  652. + for i in data_dirs:
  653. + for p in i.iterdir():
  654. + data_files += [(p.relative_to(mesonbuild_dir).as_posix(), hashlib.sha256(p.read_bytes()).hexdigest())]
  655. +
  656. + from pprint import pprint
  657. + current_files = set(mesondata.keys())
  658. + scanned_files = set([x[0] for x in data_files])
  659. +
  660. + self.assertSetEqual(current_files, scanned_files, err_msg + 'Data files were added or removed\n')
  661. + errors = []
  662. + for i in data_files:
  663. + if mesondata[i[0]].sha256sum != i[1]:
  664. + errors += [i[0]]
  665. +
  666. + self.assertListEqual(errors, [], err_msg + 'Files were changed')
  667. class BasePlatformTests(unittest.TestCase):
  668. prefix = '/usr'