Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1021 lines
32KB

  1. import argparse
  2. import gzip
  3. import os
  4. import json
  5. import json5
  6. import itertools
  7. import base64
  8. from urllib import request, parse as url_parse
  9. from typing import NamedTuple, Tuple, List, Sequence, Union, Optional, Mapping, Iterable
  10. import re
  11. from pathlib import Path
  12. import sys
  13. import textwrap
  14. from concurrent.futures import ThreadPoolExecutor
  15. class CopyMoveTransform(NamedTuple):
  16. frm: str
  17. to: str
  18. strip_components: int = 0
  19. include: Sequence[str] = []
  20. exclude: Sequence[str] = []
  21. def to_dict(self):
  22. return {
  23. 'from': self.frm,
  24. 'to': self.to,
  25. 'include': self.include,
  26. 'exclude': self.exclude,
  27. 'strip-components': self.strip_components,
  28. }
  29. class OneEdit(NamedTuple):
  30. kind: str
  31. line: int
  32. content: Optional[str] = None
  33. def to_dict(self):
  34. d = {
  35. 'kind': self.kind,
  36. 'line': self.line,
  37. }
  38. if self.content:
  39. d['content'] = self.content
  40. return d
  41. class EditTransform(NamedTuple):
  42. path: str
  43. edits: Sequence[OneEdit] = []
  44. def to_dict(self):
  45. return {
  46. 'path': self.path,
  47. 'edits': [e.to_dict() for e in self.edits],
  48. }
  49. class WriteTransform(NamedTuple):
  50. path: str
  51. content: str
  52. def to_dict(self):
  53. return {
  54. 'path': self.path,
  55. 'content': self.content,
  56. }
  57. class RemoveTransform(NamedTuple):
  58. path: str
  59. only_matching: Sequence[str] = ()
  60. def to_dict(self):
  61. return {
  62. 'path': self.path,
  63. 'only-matching': self.only_matching,
  64. }
  65. class FSTransform(NamedTuple):
  66. copy: Optional[CopyMoveTransform] = None
  67. move: Optional[CopyMoveTransform] = None
  68. remove: Optional[RemoveTransform] = None
  69. write: Optional[WriteTransform] = None
  70. edit: Optional[EditTransform] = None
  71. def to_dict(self):
  72. d = {}
  73. if self.copy:
  74. d['copy'] = self.copy.to_dict()
  75. if self.move:
  76. d['move'] = self.move.to_dict()
  77. if self.remove:
  78. d['remove'] = self.remove.to_dict()
  79. if self.write:
  80. d['write'] = self.write.to_dict()
  81. if self.edit:
  82. d['edit'] = self.edit.to_dict()
  83. return d
  84. class Git(NamedTuple):
  85. url: str
  86. ref: str
  87. auto_lib: Optional[str] = None
  88. transforms: Sequence[FSTransform] = []
  89. def to_dict(self) -> dict:
  90. d = {
  91. 'url': self.url,
  92. 'ref': self.ref,
  93. 'transform': [f.to_dict() for f in self.transforms],
  94. }
  95. if self.auto_lib:
  96. d['auto-lib'] = self.auto_lib
  97. return d
  98. def to_dict_2(self) -> str:
  99. url = f'git+{self.url}'
  100. if self.auto_lib:
  101. url += f'?lm={self.auto_lib}'
  102. url += f'#{self.ref}'
  103. return url
  104. RemoteInfo = Union[Git]
  105. class Version(NamedTuple):
  106. version: str
  107. remote: RemoteInfo
  108. depends: Sequence[str] = []
  109. description: str = '(No description provided)'
  110. def to_dict(self) -> dict:
  111. ret: dict = {
  112. 'description': self.description,
  113. 'depends': list(self.depends),
  114. }
  115. if isinstance(self.remote, Git):
  116. ret['git'] = self.remote.to_dict()
  117. return ret
  118. def to_dict_2(self) -> dict:
  119. ret: dict = {
  120. 'description': self.description,
  121. 'depends': list(self.depends),
  122. 'transform': [f.to_dict() for f in self.remote.transforms],
  123. }
  124. ret['url'] = self.remote.to_dict_2()
  125. return ret
  126. class VersionSet(NamedTuple):
  127. version: str
  128. depends: Sequence[str]
  129. class Package(NamedTuple):
  130. name: str
  131. versions: List[Version]
  132. HTTP_POOL = ThreadPoolExecutor(10)
  133. def github_http_get(url: str):
  134. url_dat = url_parse.urlparse(url)
  135. req = request.Request(url)
  136. req.add_header('Accept-Encoding', 'application/json')
  137. req.add_header('Authorization', f'token {os.environ["GITHUB_API_TOKEN"]}')
  138. if url_dat.hostname != 'api.github.com':
  139. raise RuntimeError(f'Request is outside of api.github.com [{url}]')
  140. resp = request.urlopen(req)
  141. if resp.status != 200:
  142. raise RuntimeError(
  143. f'Request to [{url}] failed [{resp.status} {resp.reason}]')
  144. return json5.loads(resp.read())
  145. def _get_github_tree_file_content(url: str) -> bytes:
  146. json_body = github_http_get(url)
  147. content_b64 = json_body['content'].encode()
  148. assert json_body['encoding'] == 'base64', json_body
  149. content = base64.decodebytes(content_b64)
  150. return content
  151. def _version_for_github_tag(pkg_name: str, desc: str, clone_url: str,
  152. tag) -> Version:
  153. print(f'Loading tag {tag["name"]}')
  154. commit = github_http_get(tag['commit']['url'])
  155. tree = github_http_get(commit['commit']['tree']['url'])
  156. tree_content = {t['path']: t for t in tree['tree']}
  157. cands = ['package.json', 'package.jsonc', 'package.json5']
  158. for cand in cands:
  159. if cand in tree_content:
  160. package_json_fname = cand
  161. break
  162. else:
  163. raise RuntimeError(
  164. f'No package JSON5 file in tag {tag["name"]} for {pkg_name} (One of {tree_content.keys()})'
  165. )
  166. package_json = json5.loads(
  167. _get_github_tree_file_content(tree_content[package_json_fname]['url']))
  168. version = package_json['version']
  169. if pkg_name != package_json['name']:
  170. raise RuntimeError(f'package name in repo "{package_json["name"]}" '
  171. f'does not match expected name "{pkg_name}"')
  172. depends = package_json.get('depends')
  173. pairs: Iterable[str]
  174. if isinstance(depends, dict):
  175. pairs = ((k + v) for k, v in depends.items())
  176. elif isinstance(depends, list):
  177. pairs = depends
  178. elif depends is None:
  179. pairs = []
  180. else:
  181. raise RuntimeError(
  182. f'Unknown "depends" object from json file: {depends!r}')
  183. remote = Git(url=clone_url, ref=tag['name'])
  184. return Version(
  185. version, description=desc, depends=list(pairs), remote=remote)
  186. def github_package(name: str, repo: str, want_tags: Iterable[str]) -> Package:
  187. print(f'Downloading repo from {repo}')
  188. repo_data = github_http_get(f'https://api.github.com/repos/{repo}')
  189. desc = repo_data['description']
  190. avail_tags = github_http_get(repo_data['tags_url'])
  191. missing_tags = set(want_tags) - set(t['name'] for t in avail_tags)
  192. if missing_tags:
  193. raise RuntimeError(
  194. 'One or more wanted tags do not exist in '
  195. f'the repository "{repo}" (Missing: {missing_tags})')
  196. tag_items = (t for t in avail_tags if t['name'] in want_tags)
  197. versions = HTTP_POOL.map(
  198. lambda tag: _version_for_github_tag(name, desc, repo_data['clone_url'], tag),
  199. tag_items)
  200. return Package(name, list(versions))
  201. def simple_packages(name: str,
  202. description: str,
  203. git_url: str,
  204. versions: Sequence[VersionSet],
  205. auto_lib: Optional[str] = None,
  206. *,
  207. tag_fmt: str = '{}') -> Package:
  208. return Package(name, [
  209. Version(
  210. ver.version,
  211. description=description,
  212. remote=Git(
  213. git_url, tag_fmt.format(ver.version), auto_lib=auto_lib),
  214. depends=ver.depends) for ver in versions
  215. ])
  216. def many_versions(name: str,
  217. versions: Sequence[str],
  218. *,
  219. tag_fmt: str = '{}',
  220. git_url: str,
  221. auto_lib: str = None,
  222. transforms: Sequence[FSTransform] = (),
  223. description='(No description was provided)') -> Package:
  224. return Package(name, [
  225. Version(
  226. ver,
  227. description='\n'.join(textwrap.wrap(description)),
  228. remote=Git(
  229. url=git_url,
  230. ref=tag_fmt.format(ver),
  231. auto_lib=auto_lib,
  232. transforms=transforms)) for ver in versions
  233. ])
  234. # yapf: disable
  235. PACKAGES = [
  236. github_package('neo-buffer', 'vector-of-bool/neo-buffer',
  237. ['0.2.1', '0.3.0', '0.4.0', '0.4.1', '0.4.2']),
  238. github_package('neo-compress', 'vector-of-bool/neo-compress', ['0.1.0', '0.1.1']),
  239. github_package('neo-url', 'vector-of-bool/neo-url',
  240. ['0.1.0', '0.1.1', '0.1.2', '0.2.0', '0.2.1', '0.2.2']),
  241. github_package('neo-sqlite3', 'vector-of-bool/neo-sqlite3',
  242. ['0.2.3', '0.3.0', '0.4.0', '0.4.1']),
  243. github_package('neo-fun', 'vector-of-bool/neo-fun', [
  244. '0.1.1', '0.2.0', '0.2.1', '0.3.0', '0.3.1', '0.3.2', '0.4.0', '0.4.1',
  245. '0.4.2', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5',
  246. ]),
  247. github_package('neo-io', 'vector-of-bool/neo-io', ['0.1.0']),
  248. github_package('neo-http', 'vector-of-bool/neo-http', ['0.1.0']),
  249. github_package('neo-concepts', 'vector-of-bool/neo-concepts', (
  250. '0.2.2',
  251. '0.3.0',
  252. '0.3.1',
  253. '0.3.2',
  254. '0.4.0',
  255. )),
  256. github_package('semver', 'vector-of-bool/semver', ['0.2.2']),
  257. github_package('pubgrub', 'vector-of-bool/pubgrub', ['0.2.1']),
  258. github_package('vob-json5', 'vector-of-bool/json5', ['0.1.5']),
  259. github_package('vob-semester', 'vector-of-bool/semester',
  260. ['0.1.0', '0.1.1', '0.2.0', '0.2.1', '0.2.2']),
  261. many_versions(
  262. 'magic_enum',
  263. (
  264. '0.5.0',
  265. '0.6.0',
  266. '0.6.1',
  267. '0.6.2',
  268. '0.6.3',
  269. '0.6.4',
  270. '0.6.5',
  271. '0.6.6',
  272. ),
  273. description='Static reflection for enums',
  274. tag_fmt='v{}',
  275. git_url='https://github.com/Neargye/magic_enum.git',
  276. auto_lib='neargye/magic_enum',
  277. ),
  278. many_versions(
  279. 'nameof',
  280. [
  281. '0.8.3',
  282. '0.9.0',
  283. '0.9.1',
  284. '0.9.2',
  285. '0.9.3',
  286. '0.9.4',
  287. ],
  288. description='Nameof operator for modern C++',
  289. tag_fmt='v{}',
  290. git_url='https://github.com/Neargye/nameof.git',
  291. auto_lib='neargye/nameof',
  292. ),
  293. many_versions(
  294. 'range-v3',
  295. (
  296. '0.5.0',
  297. '0.9.0',
  298. '0.9.1',
  299. '0.10.0',
  300. '0.11.0',
  301. ),
  302. git_url='https://github.com/ericniebler/range-v3.git',
  303. auto_lib='range-v3/range-v3',
  304. description=
  305. 'Range library for C++14/17/20, basis for C++20\'s std::ranges',
  306. ),
  307. many_versions(
  308. 'nlohmann-json',
  309. (
  310. # '3.0.0',
  311. # '3.0.1',
  312. # '3.1.0',
  313. # '3.1.1',
  314. # '3.1.2',
  315. # '3.2.0',
  316. # '3.3.0',
  317. # '3.4.0',
  318. # '3.5.0',
  319. # '3.6.0',
  320. # '3.6.1',
  321. # '3.7.0',
  322. '3.7.1', # Only this version has the dds forked branch
  323. # '3.7.2',
  324. # '3.7.3',
  325. ),
  326. git_url='https://github.com/vector-of-bool/json.git',
  327. tag_fmt='dds/{}',
  328. description='JSON for Modern C++',
  329. ),
  330. Package('ms-wil', [
  331. Version(
  332. '2020.03.16',
  333. description='The Windows Implementation Library',
  334. remote=Git('https://github.com/vector-of-bool/wil.git',
  335. 'dds/2020.03.16'))
  336. ]),
  337. many_versions(
  338. 'ctre',
  339. (
  340. '2.8.1',
  341. '2.8.2',
  342. '2.8.3',
  343. '2.8.4',
  344. ),
  345. git_url=
  346. 'https://github.com/hanickadot/compile-time-regular-expressions.git',
  347. tag_fmt='v{}',
  348. auto_lib='hanickadot/ctre',
  349. description=
  350. 'A compile-time PCRE (almost) compatible regular expression matcher',
  351. ),
  352. Package(
  353. 'spdlog',
  354. [
  355. Version(
  356. ver,
  357. description='Fast C++ logging library',
  358. depends=['fmt+6.0.0'],
  359. remote=Git(
  360. url='https://github.com/gabime/spdlog.git',
  361. ref=f'v{ver}',
  362. transforms=[
  363. FSTransform(
  364. write=WriteTransform(
  365. path='package.json',
  366. content=json.dumps({
  367. 'name': 'spdlog',
  368. 'namespace': 'spdlog',
  369. 'version': ver,
  370. 'depends': ['fmt+6.0.0'],
  371. }))),
  372. FSTransform(
  373. write=WriteTransform(
  374. path='library.json',
  375. content=json.dumps({
  376. 'name': 'spdlog',
  377. 'uses': ['fmt/fmt']
  378. }))),
  379. FSTransform(
  380. # It's all just template instantiations.
  381. remove=RemoveTransform(path='src/'),
  382. # Tell spdlog to use the external fmt library
  383. edit=EditTransform(
  384. path='include/spdlog/tweakme.h',
  385. edits=[
  386. OneEdit(
  387. kind='insert',
  388. content='#define SPDLOG_FMT_EXTERNAL 1',
  389. line=13,
  390. ),
  391. ])),
  392. ],
  393. ),
  394. ) for ver in (
  395. '1.4.0',
  396. '1.4.1',
  397. '1.4.2',
  398. '1.5.0',
  399. '1.6.0',
  400. '1.6.1',
  401. '1.7.0',
  402. )
  403. ]),
  404. many_versions(
  405. 'fmt',
  406. (
  407. '6.0.0',
  408. '6.1.0',
  409. '6.1.1',
  410. '6.1.2',
  411. '6.2.0',
  412. '6.2.1',
  413. '7.0.0',
  414. '7.0.1',
  415. '7.0.2',
  416. '7.0.3',
  417. ),
  418. git_url='https://github.com/fmtlib/fmt.git',
  419. auto_lib='fmt/fmt',
  420. description='A modern formatting library : https://fmt.dev/',
  421. ),
  422. Package('catch2', [
  423. Version(
  424. '2.12.4',
  425. description='A modern C++ unit testing library',
  426. remote=Git(
  427. 'https://github.com/catchorg/Catch2.git',
  428. 'v2.12.4',
  429. auto_lib='catch2/catch2',
  430. transforms=[
  431. FSTransform(
  432. move=CopyMoveTransform(
  433. frm='include', to='include/catch2')),
  434. FSTransform(
  435. copy=CopyMoveTransform(frm='include', to='src'),
  436. write=WriteTransform(
  437. path='include/catch2/catch_with_main.hpp',
  438. content='''
  439. #pragma once
  440. #define CATCH_CONFIG_MAIN
  441. #include "./catch.hpp"
  442. namespace Catch {
  443. CATCH_REGISTER_REPORTER("console", ConsoleReporter)
  444. }
  445. ''')),
  446. ]))
  447. ]),
  448. Package('asio', [
  449. Version(
  450. ver,
  451. description='Asio asynchronous I/O C++ library',
  452. remote=Git(
  453. 'https://github.com/chriskohlhoff/asio.git',
  454. f'asio-{ver.replace(".", "-")}',
  455. auto_lib='asio/asio',
  456. transforms=[
  457. FSTransform(
  458. move=CopyMoveTransform(
  459. frm='asio/src',
  460. to='src/',
  461. ),
  462. remove=RemoveTransform(
  463. path='src/',
  464. only_matching=[
  465. 'doc/**',
  466. 'examples/**',
  467. 'tests/**',
  468. 'tools/**',
  469. ],
  470. ),
  471. ),
  472. FSTransform(
  473. move=CopyMoveTransform(
  474. frm='asio/include/',
  475. to='include/',
  476. ),
  477. edit=EditTransform(
  478. path='include/asio/detail/config.hpp',
  479. edits=[
  480. OneEdit(
  481. line=13,
  482. kind='insert',
  483. content='#define ASIO_STANDALONE 1'),
  484. OneEdit(
  485. line=14,
  486. kind='insert',
  487. content=
  488. '#define ASIO_SEPARATE_COMPILATION 1')
  489. ]),
  490. ),
  491. ]),
  492. ) for ver in [
  493. '1.12.0',
  494. '1.12.1',
  495. '1.12.2',
  496. '1.13.0',
  497. '1.14.0',
  498. '1.14.1',
  499. '1.16.0',
  500. '1.16.1',
  501. ]
  502. ]),
  503. Package(
  504. 'abseil',
  505. [
  506. Version(
  507. ver,
  508. description='Abseil Common Libraries',
  509. remote=Git(
  510. 'https://github.com/abseil/abseil-cpp.git',
  511. tag,
  512. auto_lib='abseil/abseil',
  513. transforms=[
  514. FSTransform(
  515. move=CopyMoveTransform(
  516. frm='absl',
  517. to='src/absl/',
  518. ),
  519. remove=RemoveTransform(
  520. path='src/',
  521. only_matching=[
  522. '**/*_test.c*',
  523. '**/*_testing.c*',
  524. '**/*_benchmark.c*',
  525. '**/benchmarks.c*',
  526. '**/*_test_common.c*',
  527. '**/mocking_*.c*',
  528. # Misc files that should be removed:
  529. '**/test_util.cc',
  530. '**/mutex_nonprod.cc',
  531. '**/named_generator.cc',
  532. '**/print_hash_of.cc',
  533. '**/*_gentables.cc',
  534. ]),
  535. )
  536. ]),
  537. ) for ver, tag in [
  538. ('2018.6.0', '20180600'),
  539. ('2019.8.8', '20190808'),
  540. ('2020.2.25', '20200225.2'),
  541. ]
  542. ]),
  543. Package('zlib', [
  544. Version(
  545. ver,
  546. description=
  547. 'A massively spiffy yet delicately unobtrusive compression library',
  548. remote=Git(
  549. 'https://github.com/madler/zlib.git',
  550. tag or f'v{ver}',
  551. auto_lib='zlib/zlib',
  552. transforms=[
  553. FSTransform(
  554. move=CopyMoveTransform(
  555. frm='.',
  556. to='src/',
  557. include=[
  558. '*.c',
  559. '*.h',
  560. ],
  561. )),
  562. FSTransform(
  563. move=CopyMoveTransform(
  564. frm='src/',
  565. to='include/',
  566. include=['zlib.h', 'zconf.h'],
  567. )),
  568. ]),
  569. ) for ver, tag in [
  570. ('1.2.11', None),
  571. ('1.2.10', None),
  572. ('1.2.9', None),
  573. ('1.2.8', None),
  574. ('1.2.7', 'v1.2.7.3'),
  575. ('1.2.6', 'v1.2.6.1'),
  576. ('1.2.5', 'v1.2.5.3'),
  577. ('1.2.4', 'v1.2.4.5'),
  578. ('1.2.3', 'v1.2.3.8'),
  579. ('1.2.2', 'v1.2.2.4'),
  580. ('1.2.1', 'v1.2.1.2'),
  581. ('1.2.0', 'v1.2.0.8'),
  582. ]
  583. ]),
  584. Package('sol2', [
  585. Version(
  586. ver,
  587. description=
  588. 'A C++ <-> Lua API wrapper with advanced features and top notch performance',
  589. depends=['lua+0.0.0'],
  590. remote=Git(
  591. 'https://github.com/ThePhD/sol2.git',
  592. f'v{ver}',
  593. transforms=[
  594. FSTransform(
  595. write=WriteTransform(
  596. path='package.json',
  597. content=json.dumps(
  598. {
  599. 'name': 'sol2',
  600. 'namespace': 'sol2',
  601. 'version': ver,
  602. 'depends': [f'lua+0.0.0'],
  603. },
  604. indent=2,
  605. )),
  606. move=(None
  607. if ver.startswith('3.') else CopyMoveTransform(
  608. frm='sol',
  609. to='src/sol',
  610. )),
  611. ),
  612. FSTransform(
  613. write=WriteTransform(
  614. path='library.json',
  615. content=json.dumps(
  616. {
  617. 'name': 'sol2',
  618. 'uses': ['lua/lua'],
  619. },
  620. indent=2,
  621. ))),
  622. ]),
  623. ) for ver in [
  624. '3.2.1',
  625. '3.2.0',
  626. '3.0.3',
  627. '3.0.2',
  628. '2.20.6',
  629. '2.20.5',
  630. '2.20.4',
  631. '2.20.3',
  632. '2.20.2',
  633. '2.20.1',
  634. '2.20.0',
  635. ]
  636. ]),
  637. Package('lua', [
  638. Version(
  639. ver,
  640. description=
  641. 'Lua is a powerful and fast programming language that is easy to learn and use and to embed into your application.',
  642. remote=Git(
  643. 'https://github.com/lua/lua.git',
  644. f'v{ver}',
  645. auto_lib='lua/lua',
  646. transforms=[
  647. FSTransform(
  648. move=CopyMoveTransform(
  649. frm='.',
  650. to='src/',
  651. include=['*.c', '*.h'],
  652. ))
  653. ]),
  654. ) for ver in [
  655. '5.4.0',
  656. '5.3.5',
  657. '5.3.4',
  658. '5.3.3',
  659. '5.3.2',
  660. '5.3.1',
  661. '5.3.0',
  662. '5.2.3',
  663. '5.2.2',
  664. '5.2.1',
  665. '5.2.0',
  666. '5.1.1',
  667. ]
  668. ]),
  669. Package('pegtl', [
  670. Version(
  671. ver,
  672. description='Parsing Expression Grammar Template Library',
  673. remote=Git(
  674. 'https://github.com/taocpp/PEGTL.git',
  675. ver,
  676. auto_lib='tao/pegtl',
  677. transforms=[FSTransform(remove=RemoveTransform(path='src/'))],
  678. )) for ver in [
  679. '2.8.3',
  680. '2.8.2',
  681. '2.8.1',
  682. '2.8.0',
  683. '2.7.1',
  684. '2.7.0',
  685. '2.6.1',
  686. '2.6.0',
  687. ]
  688. ]),
  689. many_versions(
  690. 'boost.pfr', ['1.0.0', '1.0.1'],
  691. auto_lib='boost/pfr',
  692. git_url='https://github.com/apolukhin/magic_get.git'),
  693. many_versions(
  694. 'boost.leaf',
  695. [
  696. '0.1.0',
  697. '0.2.0',
  698. '0.2.1',
  699. '0.2.2',
  700. '0.2.3',
  701. '0.2.4',
  702. '0.2.5',
  703. '0.3.0',
  704. ],
  705. auto_lib='boost/leaf',
  706. git_url='https://github.com/zajo/leaf.git',
  707. ),
  708. many_versions(
  709. 'boost.mp11',
  710. ['1.70.0', '1.71.0', '1.72.0', '1.73.0'],
  711. tag_fmt='boost-{}',
  712. git_url='https://github.com/boostorg/mp11.git',
  713. auto_lib='boost/mp11',
  714. ),
  715. many_versions(
  716. 'libsodium', [
  717. '1.0.10',
  718. '1.0.11',
  719. '1.0.12',
  720. '1.0.13',
  721. '1.0.14',
  722. '1.0.15',
  723. '1.0.16',
  724. '1.0.17',
  725. '1.0.18',
  726. ],
  727. git_url='https://github.com/jedisct1/libsodium.git',
  728. auto_lib='sodium/sodium',
  729. description='Sodium is a new, easy-to-use software library '
  730. 'for encryption, decryption, signatures, password hashing and more.',
  731. transforms=[
  732. FSTransform(
  733. move=CopyMoveTransform(
  734. frm='src/libsodium/include', to='include/'),
  735. edit=EditTransform(
  736. path='include/sodium/export.h',
  737. edits=[
  738. OneEdit(
  739. line=8,
  740. kind='insert',
  741. content='#define SODIUM_STATIC 1')
  742. ])),
  743. FSTransform(
  744. edit=EditTransform(
  745. path='include/sodium/private/common.h',
  746. edits=[
  747. OneEdit(
  748. kind='insert',
  749. line=1,
  750. content=Path(__file__).parent.joinpath(
  751. 'libsodium-config.h').read_text(),
  752. )
  753. ])),
  754. FSTransform(
  755. copy=CopyMoveTransform(
  756. frm='builds/msvc/version.h',
  757. to='include/sodium/version.h',
  758. ),
  759. move=CopyMoveTransform(
  760. frm='src/libsodium',
  761. to='src/',
  762. ),
  763. remove=RemoveTransform(path='src/libsodium'),
  764. ),
  765. FSTransform(
  766. copy=CopyMoveTransform(
  767. frm='include', to='src/', strip_components=1)),
  768. ]),
  769. many_versions(
  770. 'tomlpp',
  771. [
  772. '1.0.0',
  773. '1.1.0',
  774. '1.2.0',
  775. '1.2.3',
  776. '1.2.4',
  777. '1.2.5',
  778. '1.3.0',
  779. # '1.3.2', # Wrong tag name in upstream
  780. '1.3.3',
  781. '2.0.0',
  782. ],
  783. tag_fmt='v{}',
  784. git_url='https://github.com/marzer/tomlplusplus.git',
  785. auto_lib='tomlpp/tomlpp',
  786. description=
  787. 'Header-only TOML config file parser and serializer for modern C++'),
  788. Package('inja', [
  789. *(Version(
  790. ver,
  791. description='A Template Engine for Modern C++',
  792. remote=Git(
  793. 'https://github.com/pantor/inja.git',
  794. f'v{ver}',
  795. auto_lib='inja/inja')) for ver in ('1.0.0', '2.0.0', '2.0.1')),
  796. *(Version(
  797. ver,
  798. description='A Template Engine for Modern C++',
  799. depends=['nlohmann-json+0.0.0'],
  800. remote=Git(
  801. 'https://github.com/pantor/inja.git',
  802. f'v{ver}',
  803. transforms=[
  804. FSTransform(
  805. write=WriteTransform(
  806. path='package.json',
  807. content=json.dumps({
  808. 'name':
  809. 'inja',
  810. 'namespace':
  811. 'inja',
  812. 'version':
  813. ver,
  814. 'depends': [
  815. 'nlohmann-json+0.0.0',
  816. ]
  817. }))),
  818. FSTransform(
  819. write=WriteTransform(
  820. path='library.json',
  821. content=json.dumps({
  822. 'name': 'inja',
  823. 'uses': ['nlohmann/json']
  824. }))),
  825. ],
  826. )) for ver in ('2.1.0', '2.2.0')),
  827. ]),
  828. many_versions(
  829. 'cereal',
  830. [
  831. '0.9.0',
  832. '0.9.1',
  833. '1.0.0',
  834. '1.1.0',
  835. '1.1.1',
  836. '1.1.2',
  837. '1.2.0',
  838. '1.2.1',
  839. '1.2.2',
  840. '1.3.0',
  841. ],
  842. auto_lib='cereal/cereal',
  843. git_url='https://github.com/USCiLab/cereal.git',
  844. tag_fmt='v{}',
  845. description='A C++11 library for serialization',
  846. ),
  847. many_versions(
  848. 'pybind11',
  849. [
  850. '2.0.0',
  851. '2.0.1',
  852. '2.1.0',
  853. '2.1.1',
  854. '2.2.0',
  855. '2.2.1',
  856. '2.2.2',
  857. '2.2.3',
  858. '2.2.4',
  859. '2.3.0',
  860. '2.4.0',
  861. '2.4.1',
  862. '2.4.2',
  863. '2.4.3',
  864. '2.5.0',
  865. ],
  866. git_url='https://github.com/pybind/pybind11.git',
  867. description='Seamless operability between C++11 and Python',
  868. auto_lib='pybind/pybind11',
  869. tag_fmt='v{}',
  870. ),
  871. Package('pcg-cpp', [
  872. Version(
  873. '0.98.1',
  874. description='PCG Randum Number Generation, C++ Edition',
  875. remote=Git(
  876. url='https://github.com/imneme/pcg-cpp.git',
  877. ref='v0.98.1',
  878. auto_lib='pcg/pcg-cpp'))
  879. ]),
  880. many_versions(
  881. 'hinnant-date',
  882. ['2.4.1', '3.0.0'],
  883. description=
  884. 'A date and time library based on the C++11/14/17 <chrono> header',
  885. auto_lib='hinnant/date',
  886. git_url='https://github.com/HowardHinnant/date.git',
  887. tag_fmt='v{}',
  888. transforms=[FSTransform(remove=RemoveTransform(path='src/'))],
  889. ),
  890. ]
  891. # yapf: enable
  892. if __name__ == "__main__":
  893. parser = argparse.ArgumentParser()
  894. args = parser.parse_args()
  895. data = {
  896. 'version': 2,
  897. 'packages': {
  898. pkg.name: {ver.version: ver.to_dict_2()
  899. for ver in pkg.versions}
  900. for pkg in PACKAGES
  901. }
  902. }
  903. old_data = {
  904. 'version': 1,
  905. 'packages': {
  906. pkg.name: {ver.version: ver.to_dict()
  907. for ver in pkg.versions}
  908. for pkg in PACKAGES
  909. }
  910. }
  911. json_str = json.dumps(data, indent=2, sort_keys=True)
  912. Path('catalog.json').write_text(json_str)
  913. Path('catalog.old.json').write_text(
  914. json.dumps(old_data, indent=2, sort_keys=True))
  915. cpp_template = textwrap.dedent(r'''
  916. #include <dds/catalog/package_info.hpp>
  917. #include <dds/catalog/init_catalog.hpp>
  918. #include <dds/catalog/import.hpp>
  919. #include <neo/gzip.hpp>
  920. #include <neo/transform_io.hpp>
  921. #include <neo/string_io.hpp>
  922. #include <neo/inflate.hpp>
  923. /**
  924. * The following array of integers is generated and contains gzip-compressed
  925. * JSON encoded initial catalog. MSVC can't handle string literals over
  926. * 64k large, so we have to resort to using a regular char array:
  927. */
  928. static constexpr const unsigned char INIT_PACKAGES_CONTENT[] = {
  929. @JSON@
  930. };
  931. const std::vector<dds::package_info>&
  932. dds::init_catalog_packages() noexcept {
  933. using std::nullopt;
  934. static auto pkgs = []{
  935. using namespace neo;
  936. string_dynbuf_io str_out;
  937. buffer_copy(str_out,
  938. buffer_transform_source{
  939. buffers_consumer(as_buffer(INIT_PACKAGES_CONTENT)),
  940. gzip_decompressor{inflate_decompressor{}}},
  941. @JSON_LEN@);
  942. return dds::parse_packages_json(str_out.read_area_view());
  943. }();
  944. return pkgs;
  945. }
  946. ''')
  947. json_small = json.dumps(data, sort_keys=True)
  948. json_compr = gzip.compress(json_small.encode('utf-8'), compresslevel=9)
  949. json_small_arr = ','.join(str(c) for c in json_compr)
  950. cpp_content = cpp_template.replace('@JSON@', json_small_arr).replace(
  951. '@JSON_LEN@', str(len(json_small)))
  952. Path('src/dds/catalog/init_catalog.cpp').write_text(cpp_content)