-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgen_helper.py
More file actions
58 lines (45 loc) · 1.49 KB
/
gen_helper.py
File metadata and controls
58 lines (45 loc) · 1.49 KB
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
57
58
# Copyright (c) 2023-2024 Lawrence Hunter <lawrence.hunter@outlook.com>
import pyfiglet, subprocess
def generate_header():
return "// AUTOGENERATED DO NOT EDIT\n"
def generate_boot_logo():
# Fonts: http://www.figlet.org/examples.html
logo = pyfiglet.figlet_format("SentinelBoot", font="doom", width=80).split(
"\n"
)
text = "pub fn print_boot_logo() {\n"
text += "\tprintln!();\n"
text += "\tprintln!();\n"
for line in logo:
text += f'\tprintln!(r"{line}");\n'
text += "}"
return text
def generate_version():
sha = (
subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"])
.decode()
.strip()
)
dirty = ""
try:
subprocess.check_call(["git", "diff", "--quiet"])
except subprocess.CalledProcessError:
dirty = "dirty"
return f'pub const SHA: &str = "{sha} {dirty}";\n'
def generate_version():
sha = (
subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"])
.decode()
.strip()
)
return f'pub const SHA: &str = "{sha}";\n'
def add_public_key():
file_path = "../tftp/public_key.pem"
return f'pub const PUBLIC_KEY: &[u8] = include_bytes!("{file_path}");\n'
if __name__ == "__main__":
with open("./src/helper.rs", "w") as f:
f.write(generate_header() + "\n")
f.write("use crate::println;" + "\n")
f.write(generate_boot_logo() + "\n")
f.write(generate_version())
f.write(add_public_key())