-
Notifications
You must be signed in to change notification settings - Fork 5
/
configure.py
56 lines (48 loc) · 2.82 KB
/
configure.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
51
52
53
54
55
56
import argparse
import os
from typing import List, Tuple
GCC_INCLUDE_PATH_PLACEHOLDER = "/usr/lib/gcc/x86_64-linux-gnu/7/include"
LINUX_SRC_PATH_PLACEHOLDER = "/home/rhydon/workspace/buildroot-2020.02.4/output/build/linux-4.19.91"
ROOT_USER_PASSWORD_PLACEHOLDER = "123456"
HOME_DIRECTORY_PLACEHOLDER="/home/rhydon"
BUILDROOT_IMAGES_PATH_PLACEHOLDER="$HOME_DIRECTORY/workspace/buildroot-2020.02.4/output/images"
KERNEL_MODULE_NAME_PLACEHOLDER="kernel_development"
SNAPSHOT_NAME_PLACEHOLDER="first_snapshot"
C_CPP_PROPERTIES_PATH = ".vscode/c_cpp_properties.json"
DEBUG_SCRIPT_PATH = "debug.sh"
MAKEFILE_PATH = "Makefile"
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--linux-src", type=str, required=True, help="Path to buildroot's downloaded kernel source code. /path/to/buildroot/output/build/linux-<linux={version}>")
parser.add_argument("--gcc-include-path", type=str, help="Path to gcc library header")
parser.add_argument("--guest-root-password", type=str, required=True, help="Password to the qemu vm's root user")
parser.add_argument("--snapshot", type=str, required=True, help="Qemu snapshot name to restore to")
parser.add_argument("--module-name", type=str, default="kernel_development", help="The developed module's name")
return parser.parse_args()
def inplace_change(filename, replace_pairs: List[Tuple]):
strings_to_replace = [replace_pair[0] for replace_pair in replace_pairs]
with open(filename) as f:
s = f.read()
for string_to_replace in strings_to_replace:
if string_to_replace not in s:
return
with open(filename, 'w') as f:
for replace_pair in replace_pairs:
s = s.replace(replace_pair[0], replace_pair[1])
f.write(s)
def main():
args = parse_args()
home_directory = os.path.expanduser('~')
images_path = os.path.join(os.path.dirname(os.path.dirname(args.linux_src)), "images")
inplace_change(C_CPP_PROPERTIES_PATH, [(LINUX_SRC_PATH_PLACEHOLDER, args.linux_src), (GCC_INCLUDE_PATH_PLACEHOLDER, args.gcc_include_path)])
inplace_change(DEBUG_SCRIPT_PATH, [(LINUX_SRC_PATH_PLACEHOLDER, args.linux_src),
(HOME_DIRECTORY_PLACEHOLDER, home_directory),
(BUILDROOT_IMAGES_PATH_PLACEHOLDER, images_path),
(ROOT_USER_PASSWORD_PLACEHOLDER, args.guest_root_password),
(KERNEL_MODULE_NAME_PLACEHOLDER, args.module_name),
(SNAPSHOT_NAME_PLACEHOLDER, args.snapshot),
])
inplace_change(MAKEFILE_PATH, [(KERNEL_MODULE_NAME_PLACEHOLDER, args.module_name),
(LINUX_SRC_PATH_PLACEHOLDER, args.linux_src)])
if __name__ == "__main__":
main()