OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Tool to determine inputs and outputs of a grit file. | 6 '''Tool to determine inputs and outputs of a grit file. |
7 ''' | 7 ''' |
8 | 8 |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 def GritSourceFiles(): | 55 def GritSourceFiles(): |
56 files = [] | 56 files = [] |
57 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd()) | 57 grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd()) |
58 for root, dirs, filenames in os.walk(grit_root_dir): | 58 for root, dirs, filenames in os.walk(grit_root_dir): |
59 grit_src = [os.path.join(root, f) for f in filenames | 59 grit_src = [os.path.join(root, f) for f in filenames |
60 if f.endswith('.py')] | 60 if f.endswith('.py')] |
61 files.extend(grit_src) | 61 files.extend(grit_src) |
62 return sorted(files) | 62 return sorted(files) |
63 | 63 |
64 | 64 |
65 def Inputs(filename, defines, ids_file): | 65 def Inputs(filename, defines, ids_file, target_platform): |
66 grd = grd_reader.Parse( | 66 grd = grd_reader.Parse( |
67 filename, debug=False, defines=defines, tags_to_ignore=set(['message']), | 67 filename, debug=False, defines=defines, tags_to_ignore=set(['message']), |
68 first_ids_file=ids_file) | 68 first_ids_file=ids_file, target_platform=target_platform) |
69 files = set() | 69 files = set() |
70 for lang, ctx in grd.GetConfigurations(): | 70 for lang, ctx in grd.GetConfigurations(): |
71 grd.SetOutputLanguage(lang or grd.GetSourceLanguage()) | 71 grd.SetOutputLanguage(lang or grd.GetSourceLanguage()) |
72 grd.SetOutputContext(ctx) | 72 grd.SetOutputContext(ctx) |
73 for node in grd.ActiveDescendants(): | 73 for node in grd.ActiveDescendants(): |
74 with node: | 74 with node: |
75 if (node.name == 'structure' or node.name == 'skeleton' or | 75 if (node.name == 'structure' or node.name == 'skeleton' or |
76 (node.name == 'file' and node.parent and | 76 (node.name == 'file' and node.parent and |
77 node.parent.name == 'translations')): | 77 node.parent.name == 'translations')): |
78 files.add(grd.ToRealPath(node.GetInputPath())) | 78 files.add(grd.ToRealPath(node.GetInputPath())) |
(...skipping 28 matching lines...) Expand all Loading... |
107 parser = optparse.OptionParser() | 107 parser = optparse.OptionParser() |
108 parser.add_option("--inputs", action="store_true", dest="inputs") | 108 parser.add_option("--inputs", action="store_true", dest="inputs") |
109 parser.add_option("--outputs", action="store_true", dest="outputs") | 109 parser.add_option("--outputs", action="store_true", dest="outputs") |
110 parser.add_option("-D", action="append", dest="defines", default=[]) | 110 parser.add_option("-D", action="append", dest="defines", default=[]) |
111 # grit build also supports '-E KEY=VALUE', support that to share command | 111 # grit build also supports '-E KEY=VALUE', support that to share command |
112 # line flags. | 112 # line flags. |
113 parser.add_option("-E", action="append", dest="build_env", default=[]) | 113 parser.add_option("-E", action="append", dest="build_env", default=[]) |
114 parser.add_option("-w", action="append", dest="whitelist_files", default=[]) | 114 parser.add_option("-w", action="append", dest="whitelist_files", default=[]) |
115 parser.add_option("-f", dest="ids_file", | 115 parser.add_option("-f", dest="ids_file", |
116 default="GRIT_DIR/../gritsettings/resource_ids") | 116 default="GRIT_DIR/../gritsettings/resource_ids") |
| 117 parser.add_option("-t", dest="target_platform", default=None) |
117 | 118 |
118 options, args = parser.parse_args(argv) | 119 options, args = parser.parse_args(argv) |
119 | 120 |
120 defines = {} | 121 defines = {} |
121 for define in options.defines: | 122 for define in options.defines: |
122 name, val = util.ParseDefine(define) | 123 name, val = util.ParseDefine(define) |
123 defines[name] = val | 124 defines[name] = val |
124 | 125 |
125 for env_pair in options.build_env: | 126 for env_pair in options.build_env: |
126 (env_name, env_value) = env_pair.split('=', 1) | 127 (env_name, env_value) = env_pair.split('=', 1) |
127 os.environ[env_name] = env_value | 128 os.environ[env_name] = env_value |
128 | 129 |
129 if options.inputs: | 130 if options.inputs: |
130 if len(args) > 1: | 131 if len(args) > 1: |
131 raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.") | 132 raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.") |
132 | 133 |
133 inputs = [] | 134 inputs = [] |
134 if len(args) == 1: | 135 if len(args) == 1: |
135 filename = args[0] | 136 filename = args[0] |
136 inputs = Inputs(filename, defines, options.ids_file) | 137 inputs = Inputs(filename, defines, options.ids_file, |
| 138 options.target_platform) |
137 | 139 |
138 # Add in the grit source files. If one of these change, we want to re-run | 140 # Add in the grit source files. If one of these change, we want to re-run |
139 # grit. | 141 # grit. |
140 inputs.extend(GritSourceFiles()) | 142 inputs.extend(GritSourceFiles()) |
141 inputs = [f.replace('\\', '/') for f in inputs] | 143 inputs = [f.replace('\\', '/') for f in inputs] |
142 | 144 |
143 if len(args) == 1: | 145 if len(args) == 1: |
144 # Include grd file as second input (works around gyp expecting it). | 146 # Include grd file as second input (works around gyp expecting it). |
145 inputs.insert(1, args[0]) | 147 inputs.insert(1, args[0]) |
146 if options.whitelist_files: | 148 if options.whitelist_files: |
(...skipping 22 matching lines...) Expand all Loading... |
169 except WrongNumberOfArguments, e: | 171 except WrongNumberOfArguments, e: |
170 PrintUsage() | 172 PrintUsage() |
171 print e | 173 print e |
172 return 1 | 174 return 1 |
173 print result | 175 print result |
174 return 0 | 176 return 0 |
175 | 177 |
176 | 178 |
177 if __name__ == '__main__': | 179 if __name__ == '__main__': |
178 sys.exit(main(sys.argv)) | 180 sys.exit(main(sys.argv)) |
OLD | NEW |