/
pkg-standalone.py
50 lines (40 loc) · 1.37 KB
/
pkg-standalone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import configparser
import os
import os.path
import shlex
import sys
from subprocess import run
if __name__ == '__main__':
submodule = False
if len(sys.argv) == 2:
if sys.argv[1] != 'submodule':
print('usage: python3 pkg-standalone.py [submodule]')
sys.exit(1)
submodule = True
cfg = configparser.ConfigParser()
cfg.read('.pkg')
os.makedirs('deps', exist_ok=True)
for name in cfg.sections():
url = cfg[name]['url']
commit = cfg[name]['commit']
path = os.path.join('deps', name)
if os.path.exists(path):
print('skip:', path)
continue
if submodule:
cmd = 'git submodule add -f {} {}'.format(url, path)
print(name, ' : ', cmd)
run(shlex.split(cmd), check=True)
else:
cmd = 'git clone --no-checkout {} {}'.format(url, path)
print(name, ' : ', cmd)
run(shlex.split(cmd), check=True)
cmd = 'git checkout {}'.format(commit)
print(name, ' : ', cmd)
run(shlex.split(cmd), cwd=path, check=True)
with open('deps/CMakeLists.txt', 'w') as f:
f.write('project(deps)\n')
f.write('cmake_minimum_required(VERSION 3.10)\n\n')
for name in cfg.sections():
f.write('add_subdirectory({} EXCLUDE_FROM_ALL)\n'.format(name))