| Index: runtime/tools/create_service_isolate_bindata.py
|
| diff --git a/runtime/tools/create_service_isolate_bindata.py b/runtime/tools/create_service_isolate_bindata.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..1f006e0d9f3880b6f97fcc6e3cfb99a05d1245d4
|
| --- /dev/null
|
| +++ b/runtime/tools/create_service_isolate_bindata.py
|
| @@ -0,0 +1,98 @@
|
| +#!/usr/bin/env python
|
| +# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
| +# for details. All rights reserved. Use of this source code is governed by a
|
| +# BSD-style license that can be found in the LICENSE file.
|
| +#
|
| +# This python script creates a literal array of uint8_t data which represents
|
| +# binary data of the kernel to be loaded in to the service isolate of the
|
| +# dart VM.
|
| +
|
| +import optparse
|
| +import os
|
| +import subprocess
|
| +import sys
|
| +
|
| +
|
| +VMSERVICE_IO_URI = "dart:vmservice_io"
|
| +
|
| +
|
| +def get_options():
|
| + parser = optparse.OptionParser()
|
| + parser.add_option("--build_dir", "-b",
|
| + action="store", type="string",
|
| + help="Path to the build dir.")
|
| + parser.add_option("--output", "-o",
|
| + action="store", type="string",
|
| + help="output file name")
|
| + parser.add_option("--empty", "-e",
|
| + action="store_true", default=False,
|
| + help="Generate empty service isolate binary data.")
|
| + options, _ = parser.parse_args()
|
| + if not options.output:
|
| + sys.exit("--output not specified")
|
| + if not options.build_dir:
|
| + sys.exit("--build_dir not specified")
|
| + return options
|
| +
|
| +
|
| +class ServiceDillGenerator(object):
|
| +
|
| + def __init__(self, options):
|
| + self._empty_dill = options.empty
|
| + self._cc_file = options.output
|
| + self._service_dill = os.path.join(os.path.dirname(options.output),
|
| + 'service.dill')
|
| + self._dart_bootstrap = os.path.join(options.build_dir, "dart_bootstrap")
|
| + self._compiler = os.path.join(
|
| + options.build_dir, os.pardir, os.pardir,
|
| + "pkg", "front_end", "tool", "_fasta", "compile.dart")
|
| +
|
| + def gen_service_isolate_bin_data(self):
|
| + with open(self._cc_file, 'w') as cc:
|
| + cc.write("#include \"bin/service_isolate_bindata.h\"\n")
|
| + cc.write("const uint8_t service_isolate_kernel_bindata_[] = {\n")
|
| + if self._empty_dill:
|
| + size = 0
|
| + else:
|
| + self._generate_service_dill()
|
| + size = self._write_service_dill_to_cc_file(cc)
|
| + cc.write("};\n")
|
| + cc.write(
|
| + "const intptr_t service_isolate_kernel_bindata_size_ = %d;\n" % size)
|
| +
|
| + def _generate_service_dill(self):
|
| + cmd = [
|
| + self._dart_bootstrap, self._compiler,
|
| + "--compile-sdk", "patched_sdk/",
|
| + "--packages=../../.packages",
|
| + VMSERVICE_IO_URI,
|
| + "-o", self._service_dill,
|
| + ]
|
| + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| + out, err = p.communicate()
|
| + if p.returncode != 0:
|
| + sys.exit(err + '\n' + out)
|
| +
|
| + def _write_service_dill_to_cc_file(self, cc_file):
|
| + bytecount = 0
|
| + with open(self._service_dill, 'rb') as kernel:
|
| + while True:
|
| + byte = kernel.read(1)
|
| + if byte == '':
|
| + # Read until EOF.
|
| + break
|
| + bytecount += 1
|
| + cc_file.write(hex(ord(byte)) + ', ')
|
| + if bytecount % 8 == 0:
|
| + cc_file.write('\n')
|
| + return bytecount
|
| +
|
| +
|
| +def main():
|
| + options = get_options()
|
| + generator = ServiceDillGenerator(get_options())
|
| + generator.gen_service_isolate_bin_data()
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + main()
|
|
|