-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci.py
More file actions
48 lines (35 loc) · 2.1 KB
/
ci.py
File metadata and controls
48 lines (35 loc) · 2.1 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
import subprocess, os, tempfile, shutil, sys
CURRENT_DIR = os.getcwd()
if __name__ == '__main__':
path = os.path.join(tempfile.gettempdir(), "katapult")
outdir = os.path.join(tempfile.gettempdir(), "katapult-out")
if os.path.exists(path):
shutil.rmtree(path)
if os.path.exists(outdir):
shutil.rmtree(outdir)
os.mkdir(outdir)
print("Cloning katapult...")
subprocess.run(["git", "clone", "--depth", "1", "https://github.com/Arksine/katapult", path], check=True)
os.chdir(path)
sys.path.insert(1, os.path.join(path, "scripts"))
import buildbinary
for file in os.listdir(os.path.join(CURRENT_DIR, "patches")):
print(f"Applying patch {file}...")
subprocess.run(["git", "apply", os.path.join(CURRENT_DIR, "patches", file)], check=True)
for config in os.listdir(os.path.join(CURRENT_DIR, "mcu")):
config_stripped = config.split(".")[0]
print(f"Building {config_stripped} (Elegoo bootloader -> Katapult)...")
shutil.copy(os.path.join(CURRENT_DIR, "mcu", config), os.path.join(path, ".config"))
subprocess.run(["make", "clean"], check=True)
subprocess.run(["make"], check=True)
shutil.copy(os.path.join(path, "out/deployer.bin"), os.path.join(outdir, f"{config_stripped}-katapult-deployer.bin"))
shutil.copy(os.path.join(path, "out/katapult.bin"), os.path.join(outdir, f"{config_stripped}-katapult-firmware.bin"))
official_bootloader_path = os.path.join(CURRENT_DIR, "official_bootloader", f"{config_stripped}.bin")
if os.path.exists(official_bootloader_path):
print(f"Building {config_stripped} (Katapult -> Elegoo bootloader)...")
with open(official_bootloader_path, "rb") as f:
official_bootloader = f.read()
with open(os.path.join(path, "out/katapult_payload.c"), "w") as fp:
fp.write(buildbinary.format_c_code(official_bootloader))
subprocess.run(["make"], check=True)
shutil.copy(os.path.join(path, "out/deployer.bin"), os.path.join(outdir, f"{config_stripped}-official-deployer.bin"))