Flutter Engine
The Flutter Engine
Functions | Variables
create_snapshot_file Namespace Reference

Functions

def BuildOptions ()
 
def ProcessOptions (options)
 
def WriteBytesAsText (out, input_file)
 
def GenerateFileFromTemplate (output_file, input_cc_file, vm_isolate_input_file, isolate_input_file)
 
def Main ()
 

Variables

 HOST_OS = utils.GuessOS()
 
 HOST_CPUS = utils.GuessCpus()
 

Function Documentation

◆ BuildOptions()

def create_snapshot_file.BuildOptions ( )

Definition at line 21 of file create_snapshot_file.py.

21def BuildOptions():
22 result = optparse.OptionParser()
23 result.add_option(
24 "--vm_input_bin",
25 action="store",
26 type="string",
27 help="input file name of the vm isolate snapshot in binary form")
28 result.add_option(
29 "--input_bin",
30 action="store",
31 type="string",
32 help="input file name of the isolate snapshot in binary form")
33 result.add_option(
34 "--input_cc",
35 action="store",
36 type="string",
37 help="input file name which contains the C buffer template")
38 result.add_option(
39 "--output",
40 action="store",
41 type="string",
42 help="output file name into which snapshot in C buffer form is generated"
43 )
44 result.add_option(
45 "-v",
46 "--verbose",
47 help='Verbose output.',
48 default=False,
49 action="store_true")
50 return result
51
52

◆ GenerateFileFromTemplate()

def create_snapshot_file.GenerateFileFromTemplate (   output_file,
  input_cc_file,
  vm_isolate_input_file,
  isolate_input_file 
)
Generates C++ file based on a input_cc_file template and two binary files

Template is expected to have two %s placeholders which would be filled
with binary contents of the given files each formatted as a comma separated
list of integers.

Definition at line 89 of file create_snapshot_file.py.

90 isolate_input_file):
91 """Generates C++ file based on a input_cc_file template and two binary files
92
93 Template is expected to have two %s placeholders which would be filled
94 with binary contents of the given files each formatted as a comma separated
95 list of integers.
96 """
97 snapshot_cc_text = open(input_cc_file).read()
98 chunks = snapshot_cc_text.split("%s")
99 if len(chunks) != 3:
100 raise Exception("Template %s should contain exactly two %%s occurrences"
101 % input_cc_file)
102
103 with open(output_file, 'w') as out:
104 out.write(chunks[0])
105 WriteBytesAsText(out, vm_isolate_input_file)
106 out.write(chunks[1])
107 WriteBytesAsText(out, isolate_input_file)
108 out.write(chunks[2])
109
110
static bool read(SkStream *stream, void *buffer, size_t amount)
def WriteBytesAsText(out, input_file)

◆ Main()

def create_snapshot_file.Main ( )

Definition at line 111 of file create_snapshot_file.py.

111def Main():
112 # Parse options.
113 parser = BuildOptions()
114 (options, args) = parser.parse_args()
115 if not ProcessOptions(options):
116 parser.print_help()
117 return 1
118
119 # If there are additional arguments, report error and exit.
120 if args:
121 parser.print_help()
122 return 1
123
124 GenerateFileFromTemplate(options.output, options.input_cc,
125 options.vm_input_bin, options.input_bin)
126
127 return 0
128
129
def GenerateFileFromTemplate(output_file, input_cc_file, vm_isolate_input_file, isolate_input_file)

◆ ProcessOptions()

def create_snapshot_file.ProcessOptions (   options)

Definition at line 53 of file create_snapshot_file.py.

53def ProcessOptions(options):
54 if not options.vm_input_bin:
55 sys.stderr.write('--vm_input_bin not specified\n')
56 return False
57 if not options.input_bin:
58 sys.stderr.write('--input_bin not specified\n')
59 return False
60 if not options.input_cc:
61 sys.stderr.write('--input_cc not specified\n')
62 return False
63 if not options.output:
64 sys.stderr.write('--output not specified\n')
65 return False
66 return True
67
68

◆ WriteBytesAsText()

def create_snapshot_file.WriteBytesAsText (   out,
  input_file 
)
Writes byte contents of the input_file into out file as text.

Output is formatted as a list of comma separated integer values - one value
for each byte.

Definition at line 69 of file create_snapshot_file.py.

69def WriteBytesAsText(out, input_file):
70 """Writes byte contents of the input_file into out file as text.
71
72 Output is formatted as a list of comma separated integer values - one value
73 for each byte.
74 """
75 with open(input_file, 'rb') as input:
76 lineCounter = 0
77 line = ' '
78 for byte in input.read():
79 line += ' %d,' % ord(byte)
80 lineCounter += 1
81 if lineCounter == 10:
82 out.write(line + '\n')
83 line = ' '
84 lineCounter = 0
85 if lineCounter != 0:
86 out.write(line + '\n')
87
88

Variable Documentation

◆ HOST_CPUS

create_snapshot_file.HOST_CPUS = utils.GuessCpus()

Definition at line 18 of file create_snapshot_file.py.

◆ HOST_OS

create_snapshot_file.HOST_OS = utils.GuessOS()

Definition at line 17 of file create_snapshot_file.py.