meta: add build system

This commit is contained in:
2026-02-05 09:54:46 +00:00
parent 62c5653d5b
commit 9c8fbc72ac
15 changed files with 694 additions and 0 deletions

124
util/bsp-tool.py Executable file
View File

@@ -0,0 +1,124 @@
#!/usr/bin/env python3
import sys
import os
import shutil
import tarfile
from lib.manifest import Manifest, Component
def reset():
if len(sys.argv) < 3:
print("USAGE: {} reset <manifest-path>".format(sys.argv[0]))
manifest_path = sys.argv[2]
manifest = Manifest(manifest_path)
manifest.reset()
manifest.save()
return 0
def add_headers():
if len(sys.argv) < 3:
print("USAGE: {} add-headers <manifest-path> <component-name> <source-directory> <dest-directory>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
component_name = sys.argv[3]
dest_path = sys.argv[4]
src_path = sys.argv[5]
manifest = Manifest(manifest_path)
manifest.load()
component = manifest.get_component(component_name)
component.add_headers(src_path, dest_path)
manifest.save()
return 0
def add_binary():
if len(sys.argv) < 3:
print("USAGE: {} add-binary <manifest-path> <component-name> <source-file> <dest-directory>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
component_name = sys.argv[3]
dest_path = sys.argv[4]
src_path = sys.argv[5]
manifest = Manifest(manifest_path)
manifest.load()
component = manifest.get_component(component_name)
component.add_binary(src_path, dest_path)
manifest.save()
return 0
def build_bsp():
if len(sys.argv) < 3:
print("USAGE: {} build-bsp <manifest-path> <dest-path>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
bsp_path = sys.argv[3]
if os.path.exists(bsp_path):
os.remove(bsp_path)
bsp_file = tarfile.open(name=bsp_path, mode='x')
manifest = Manifest(manifest_path)
manifest.load()
for n, c in manifest.get_all_components().items():
for h in c.get_headers():
header_src = h['src']
header_dest = h['dest']
while header_dest.startswith('/'):
header_dest = header_dest[1:]
for f in os.listdir(header_src):
print('ADD {} -> {}'.format(
os.path.join(header_src, f),
os.path.join(header_dest, f)))
bsp_file.add(
os.path.join(header_src, f),
arcname=os.path.join(header_dest, f))
for b in c.get_binaries():
binary_src = b['src']
binary_dest = b['dest']
while binary_dest.startswith('/'):
binary_dest = binary_dest[1:]
bsp_file.add(binary_src, arcname=binary_dest)
bsp_file.close()
return 0
if len(sys.argv) < 2:
print("USAGE: {} <command> [args...]".format(sys.argv[0]))
exit(-1)
commands = {
'reset': reset,
'add-headers': add_headers,
'add-binary': add_binary,
'build-bsp': build_bsp,
}
cmd_name = sys.argv[1]
if cmd_name not in commands:
print("FATAL: unrecognised command '{}'".format(cmd_name))
exit(-1)
try:
exit(commands[cmd_name]())
except RuntimeError as e:
print('FATAL: {}'.format(e))
exit(-1)

125
util/sysroot-tool.py Normal file
View File

@@ -0,0 +1,125 @@
#!/usr/bin/env python3
import sys
import os
import shutil
from lib.manifest import Manifest, Component
def reset():
if len(sys.argv) < 3:
print("USAGE: {} reset <manifest-path>".format(sys.argv[0]))
manifest_path = sys.argv[2]
manifest = Manifest(manifest_path)
manifest.reset()
manifest.save()
return 0
def add_headers():
if len(sys.argv) < 3:
print("USAGE: {} add-headers <manifest-path> <component-name> <source-directory> <dest-directory>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
component_name = sys.argv[3]
dest_path = sys.argv[4]
src_path = sys.argv[5]
manifest = Manifest(manifest_path)
manifest.load()
component = manifest.get_component(component_name)
component.add_headers(src_path, dest_path)
manifest.save()
return 0
def add_binary():
if len(sys.argv) < 3:
print("USAGE: {} add-binary <manifest-path> <component-name> <source-file> <dest-directory>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
component_name = sys.argv[3]
dest_path = sys.argv[4]
src_path = sys.argv[5]
manifest = Manifest(manifest_path)
manifest.load()
component = manifest.get_component(component_name)
component.add_binary(src_path, dest_path)
manifest.save()
return 0
def build_sysroot():
if len(sys.argv) < 3:
print("USAGE: {} build-sysroot <manifest-path> <dest-directory>".format(sys.argv[0]))
return -1
manifest_path = sys.argv[2]
sysroot_path = sys.argv[3]
if os.path.isdir(sysroot_path):
shutil.rmtree(sysroot_path)
manifest = Manifest(manifest_path)
manifest.load()
for n, c in manifest.get_all_components().items():
for h in c.get_headers():
header_src = h['src']
header_dest = h['dest']
while header_dest.startswith('/'):
header_dest = header_dest[1:]
header_dest = os.path.join(sysroot_path, header_dest)
if not os.path.isdir(header_dest):
os.makedirs(header_dest)
for f in os.listdir(header_src):
shutil.copy(
os.path.join(header_src, f),
os.path.join(header_dest, f))
for b in c.get_binaries():
binary_src = b['src']
binary_dest = b['dest']
while binary_dest.startswith('/'):
binary_dest = binary_dest[1:]
binary_dest = os.path.join(sysroot_path, binary_dest)
if not os.path.isdir(binary_dest):
os.makedirs(binary_dest)
shutil.copy(binary_src, binary_dest)
return 0
if len(sys.argv) < 2:
print("USAGE: {} <command> [args...]".format(sys.argv[0]))
exit(-1)
commands = {
'reset': reset,
'add-headers': add_headers,
'add-binary': add_binary,
'build-sysroot': build_sysroot,
}
cmd_name = sys.argv[1]
if cmd_name not in commands:
print("FATAL: unrecognised command '{}'".format(cmd_name))
exit(-1)
try:
exit(commands[cmd_name]())
except RuntimeError as e:
print('FATAL: {}'.format(e))
exit(-1)