blob: daf714376044fd946abb40d0eb6b41ff62e67a1b (
plain)
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
|
import os
import toml
from glob import glob
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# ======= load test list
tests = {}
for f in sorted(glob('./src/bin/*.rs')):
name = os.path.splitext(os.path.basename(f))[0]
features = []
with open(f, 'r') as f:
for line in f:
if line.startswith('// required-features:'):
features = [feature.strip() for feature in line.split(':', 2)[1].strip().split(',')]
tests[name] = features
# ========= Update Cargo.toml
things = {
'bin': [
{
'name': f'{name}',
'path': f'src/bin/{name}.rs',
'required-features': features,
}
for name, features in tests.items()
]
}
SEPARATOR_START = '# BEGIN TESTS\n'
SEPARATOR_END = '# END TESTS\n'
HELP = '# Generated by gen_test.py. DO NOT EDIT.\n'
with open('Cargo.toml', 'r') as f:
data = f.read()
before, data = data.split(SEPARATOR_START, maxsplit=1)
_, after = data.split(SEPARATOR_END, maxsplit=1)
data = before + SEPARATOR_START + HELP + \
toml.dumps(things) + SEPARATOR_END + after
with open('Cargo.toml', 'w') as f:
f.write(data)
|