Commit 25c6d5b9 authored by Kunshan Wang's avatar Kunshan Wang

Merge branch 'mar-as-func' into 'master'

mar.py as a importable function

Put the functionality of mar.py as a importable function that can be used in RPython compiling tool chain.

See merge request !1
parents 2e5c2f30 e4b223c6
...@@ -5,66 +5,70 @@ import zipfile ...@@ -5,66 +5,70 @@ import zipfile
import tempfile import tempfile
import shutil import shutil
parser = argparse.ArgumentParser(
description='''Set additional boot-image metadata.''',
epilog='''Example:
./tools/mar.py -n @foo -l libm.so:/path/to/mylib.so my-boot-img.muref
'''
)
entry_point_group = parser.add_mutually_exclusive_group()
entry_point_group.add_argument('-i', '--entry-point-id',
metavar="MuID",
type=int,
help='set the entry point by ID'
)
entry_point_group.add_argument('-n', '--entry-point-name',
metavar="MuName",
help='set the entry point by name'
)
parser.add_argument('-l', '--extra-libraries',
metavar="colon-separated-libs",
help='''extra libraries to load at boot-image loading time. It is a
colon-separated list of libraries.''')
parser.add_argument('bootimg', help='path to the boot image') def mu_meta_set(bootimg, entry_point_id=None, entry_point_name=None, extra_libraries=None):
with tempfile.NamedTemporaryFile(delete=False) as tf:
tmpfilename = tf.name
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo:
with zipfile.ZipFile(bootimg, "a") as zi:
il = zi.infolist()
entrypoint = None
extralibs = None
for info in il:
name = info.filename
if name == 'entrypoint':
entrypoint = zi.read(info)
elif name == 'extralibs':
extralibs = zi.read(info)
else:
oldcontent = zi.read(info)
zo.writestr(name, oldcontent)
if entry_point_id is not None:
entrypoint = "id {}".format(entry_point_id).encode("utf8")
if entry_point_name is not None:
entrypoint = "name {}".format(entry_point_name).encode("utf8")
if extra_libraries is not None:
extralibs = extra_libraries.encode("utf8")
if entrypoint is not None:
zo.writestr("entrypoint", entrypoint)
if extralibs is not None:
zo.writestr("extralibs", extralibs)
shutil.move(tmpfilename, bootimg)
args = parser.parse_args()
if __name__ == "__main__":
with tempfile.NamedTemporaryFile(delete=False) as tf: parser = argparse.ArgumentParser(
tmpfilename = tf.name description='''Set additional boot-image metadata.''',
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo: epilog='''Example:
with zipfile.ZipFile(args.bootimg, "a") as zi: ./tools/mar.py -n @foo -l libm.so:/path/to/mylib.so my-boot-img.muref
il = zi.infolist() '''
)
entrypoint = None entry_point_group = parser.add_mutually_exclusive_group()
extralibs = None
for info in il: entry_point_group.add_argument('-i', '--entry-point-id',
name = info.filename metavar="MuID",
if name == 'entrypoint': type=int,
entrypoint = zi.read(info) help='set the entry point by ID'
elif name == 'extralibs': )
extralibs = zi.read(info)
else:
oldcontent = zi.read(info)
zo.writestr(name, oldcontent)
if args.entry_point_id is not None: entry_point_group.add_argument('-n', '--entry-point-name',
entrypoint = "id {}".format(args.entry_point_id).encode("utf8") metavar="MuName",
if args.entry_point_name is not None: help='set the entry point by name'
entrypoint = "name {}".format(args.entry_point_name).encode("utf8") )
if args.extra_libraries is not None:
extralibs = args.extra_libraries.encode("utf8")
if entrypoint is not None: parser.add_argument('-l', '--extra-libraries',
zo.writestr("entrypoint", entrypoint) metavar="colon-separated-libs",
if extralibs is not None: help='''extra libraries to load at boot-image loading time. It is a
zo.writestr("extralibs", extralibs) colon-separated list of libraries.''')
shutil.move(tmpfilename, args.bootimg) parser.add_argument('bootimg', help='path to the boot image')
args = parser.parse_args()
mu_meta_set(args.bootimg, args.entry_point_id, args.entry_point_name, args.extra_libraries)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment