Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

990 linhas
31KB

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