13from os.path
import join
14from optparse
import OptionParser
20 result =
'static const char ' + var_name +
'[] = {\n '
21 fileHandle = open(input_file,
'rb')
23 for byte
in fileHandle.read():
24 result +=
'\'\\x%02x' % ord(byte) +
'\', '
36 for string_file
in in_files:
37 if string_file.endswith(
'.dart'):
40 "source_array_" + str(file_count))
45def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
47 bootstrap_cc_text = open(input_cc_file).
read()
48 bootstrap_cc_text = bootstrap_cc_text.replace(
"{{SOURCE_ARRAYS}}",
50 bootstrap_cc_text = bootstrap_cc_text.replace(
"{{INCLUDE}}", include)
51 bootstrap_cc_text = bootstrap_cc_text.replace(
"{{VAR_NAME}}", var_name)
52 main_file_found =
False
54 for string_file
in in_files:
55 if string_file.endswith(
'.dart'):
57 if (
not main_file_found):
58 inpt = open(string_file,
'r')
61 if line.startswith(
'library '):
62 main_file_found =
True
63 bootstrap_cc_text = bootstrap_cc_text.replace(
64 "{{LIBRARY_SOURCE_MAP}}",
' "' + lib_name +
'",\n' +
65 ' source_array_' + str(file_count) +
',\n')
69 part_index.append(
' "' + lib_name +
"/" + os.path.basename(
70 string_file).replace(
'\\',
'\\\\') +
'",\n')
71 part_index.append(
' source_array_' + str(file_count) +
',\n\n')
72 bootstrap_cc_text = bootstrap_cc_text.replace(
"{{LIBRARY_SOURCE_MAP}}",
'')
73 bootstrap_cc_text = bootstrap_cc_text.replace(
"{{PART_SOURCE_MAP}}",
75 open(output_file,
'w').
write(bootstrap_cc_text)
82 parser = OptionParser()
84 "--output", action=
"store", type=
"string", help=
"output file name")
89 help=
"input template file")
91 "--include", action=
"store", type=
"string", help=
"variable name")
98 "--var_name", action=
"store", type=
"string", help=
"variable name")
100 (options, args) = parser.parse_args()
101 if not options.output:
102 sys.stderr.write(
'--output not specified\n')
104 if not len(options.input_cc):
105 sys.stderr.write(
'--input_cc not specified\n')
107 if not len(options.include):
108 sys.stderr.write(
'--include not specified\n')
110 if not len(options.var_name):
111 sys.stderr.write(
'--var_name not specified\n')
113 if not len(options.library_name):
114 sys.stderr.write(
'--library_name not specified\n')
117 sys.stderr.write(
'No input files specified\n')
124 if not makeFile(options.output, options.input_cc, options.include,
125 options.var_name, options.library_name, files):
129 except Exception
as inst:
130 sys.stderr.write(
'gen_library_src_paths.py exception\n')
131 sys.stderr.write(str(inst))
132 sys.stderr.write(
'\n')
136if __name__ ==
'__main__':
137 sys.exit(
main(sys.argv))
static bool read(SkStream *stream, void *buffer, size_t amount)
def makeSourceArrays(in_files)
def makeString(input_file, var_name)
def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files)
static SkString join(const CommandLineFlags::StringArray &)
void write(SkWStream *wStream, const T &text)