OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 17 matching lines...) Expand all Loading... |
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 """Creates a grd file for packaging the inspector files.""" | 31 """Creates a grd file for packaging the inspector files.""" |
32 | 32 |
33 from __future__ import with_statement | 33 from __future__ import with_statement |
34 from os import path | 34 from os import path |
35 | 35 |
36 import errno | 36 import errno |
37 import os | 37 import os |
| 38 import shlex |
38 import shutil | 39 import shutil |
39 import sys | 40 import sys |
40 from xml.dom import minidom | 41 from xml.dom import minidom |
41 | 42 |
42 kDevToolsResourcePrefix = 'IDR_DEVTOOLS_' | 43 kDevToolsResourcePrefix = 'IDR_DEVTOOLS_' |
43 kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?> | 44 kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?> |
44 <grit latest_public_release="0" current_release="1"> | 45 <grit latest_public_release="0" current_release="1"> |
45 <outputs> | 46 <outputs> |
46 <output filename="grit/devtools_resources.h" type="rc_header"> | 47 <output filename="grit/devtools_resources.h" type="rc_header"> |
47 <emit emit_type='prepend'></emit> | 48 <emit emit_type='prepend'></emit> |
(...skipping 12 matching lines...) Expand all Loading... |
60 | 61 |
61 class ParsedArgs: | 62 class ParsedArgs: |
62 def __init__(self, source_files, relative_path_dirs, image_dirs, output_file
name): | 63 def __init__(self, source_files, relative_path_dirs, image_dirs, output_file
name): |
63 self.source_files = source_files | 64 self.source_files = source_files |
64 self.relative_path_dirs = relative_path_dirs | 65 self.relative_path_dirs = relative_path_dirs |
65 self.image_dirs = image_dirs | 66 self.image_dirs = image_dirs |
66 self.output_filename = output_filename | 67 self.output_filename = output_filename |
67 | 68 |
68 | 69 |
69 def parse_args(argv): | 70 def parse_args(argv): |
70 static_files_list_position = argv.index('--static_files_list') | 71 # The arguments are of the format: |
| 72 # [ <source_files> ]* |
| 73 # [ (--static_files_list <file>) | (--static_files_args <file>) ] |
| 74 # --relative_path_dirs [ <directory> ]* |
| 75 # --images [ <image_dirs> ]* |
| 76 # --output <output_file> |
| 77 # |
| 78 # --static_files_list means the file contains newline-separated filenames |
| 79 # from GYP, and --static_files_args means the file looks like a shell |
| 80 # string from GN. |
71 relative_path_dirs_position = argv.index('--relative_path_dirs') | 81 relative_path_dirs_position = argv.index('--relative_path_dirs') |
72 images_position = argv.index('--images') | 82 images_position = argv.index('--images') |
73 output_position = argv.index('--output') | 83 output_position = argv.index('--output') |
74 static_files_list_path = argv[static_files_list_position + 1] | 84 |
75 source_files = argv[:static_files_list_position] | 85 if '--static_files_list' in argv: |
76 with open(static_files_list_path, 'r') as static_list_file: | 86 # This branch can be removed when GYP support is no longer necessary. |
77 source_files.extend([line.rstrip('\n') for line in static_list_file.read
lines()]) | 87 static_files_list_position = argv.index('--static_files_list') |
| 88 static_files_list_path = argv[static_files_list_position + 1] |
| 89 source_files = argv[:static_files_list_position] |
| 90 with open(static_files_list_path, 'r') as static_list_file: |
| 91 source_files.extend([line.rstrip('\n') for line in static_list_file.
readlines()]) |
| 92 elif '--static_files_args' in argv: |
| 93 static_files_args_position = argv.index('--static_files_args') |
| 94 static_files_args_path = argv[static_files_args_position + 1] |
| 95 source_files = argv[:static_files_args_position] |
| 96 with open(static_files_args_path, 'r') as static_args_file: |
| 97 source_files.extend(shlex.split(static_args_file)) |
| 98 else: |
| 99 source_files = argv[:relative_path_dirs_position] |
| 100 |
78 relative_path_dirs = argv[relative_path_dirs_position + 1:images_position] | 101 relative_path_dirs = argv[relative_path_dirs_position + 1:images_position] |
79 image_dirs = argv[images_position + 1:output_position] | 102 image_dirs = argv[images_position + 1:output_position] |
80 return ParsedArgs(source_files, relative_path_dirs, image_dirs, argv[output_
position + 1]) | 103 return ParsedArgs(source_files, relative_path_dirs, image_dirs, argv[output_
position + 1]) |
81 | 104 |
82 | 105 |
83 def make_name_from_filename(filename): | 106 def make_name_from_filename(filename): |
84 return (filename.replace('/', '_') | 107 return (filename.replace('/', '_') |
85 .replace('\\', '_') | 108 .replace('\\', '_') |
86 .replace('-', '_') | 109 .replace('-', '_') |
87 .replace('.', '_')).upper() | 110 .replace('.', '_')).upper() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 shutil.copy(path.join(dirname, filename), | 161 shutil.copy(path.join(dirname, filename), |
139 path.join(output_directory, 'Images')) | 162 path.join(output_directory, 'Images')) |
140 add_file_to_grd(doc, path.join('Images', filename)) | 163 add_file_to_grd(doc, path.join('Images', filename)) |
141 | 164 |
142 with open(parsed_args.output_filename, 'w') as output_file: | 165 with open(parsed_args.output_filename, 'w') as output_file: |
143 output_file.write(doc.toxml(encoding='UTF-8')) | 166 output_file.write(doc.toxml(encoding='UTF-8')) |
144 | 167 |
145 | 168 |
146 if __name__ == '__main__': | 169 if __name__ == '__main__': |
147 sys.exit(main(sys.argv)) | 170 sys.exit(main(sys.argv)) |
OLD | NEW |