OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 import collections | 6 import collections |
7 import hashlib | 7 import hashlib |
8 import operator | 8 import operator |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 indices_array = _GenDataArray( | 149 indices_array = _GenDataArray( |
150 hashed_tuples, " %s, // %s", 'kResourceIndices', 'int', | 150 hashed_tuples, " %s, // %s", 'kResourceIndices', 'int', |
151 operator.attrgetter('index')) | 151 operator.attrgetter('index')) |
152 | 152 |
153 return ( | 153 return ( |
154 "// This file was generated by generate_resources_map.py. Do not edit.\n" | 154 "// This file was generated by generate_resources_map.py. Do not edit.\n" |
155 "\n\n" | 155 "\n\n" |
156 "#include " | 156 "#include " |
157 "\"chrome/browser/metrics/variations/generated_resources_map.h\"\n\n" | 157 "\"chrome/browser/metrics/variations/generated_resources_map.h\"\n\n" |
158 "namespace chrome_variations {\n\n" | 158 "namespace chrome_variations {\n\n" |
| 159 "const size_t kNumResources = %i;\n\n" |
159 "%s" | 160 "%s" |
160 "\n" | 161 "\n" |
161 "%s" | 162 "%s" |
162 "\n" | 163 "\n" |
163 "} // namespace chrome_variations\n") % (hashes_array, indices_array) | 164 "} // namespace chrome_variations\n") % ( |
| 165 len(hashed_tuples), hashes_array, indices_array) |
164 | 166 |
165 | 167 |
166 def main(resources_file, map_file): | 168 def main(resources_file, map_file): |
167 generated_resources_h = "" | 169 generated_resources_h = "" |
168 with open(resources_file, "r") as resources: | 170 with open(resources_file, "r") as resources: |
169 generated_resources_h = resources.read() | 171 generated_resources_h = resources.read() |
170 | 172 |
171 if len(generated_resources_h) == 0: | 173 if len(generated_resources_h) == 0: |
172 raise Error("No content loaded for %s." % (resources_file)) | 174 raise Error("No content loaded for %s." % (resources_file)) |
173 | 175 |
174 file_content = _GenerateFileContent(generated_resources_h) | 176 file_content = _GenerateFileContent(generated_resources_h) |
175 | 177 |
176 with open(map_file, "w") as generated_file: | 178 with open(map_file, "w") as generated_file: |
177 generated_file.write(file_content) | 179 generated_file.write(file_content) |
178 | 180 |
179 | 181 |
180 if __name__ == '__main__': | 182 if __name__ == '__main__': |
181 sys.exit(main(sys.argv[1], sys.argv[2])) | 183 sys.exit(main(sys.argv[1], sys.argv[2])) |
OLD | NEW |