build 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #!/usr/bin/env python3
  2. import re
  3. import os
  4. import cli_function
  5. import collections
  6. import common
  7. import copy
  8. import itertools
  9. import math
  10. import subprocess
  11. import shell_helpers
  12. from shell_helpers import LF
  13. import lkmc
  14. class _Component:
  15. '''
  16. Yes, we are re-inventing a crappy dependency resolution system,
  17. reminiscent of scons or apt or Buildroot. I can't believe it.
  18. The hard part is that we have optional dependencies as well...
  19. e.g. Buildroot optionally depends on m5 to put m5 in the root filesystem,
  20. and Buildroot optionally depends on QEMU to build the qcow2 version
  21. of the image.
  22. '''
  23. def __init__(
  24. self,
  25. build_callback=None,
  26. supported_archs=None,
  27. dependencies=None,
  28. apt_get_pkgs=None,
  29. apt_build_deps=None,
  30. submodules=None,
  31. submodules_shallow=None,
  32. python2_pkgs=None,
  33. python3_pkgs=None,
  34. ruby_pkgs=None,
  35. ):
  36. self.build_callback = build_callback
  37. self.supported_archs = supported_archs
  38. self.dependencies = dependencies or set()
  39. self.apt_get_pkgs = apt_get_pkgs or set()
  40. self.apt_build_deps = apt_build_deps or set()
  41. self.submodules = submodules or set()
  42. self.submodules_shallow = submodules_shallow or set()
  43. self.python2_pkgs = python2_pkgs or set()
  44. self.python3_pkgs = python3_pkgs or set()
  45. self.ruby_pkgs = ruby_pkgs or set()
  46. def build(self, arch):
  47. if (
  48. (self.build_callback is not None) and
  49. (self.supported_archs is None or arch in self.supported_archs)
  50. ):
  51. self.build_callback()
  52. submodule_extra_remotes = {
  53. 'binutils-gdb': {
  54. 'up': 'git://sourceware.org/git/binutils-gdb.git',
  55. },
  56. 'buildroot': {
  57. 'up': 'https://gem5.googlesource.com/public/gem5',
  58. },
  59. 'crosstool-ng': {
  60. 'up': 'https://github.com/crosstool-ng/crosstool-ng',
  61. },
  62. 'gcc': {
  63. 'up': 'git://gcc.gnu.org/git/gcc.git',
  64. },
  65. 'gem5': {
  66. 'up': 'https://gem5.googlesource.com/public/gem5',
  67. },
  68. 'glibc': {
  69. 'up': 'git://sourceware.org/git/glibc.git',
  70. },
  71. 'linux': {
  72. # https://cirosantilli.com/linux-kernel-module-cheat#gem5-arm-linux-kernel-patches
  73. 'gem5-arm': 'https://gem5.googlesource.com/arm/linux',
  74. 'up': 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git',
  75. },
  76. 'qemu': {
  77. 'up': 'https://git.qemu.org/git/qemu.git',
  78. },
  79. 'xen': {
  80. 'up': 'git://xenbits.xen.org/xen.git',
  81. },
  82. }
  83. class Main(common.LkmcCliFunction):
  84. def __init__(self):
  85. super().__init__(
  86. description='''\
  87. Build a component and all its dependencies.
  88. Our build-* scripts don't build any dependencies to make iterative
  89. development fast and more predictable.
  90. It is currently not possible to configure individual components from the command line
  91. when you build with this script. TODO.
  92. Without any args, build only what is necessary for:
  93. https://cirosantilli.com/linux-kernel-module-cheat#qemu-buildroot-setup
  94. ....
  95. ./%(prog)s
  96. ....
  97. This is equivalent to:
  98. ....
  99. ./%(prog)s --arch x86_64 qemu-buildroot
  100. ....
  101. Another important target is `all`:
  102. ....
  103. ./%(prog)s all
  104. ....
  105. This does not truly build ALL configurations: that would be impractical.
  106. But more precisely: build the reference configuration of each major component.
  107. So e.g.: one config of Linux kernel, Buildroot, gem5 and QEMU.
  108. Don't do for example all possible gem5 configs: debug, opt and fast,
  109. as that would be huge. This ensures that every piece of software
  110. builds in at least one config.
  111. TODO looping over emulators is not currently supported by this script, e.g.:
  112. ....
  113. ./%(prog)s --arch x86_64 --arch aarch64 all
  114. ....
  115. Instead, for the targets that are emulator dependent, you must select the
  116. taret version for the desired emulator, e.g.:
  117. ....
  118. ./build --arch aarch64 baremetal-qemu baremetal-gem5
  119. ....
  120. The reason is that some targets depend on emulator, while others don't,
  121. so looping over all of them would waste time.
  122. ''',
  123. )
  124. buildroot_component = _Component(
  125. self._build_file('build-buildroot'),
  126. submodules_shallow = {
  127. 'buildroot',
  128. 'binutils-gdb',
  129. 'gcc',
  130. 'glibc',
  131. },
  132. # https://buildroot.org/downloads/manual/manual.html#requirement
  133. apt_get_pkgs={
  134. 'bash',
  135. 'bc',
  136. 'binutils',
  137. 'build-essential',
  138. 'bzip2',
  139. 'cpio',
  140. 'g++',
  141. 'gcc',
  142. 'graphviz',
  143. 'gzip',
  144. 'make',
  145. 'patch',
  146. 'perl',
  147. 'python-matplotlib',
  148. 'python3',
  149. 'rsync',
  150. 'sed',
  151. 'tar',
  152. 'unzip',
  153. },
  154. )
  155. buildroot_overlay_qemu_component = copy.copy(buildroot_component)
  156. # We need to build QEMU before the final Buildroot to get qemu-img.
  157. buildroot_overlay_qemu_component.dependencies = ['overlay', 'qemu']
  158. buildroot_overlay_gem5_component = copy.copy(buildroot_component)
  159. buildroot_overlay_gem5_component.dependencies = ['overlay-gem5']
  160. gem5_deps = {
  161. # TODO test it out on Docker and answer that question properly:
  162. # https://askubuntu.com/questions/350475/how-can-i-install-gem5
  163. 'apt_get_pkgs': {
  164. 'device-tree-compiler',
  165. 'diod',
  166. 'libgoogle-perftools-dev',
  167. 'libboost-all-dev',
  168. 'm4',
  169. 'protobuf-compiler',
  170. 'python-dev',
  171. 'python-pip',
  172. # For prebuilt qcow2 unpack.
  173. 'qemu-utils',
  174. 'scons',
  175. 'zlib1g-dev',
  176. },
  177. 'python2_pkgs': {
  178. # Generate graphs of config.ini under m5out.
  179. 'pydot',
  180. },
  181. 'submodules_shallow': {'gem5'},
  182. }
  183. self.name_to_component_map = {
  184. 'all': _Component(dependencies=[
  185. 'qemu-gem5-buildroot',
  186. 'all-baremetal',
  187. 'user-mode-qemu',
  188. 'doc',
  189. ]),
  190. 'all-baremetal': _Component(dependencies=[
  191. 'qemu-baremetal',
  192. 'gem5-baremetal',
  193. 'baremetal-gem5-pbx',
  194. ],
  195. supported_archs=common.consts['crosstool_ng_supported_archs'],
  196. ),
  197. 'baremetal': _Component(dependencies=[
  198. 'baremetal-gem5',
  199. 'baremetal-qemu',
  200. ]),
  201. 'baremetal-qemu': _Component(
  202. self._build_file('build-baremetal', emulators=['qemu']),
  203. supported_archs=common.consts['crosstool_ng_supported_archs'],
  204. dependencies=['crosstool-ng'],
  205. ),
  206. 'baremetal-gem5': _Component(
  207. self._build_file('build-baremetal', emulators=['gem5']),
  208. supported_archs=common.consts['crosstool_ng_supported_archs'],
  209. dependencies=['crosstool-ng'],
  210. ),
  211. 'baremetal-gem5-pbx': _Component(
  212. self._build_file('build-baremetal', emulators=['gem5'], machine='RealViewPBX'),
  213. supported_archs=common.consts['crosstool_ng_supported_archs'],
  214. dependencies=['crosstool-ng'],
  215. ),
  216. 'buildroot': buildroot_component,
  217. # We need those to avoid circular dependencies, since we need to run Buildroot
  218. # twice: once to get the toolchain, and a second time to put the overlay into
  219. # the root filesystem.
  220. 'buildroot-overlay-qemu': buildroot_overlay_qemu_component,
  221. 'buildroot-overlay-gem5': buildroot_overlay_gem5_component,
  222. 'copy-overlay': _Component(
  223. self._build_file('copy-overlay'),
  224. ),
  225. 'crosstool-ng': _Component(
  226. self._build_file('build-crosstool-ng'),
  227. supported_archs=common.consts['crosstool_ng_supported_archs'],
  228. # http://crosstool-ng.github.io/docs/os-setup/
  229. apt_get_pkgs={
  230. 'bison',
  231. 'docbook2x',
  232. 'flex',
  233. 'gawk',
  234. 'gcc',
  235. 'gperf',
  236. 'help2man',
  237. 'libncurses5-dev',
  238. 'libtool-bin',
  239. 'make',
  240. 'python-dev',
  241. 'texinfo',
  242. },
  243. submodules_shallow={'crosstool-ng'},
  244. ),
  245. 'doc': _Component(
  246. self._build_file('build-doc'),
  247. ruby_pkgs={
  248. 'asciidoctor',
  249. },
  250. ),
  251. 'gem5': _Component(
  252. self._build_file('build-gem5'),
  253. **gem5_deps
  254. ),
  255. 'gem5-baremetal': _Component(dependencies=[
  256. 'gem5',
  257. 'baremetal-gem5',
  258. ]),
  259. 'gem5-buildroot': _Component(dependencies=[
  260. 'buildroot-overlay-gem5',
  261. 'linux',
  262. 'gem5',
  263. ]),
  264. 'gem5-debug': _Component(
  265. self._build_file('build-gem5', gem5_build_type='debug'),
  266. **gem5_deps
  267. ),
  268. 'gem5-fast': _Component(
  269. self._build_file('build-gem5', gem5_build_type='fast'),
  270. **gem5_deps
  271. ),
  272. 'linux': _Component(
  273. self._build_file('build-linux'),
  274. dependencies={'buildroot'},
  275. submodules_shallow={'linux'},
  276. apt_get_pkgs={
  277. 'bison',
  278. 'flex',
  279. # Without this started failing in kernel 4.15 with:
  280. # Makefile:932: *** "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel". Stop.
  281. 'libelf-dev',
  282. },
  283. ),
  284. 'modules': _Component(
  285. self._build_file('build-modules'),
  286. dependencies=['buildroot', 'linux'],
  287. ),
  288. 'm5': _Component(
  289. self._build_file('build-m5'),
  290. dependencies=['buildroot'],
  291. submodules_shallow={'gem5'},
  292. ),
  293. 'overlay': _Component(dependencies=[
  294. 'copy-overlay',
  295. 'modules',
  296. 'userland',
  297. ]),
  298. 'overlay-gem5': _Component(dependencies=[
  299. 'm5',
  300. 'overlay',
  301. ]),
  302. 'parsec-benchmark': _Component(
  303. submodules_shallow={'parsec-benchmark'},
  304. dependencies=['buildroot'],
  305. ),
  306. 'qemu': _Component(
  307. self._build_file('build-qemu'),
  308. apt_build_deps={'qemu'},
  309. apt_get_pkgs={'libsdl2-dev'},
  310. submodules={'qemu'},
  311. ),
  312. 'qemu-baremetal': _Component(dependencies=[
  313. 'qemu',
  314. 'baremetal-qemu',
  315. ]),
  316. 'qemu-buildroot': _Component(dependencies=[
  317. 'buildroot-overlay-qemu',
  318. 'linux',
  319. ]),
  320. 'qemu-gem5-buildroot': _Component(dependencies=[
  321. 'qemu',
  322. 'gem5-buildroot',
  323. ]),
  324. 'qemu-user': _Component(
  325. self._build_file('build-qemu', mode='userland'),
  326. apt_build_deps = {'qemu'},
  327. apt_get_pkgs={'libsdl2-dev'},
  328. submodules={'qemu'},
  329. ),
  330. 'release': _Component(dependencies=[
  331. 'baremetal-qemu',
  332. 'qemu-buildroot',
  333. 'doc',
  334. ]),
  335. 'test-gdb': _Component(dependencies=[
  336. 'all-baremetal',
  337. 'userland',
  338. ],
  339. ),
  340. 'test-executables-userland': _Component(dependencies=[
  341. 'test-executables-userland-qemu',
  342. 'test-executables-userland-gem5',
  343. ]),
  344. 'test-executables-userland-qemu': _Component(dependencies=[
  345. 'user-mode-qemu',
  346. 'userland',
  347. ]),
  348. 'test-executables-userland-gem5': _Component(dependencies=[
  349. 'gem5',
  350. 'userland-gem5',
  351. ]),
  352. 'user-mode-qemu': _Component(
  353. dependencies=['qemu-user', 'userland'],
  354. ),
  355. 'userland': _Component(
  356. self._build_file('build-userland'),
  357. dependencies=['buildroot'],
  358. ),
  359. 'userland-host': _Component(
  360. self._build_file('build-userland-in-tree'),
  361. apt_get_pkgs={
  362. 'libdrm-dev',
  363. 'libeigen3-dev',
  364. 'libopenblas-dev',
  365. },
  366. ),
  367. 'userland-gem5': _Component(
  368. self._build_file('build-userland', static=True, userland_build_id='static'),
  369. dependencies=['buildroot'],
  370. ),
  371. }
  372. self.component_to_name_map = {self.name_to_component_map[key]:key for key in self.name_to_component_map}
  373. self.add_argument(
  374. '--apt',
  375. default=True,
  376. help='''\
  377. Don't run any apt-get commands. To make it easier to use with other archs:
  378. https://cirosantilli.com/linux-kernel-module-cheat#supported-hosts
  379. '''
  380. )
  381. self.add_argument(
  382. '--download-dependencies',
  383. default=False,
  384. help='''\
  385. Also download all dependencies required for a given build: Ubuntu packages,
  386. Python packages and git submodules.
  387. '''
  388. )
  389. self.add_argument(
  390. '--print-components',
  391. default=False,
  392. help='''\
  393. Print the components that would be built, including dependencies, but don't
  394. build them, nor show the build commands.
  395. '''
  396. )
  397. self.add_argument(
  398. '--travis',
  399. default=False,
  400. help='''\
  401. Extra args to pass to all scripts.
  402. '''
  403. )
  404. self.add_argument(
  405. 'components',
  406. choices=list(self.name_to_component_map.keys()) + [[]],
  407. default=[],
  408. nargs='*',
  409. help='''\
  410. Which components to build. Default: qemu-buildroot
  411. '''
  412. )
  413. def _build_file(self, component_file, **extra_args):
  414. '''
  415. Build something based on a component file that defines a Main class.
  416. '''
  417. def f():
  418. args = self.get_common_args()
  419. args.update(extra_args)
  420. args['show_time'] = False
  421. lkmc.import_path.import_path_main(component_file)(**args)
  422. return f
  423. def timed_main(self):
  424. self.sh = shell_helpers.ShellHelpers(dry_run=self.env['dry_run'])
  425. # Decide components.
  426. components = self.env['components']
  427. if components == []:
  428. components = ['qemu-buildroot']
  429. selected_components = []
  430. for component_name in components:
  431. todo = [component_name]
  432. while todo:
  433. current_name = todo.pop(0)
  434. component = self.name_to_component_map[current_name]
  435. selected_components.insert(0, component)
  436. todo.extend(component.dependencies)
  437. # Remove duplicates, keep only the first one of each.
  438. # https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists/7961390#7961390
  439. selected_components = collections.OrderedDict.fromkeys(selected_components)
  440. if self.env['download_dependencies']:
  441. apt_get_pkgs = {
  442. # Core requirements for this repo.
  443. 'git',
  444. 'moreutils', # ts
  445. 'python3-pip',
  446. 'rr',
  447. 'tmux',
  448. 'vinagre',
  449. 'wget',
  450. }
  451. # E.g. on an ARM host, the package gcc-arm-linux-gnueabihf
  452. # is called just gcc.
  453. processor = self.env['host_arch']
  454. if processor != 'arm':
  455. apt_get_pkgs.update({
  456. 'gcc-arm-linux-gnueabihf',
  457. 'g++-arm-linux-gnueabihf',
  458. })
  459. if processor != 'aarch64':
  460. apt_get_pkgs.update({
  461. 'gcc-aarch64-linux-gnu',
  462. 'g++-aarch64-linux-gnu',
  463. })
  464. apt_build_deps = set()
  465. submodules = set()
  466. submodules_shallow = set()
  467. python2_pkgs = set()
  468. python3_pkgs = {
  469. 'pexpect==4.6.0',
  470. }
  471. ruby_pkgs = set()
  472. for component in selected_components:
  473. apt_get_pkgs.update(component.apt_get_pkgs)
  474. apt_build_deps.update(component.apt_build_deps)
  475. submodules.update(component.submodules)
  476. submodules_shallow.update(component.submodules_shallow)
  477. python2_pkgs.update(component.python2_pkgs)
  478. python3_pkgs.update(component.python3_pkgs)
  479. python3_pkgs.update(component.python3_pkgs)
  480. ruby_pkgs.update(component.ruby_pkgs)
  481. if ruby_pkgs:
  482. apt_get_pkgs.add('ruby')
  483. if apt_get_pkgs or apt_build_deps:
  484. if self.env['travis']:
  485. interacive_pkgs = {
  486. 'libsdl2-dev',
  487. }
  488. apt_get_pkgs.difference_update(interacive_pkgs)
  489. if common.consts['in_docker']:
  490. sudo = []
  491. # https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai
  492. os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
  493. # https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list
  494. sources_path = os.path.join('/etc', 'apt', 'sources.list')
  495. with open(sources_path, 'r') as f:
  496. sources_txt = f.read()
  497. sources_txt = re.sub('^# deb-src ', 'deb-src ', sources_txt, flags=re.MULTILINE)
  498. with open(sources_path, 'w') as f:
  499. f.write(sources_txt)
  500. else:
  501. sudo = ['sudo']
  502. if common.consts['in_docker'] or self.env['travis']:
  503. y = ['-y']
  504. else:
  505. y = []
  506. if self.env['apt']:
  507. self.sh.run_cmd(
  508. sudo + ['apt-get', 'update', LF]
  509. )
  510. if apt_get_pkgs:
  511. self.sh.run_cmd(
  512. sudo + ['apt-get', 'install'] + y + [LF] +
  513. self.sh.add_newlines(sorted(apt_get_pkgs))
  514. )
  515. if apt_build_deps:
  516. self.sh.run_cmd(
  517. sudo +
  518. ['apt-get', 'build-dep'] + y + [LF] +
  519. self.sh.add_newlines(sorted(apt_build_deps))
  520. )
  521. if python2_pkgs:
  522. self.sh.run_cmd(
  523. ['python', '-m', 'pip', 'install', '--user', LF] +
  524. self.sh.add_newlines(sorted(python2_pkgs))
  525. )
  526. if python3_pkgs:
  527. # Not with pip executable directly:
  528. # https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main/51846054#51846054
  529. self.sh.run_cmd(
  530. ['python3', '-m', 'pip', 'install', '--user', LF] +
  531. self.sh.add_newlines(sorted(python3_pkgs))
  532. )
  533. if ruby_pkgs:
  534. # The right thing to do would be to use RVM and avoid sudo,
  535. # but we felt it was too much boilerplate for now.
  536. #
  537. # --user-install does work here, but we still need to add
  538. # the binary to PATH which is a pain:
  539. # https://stackoverflow.com/questions/31596273/install-gem-in-local-folder
  540. self.sh.run_cmd(['sudo', 'gem', 'install', 'bundler', LF])
  541. # No ones knows how to do this without sudo:
  542. # https://stackoverflow.com/questions/16376995/bundler-cannot-install-any-gems-without-sudo/27677094
  543. self.sh.run_cmd([
  544. 'sudo', LF,
  545. 'bundle', LF,
  546. 'install', LF,
  547. '--gemfile', os.path.join(self.env['root_dir'], 'Gemfile'), LF,
  548. ])
  549. git_cmd_common = [
  550. 'git', LF,
  551. 'submodule', LF,
  552. 'update', LF,
  553. '--init', LF,
  554. '--recursive', LF,
  555. ]
  556. if self.env['dry_run']:
  557. git_version_tuple = (math.inf, math.inf, math.inf)
  558. else:
  559. git_version_tuple = tuple(
  560. int(x) for x in self.sh.check_output(['git', '--version']) \
  561. .decode().split(' ')[-1].split('.')[:3]
  562. )
  563. if git_version_tuple >= (2, 9, 0):
  564. # https://stackoverflow.com/questions/26957237/how-to-make-git-clone-faster-with-multiple-threads/52327638#52327638
  565. git_cmd_common.extend(['--jobs', str(len(os.sched_getaffinity(0))), LF])
  566. if git_version_tuple >= (2, 10, 0):
  567. # * https://stackoverflow.com/questions/32944468/how-to-show-progress-for-submodule-fetching
  568. # * https://stackoverflow.com/questions/4640020/progress-indicator-for-git-clone
  569. git_cmd_common.extend(['--progress', LF])
  570. def submodule_ids_to_cmd(submodules):
  571. return self.sh.add_newlines([os.path.join(common.consts['submodules_dir'], x) for x in sorted(submodules)])
  572. if submodules:
  573. self.sh.run_cmd(git_cmd_common + ['--', LF] + submodule_ids_to_cmd(submodules))
  574. if submodules_shallow:
  575. # TODO Ideally we should shallow clone --depth 1 all of them.
  576. #
  577. # However, most git servers out there are crap or craply configured
  578. # and don't allow shallow cloning except for branches.
  579. #
  580. # So for now I'm keeping all mirrors in my GitHub.
  581. # and always have a lkmc-* branch pointint to it.
  582. #
  583. # However, QEMU has a bunch of submodules itself, and I'm not in the mood
  584. # to mirror all of them...
  585. #
  586. # See also:
  587. #
  588. # * https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset
  589. # * https://stackoverflow.com/questions/2144406/git-shallow-submodules/47374702#47374702
  590. # * https://unix.stackexchange.com/questions/338578/why-is-the-git-clone-of-the-linux-kernel-source-code-much-larger-than-the-extrac
  591. cmd = git_cmd_common.copy()
  592. if git_version_tuple > (2, 7, 4):
  593. # Then there is a bug in Ubuntu 16.04 git 2.7.4 where --depth 1 fails...
  594. # OMG git submodules implementation sucks:
  595. # * https://stackoverflow.com/questions/2155887/git-submodule-head-reference-is-not-a-tree-error/25875273#25875273
  596. # * https://github.com/boostorg/boost/issues/245
  597. cmd.extend(['--depth', '1', LF])
  598. else:
  599. self.log_warn('your git is too old for git submodule update --depth 1')
  600. self.log_warn('update to git 2.17 or newer and you will save clone time')
  601. self.log_warn('see: https://github.com/cirosantilli/linux-kernel-module-cheat/issues/44')
  602. self.sh.run_cmd(cmd + ['--', LF] + submodule_ids_to_cmd(submodules_shallow))
  603. for submodule_name in submodule_extra_remotes:
  604. submodule = submodule_extra_remotes[submodule_name]
  605. for remote_name in submodule:
  606. self.sh.run_cmd(
  607. [
  608. 'git', LF,
  609. '-C', os.path.join(common.consts['submodules_dir'], submodule_name), LF,
  610. 'remote', LF,
  611. 'add', LF,
  612. remote_name, LF,
  613. submodule[remote_name], LF,
  614. ],
  615. # In case the remote already exists.
  616. raise_on_failure=False
  617. )
  618. # Do the build.
  619. for component in selected_components:
  620. if self.env['print_components']:
  621. print(self.component_to_name_map[component])
  622. else:
  623. component.build(self.env['arch'])
  624. if __name__ == '__main__':
  625. Main().cli()