Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
create_string_literal.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
4# for details. All rights reserved. Use of this source code is governed by a
5# BSD-style license that can be found in the LICENSE file.
6#
7# This python script creates a string literal in a C++ source file from a C++
8# source template and text file.
9
10import os
11import sys
12from os.path import join
13import time
14from optparse import OptionParser
15
16
17def makeString(input_files):
18 result = ' '
19 for string_file in input_files:
20 if string_file.endswith('dart'):
21 fileHandle = open(string_file, 'rb')
22 lineCounter = 0
23 result += ' // ' + string_file + '\n '
24 for byte in fileHandle.read():
25 result += ' %d,' % ord(byte)
26 lineCounter += 1
27 if lineCounter == 10:
28 result += '\n '
29 lineCounter = 0
30 if lineCounter != 0:
31 result += '\n '
32 result += ' // Terminating null character.\n 0'
33 return result
34
35
36def makeFile(output_file, input_cc_file, include, var_name, input_files):
37 bootstrap_cc_text = open(input_cc_file).read()
38 bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include)
39 bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name)
40 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}",
41 makeString(input_files))
42 open(output_file, 'w').write(bootstrap_cc_text)
43 return True
44
45
46def main(args):
47 try:
48 # Parse input.
49 parser = OptionParser()
50 parser.add_option(
51 "--output", action="store", type="string", help="output file name")
52 parser.add_option(
53 "--input_cc",
54 action="store",
55 type="string",
56 help="input template file")
57 parser.add_option(
58 "--include", action="store", type="string", help="variable name")
59 parser.add_option(
60 "--var_name", action="store", type="string", help="variable name")
61
62 (options, args) = parser.parse_args()
63 if not options.output:
64 sys.stderr.write('--output not specified\n')
65 return -1
66 if not len(options.input_cc):
67 sys.stderr.write('--input_cc not specified\n')
68 return -1
69 if not len(options.include):
70 sys.stderr.write('--include not specified\n')
71 return -1
72 if not len(options.var_name):
73 sys.stderr.write('--var_name not specified\n')
74 return -1
75 if len(args) == 0:
76 sys.stderr.write('No input files specified\n')
77 return -1
78
79 files = []
80 for arg in args:
81 files.append(arg)
82
83 if not makeFile(options.output, options.input_cc, options.include,
84 options.var_name, files):
85 return -1
86
87 return 0
88 except Exception as inst:
89 sys.stderr.write('create_string_literal.py exception\n')
90 sys.stderr.write(str(inst))
91 sys.stderr.write('\n')
92 return -1
93
94
95if __name__ == '__main__':
96 sys.exit(main(sys.argv))
static bool read(SkStream *stream, void *buffer, size_t amount)
makeFile(output_file, input_cc_file, include, var_name, input_files)
Definition main.py:1
void write(SkWStream *wStream, const T &text)
Definition skqp.cpp:188