meta: add build system
This commit is contained in:
125
util/sysroot-tool.py
Normal file
125
util/sysroot-tool.py
Normal 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)
|
||||
Reference in New Issue
Block a user