2026-02-05 09:54:46 +00:00
|
|
|
#!/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():
|
2026-02-19 19:27:42 +00:00
|
|
|
if len(sys.argv) < 6:
|
|
|
|
|
print("USAGE: {} add-headers <manifest-path> <component-name> <dest-directory> <source-directory>".format(sys.argv[0]))
|
2026-02-05 09:54:46 +00:00
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
manifest_path = sys.argv[2]
|
|
|
|
|
component_name = sys.argv[3]
|
|
|
|
|
dest_path = sys.argv[4]
|
2026-02-19 19:27:42 +00:00
|
|
|
src_paths = sys.argv[5:]
|
2026-02-05 09:54:46 +00:00
|
|
|
|
|
|
|
|
manifest = Manifest(manifest_path)
|
|
|
|
|
manifest.load()
|
|
|
|
|
|
|
|
|
|
component = manifest.get_component(component_name)
|
2026-02-19 19:27:42 +00:00
|
|
|
|
|
|
|
|
for p in src_paths:
|
|
|
|
|
component.add_headers(p, dest_path)
|
2026-02-05 09:54:46 +00:00
|
|
|
|
|
|
|
|
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):
|
2026-02-19 19:27:42 +00:00
|
|
|
f_src = os.path.join(header_src, f)
|
|
|
|
|
f_dst = os.path.join(header_dest, f)
|
|
|
|
|
if os.path.isfile(f_src):
|
|
|
|
|
shutil.copy(
|
|
|
|
|
os.path.join(header_src, f),
|
|
|
|
|
os.path.join(header_dest, f))
|
|
|
|
|
else:
|
|
|
|
|
shutil.copytree(
|
|
|
|
|
os.path.join(header_src, f),
|
|
|
|
|
os.path.join(header_dest, f),
|
|
|
|
|
dirs_exist_ok=True)
|
|
|
|
|
|
2026-02-05 09:54:46 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2026-02-19 19:27:42 +00:00
|
|
|
if binary_src.endswith('.s.o'):
|
|
|
|
|
binary_dest = os.path.join(binary_dest, os.path.basename(binary_src)[:-4] + '.o')
|
|
|
|
|
|
2026-02-05 09:54:46 +00:00
|
|
|
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)
|