Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: runtime/tools/create_service_isolate_bindata.py

Issue 2925203002: Load service isolate from the kernel binary. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« runtime/bin/main.cc ('K') | « runtime/bin/service_isolate_bindata.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file.
5 #
6 # This python script creates a literal array of uint8_t data which represents
7 # binary data of the kernel to be loaded in to the service isolate of the
8 # dart VM.
9
10 import optparse
11 import os
12 import subprocess
13 import sys
14
15
16 VMSERVICE_IO_URI = "dart:vmservice_io"
17
18
19 def get_options():
20 parser = optparse.OptionParser()
21 parser.add_option("--build_dir", "-b",
22 action="store", type="string",
23 help="Path to the build dir.")
24 parser.add_option("--output", "-o",
25 action="store", type="string",
26 help="output file name")
27 parser.add_option("--empty", "-e",
28 action="store_true", default=False,
29 help="Generate empty service isolate binary data.")
30 options, _ = parser.parse_args()
31 if not options.output:
32 sys.exit("--output not specified")
33 if not options.build_dir:
34 sys.exit("--build_dir not specified")
35 return options
36
37
38 class ServiceDillGenerator(object):
39
40 def __init__(self, options):
41 self._empty_dill = options.empty
42 self._cc_file = options.output
43 self._service_dill = os.path.join(os.path.dirname(options.output),
44 'service.dill')
45 self._dart_bootstrap = os.path.join(options.build_dir, "dart_bootstrap")
46 self._compiler = os.path.join(
47 options.build_dir, os.pardir, os.pardir,
48 "pkg", "front_end", "tool", "_fasta", "compile.dart")
49
50 def gen_service_isolate_bin_data(self):
51 with open(self._cc_file, 'w') as cc:
52 cc.write("#include \"bin/service_isolate_bindata.h\"\n")
53 cc.write("const uint8_t service_isolate_kernel_bindata_[] = {\n")
54 if self._empty_dill:
55 size = 0
56 else:
57 self._generate_service_dill()
58 size = self._write_service_dill_to_cc_file(cc)
59 cc.write("};\n")
60 cc.write(
61 "const intptr_t service_isolate_kernel_bindata_size_ = %d;\n" % size)
62
63 def _generate_service_dill(self):
64 cmd = [
65 self._dart_bootstrap, self._compiler,
66 "--compile-sdk", "patched_sdk/",
67 "--packages=../../.packages",
68 VMSERVICE_IO_URI,
69 "-o", self._service_dill,
70 ]
71 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
72 out, err = p.communicate()
73 if p.returncode != 0:
74 sys.exit(err + '\n' + out)
75
76 def _write_service_dill_to_cc_file(self, cc_file):
77 bytecount = 0
78 with open(self._service_dill, 'rb') as kernel:
79 while True:
80 byte = kernel.read(1)
81 if byte == '':
82 # Read until EOF.
83 break
84 bytecount += 1
85 cc_file.write(hex(ord(byte)) + ', ')
86 if bytecount % 8 == 0:
87 cc_file.write('\n')
88 return bytecount
89
90
91 def main():
92 options = get_options()
93 generator = ServiceDillGenerator(get_options())
94 generator.gen_service_isolate_bin_data()
95
96
97 if __name__ == '__main__':
98 main()
OLDNEW
« runtime/bin/main.cc ('K') | « runtime/bin/service_isolate_bindata.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698