2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """generates files to embed the gles2 conformance test data in executable."""
11 class GenerateEmbeddedFiles(object):
12 """generates files to embed the gles2 conform test data in executable"""
14 paths_to_ignore
= set([
22 extensions_to_include
= set([
29 def __init__(self
, scan_dir
, base_dir
):
30 self
.scan_dir
= scan_dir
31 self
.base_dir
= base_dir
33 if self
.base_dir
!= None:
34 self
.files_data_h
= open(os
.path
.join(base_dir
, "FilesDATA.h"), "wb")
35 self
.files_data_c
= open(os
.path
.join(base_dir
, "FilesDATA.c"), "wb")
36 self
.files_toc_c
= open(os
.path
.join(base_dir
, "FilesTOC.c"), "wb")
38 self
.files_data_h
.write("#ifndef FilesDATA_h\n\n")
39 self
.files_data_h
.write("#define FilesDATA_h\n\n");
41 self
.files_data_c
.write("#include \"FilesDATA.h\"\n\n")
43 self
.files_toc_c
.write("#include \"FilesTOC.h\"\n\n");
44 self
.files_toc_c
.write("struct GTFVectorFileEntry tempFiles;\n\n");
45 self
.files_toc_c
.write("struct FileEntry files[] = {\n");
47 self
.AddFiles(scan_dir
)
49 if self
.base_dir
!= None:
50 self
.files_toc_c
.write("\n};\n\n");
51 self
.files_toc_c
.write(
52 "int numFileEntrys = sizeof(files) / sizeof(struct FileEntry);\n");
54 self
.files_data_h
.write("\n\n#endif // FilesDATA_h\n");
56 self
.files_data_c
.close()
57 self
.files_data_h
.close()
58 self
.files_toc_c
.close()
60 def AddFiles(self
, scan_dir
):
61 """Scan a folder and embed the contents of files."""
62 files
= os
.listdir(scan_dir
)
65 full_path
= os
.path
.join(scan_dir
, file)
66 ext
= os
.path
.splitext(file)[1]
67 base_path
= full_path
[len(self
.scan_dir
) + 1:]
68 if os
.path
.isdir(full_path
):
69 if not file in GenerateEmbeddedFiles
.paths_to_ignore
:
70 sub_dirs
.append(full_path
)
71 elif ext
in GenerateEmbeddedFiles
.extensions_to_include
:
72 if self
.base_dir
== None:
73 print full_path
.replace("\\", "/")
76 name
= "_FILE_%s_%d" % (ext
.upper(), self
.count
)
77 name
= name
.replace(".", "_")
79 self
.files_data_h
.write("extern const char %s[];\n" % name
)
80 self
.files_data_c
.write("const char %s[] = \n" % name
)
82 data
= open(full_path
, "r")
83 lines
= data
.readlines();
87 line
= line
.replace("\n", "")
88 line
= line
.replace("\r", "")
89 line
= line
.replace("\\", "\\\\")
90 line
= line
.replace("\"", "\\\"")
92 self
.files_data_c
.write('"%s\\n"\n' % line
)
94 self
.files_data_c
.write(";\n")
95 self
.files_toc_c
.write("\t{ \"%s\", %s, 0 },\n" % (
96 base_path
.replace("\\", "/"), name
))
98 for sub_dir
in sub_dirs
:
99 self
.AddFiles(sub_dir
)
103 """This is the main function."""
115 GenerateEmbeddedFiles(scan_dir
, base_dir
)
119 if __name__
== '__main__':
120 sys
.exit(main(sys
.argv
[1:]))