Skip to content

Commit a6360d5

Browse files
committed
scripts: Add script to apply configs to a source tree
1 parent c43de0b commit a6360d5

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/misc/apply-configs.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Apply configs from etc/configs/ to the local kernel tree.
4+
#
5+
# eg.
6+
# $ cd ~/linux
7+
# $ make ppc64le_defconfig
8+
# $ ~/ci-scripts/scripts/misc/apply-configs.py 4k-pages compat-y
9+
# $ make olddefconfig
10+
#
11+
# Or a group of configs defined in configs.py:
12+
#
13+
# $ ~/ci-scripts/scripts/misc/apply-configs.py guest_configs
14+
15+
16+
from subprocess import run
17+
import os, sys
18+
19+
base_dir = os.path.realpath(f'{os.path.dirname(os.path.realpath(sys.argv[0]))}/../..')
20+
sys.path.append(f'{base_dir}/lib')
21+
22+
import configs
23+
24+
25+
def main(args):
26+
if len(args) == 0:
27+
print('Usage: apply-configs.py (config group|config file)+')
28+
return False
29+
30+
names = []
31+
for arg in args:
32+
try:
33+
group = getattr(configs, arg)
34+
except AttributeError:
35+
names.append(arg)
36+
else:
37+
names.extend(group)
38+
39+
src_dir = os.getcwd()
40+
paths = []
41+
for name in names:
42+
# Look in source tree first, which must be current directory
43+
full_path = f'{src_dir}/{name}'
44+
if os.path.exists(full_path):
45+
paths.append((name, full_path))
46+
continue
47+
48+
full_path = f'{base_dir}/etc/configs/{name}'
49+
if not name.endswith('.config'):
50+
full_path += '.config'
51+
52+
if not os.path.exists(full_path):
53+
print(f'Error: unable to find {name}')
54+
return False
55+
56+
paths.append((name, full_path))
57+
58+
kbuild_output = os.environ.get('KBUILD_OUTPUT', None)
59+
if kbuild_output:
60+
# merge_config.sh writes its TMP files to $PWD, so change into KBUILD_OUTPUT
61+
os.chdir(kbuild_output)
62+
63+
for name, path in paths:
64+
print(f'Merging {name} ...')
65+
rc = run([f'{src_dir}/scripts/kconfig/merge_config.sh', '-m', '.config', path])
66+
if rc.returncode != 0:
67+
print(f'Error: failed merging {name}')
68+
return False
69+
70+
return True
71+
72+
73+
sys.exit(0 if main(sys.argv[1:]) else 1)

0 commit comments

Comments
 (0)