| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 Utilities for the modular DevTools build. | 8 Utilities for the modular DevTools build. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 if path.exists(filename): | 26 if path.exists(filename): |
| 27 os.remove(filename) | 27 os.remove(filename) |
| 28 with open(filename, 'wt') as output: | 28 with open(filename, 'wt') as output: |
| 29 output.write(content) | 29 output.write(content) |
| 30 | 30 |
| 31 | 31 |
| 32 def bail_error(message): | 32 def bail_error(message): |
| 33 raise Exception(message) | 33 raise Exception(message) |
| 34 | 34 |
| 35 | 35 |
| 36 def load_and_parse_json(filename): |
| 37 try: |
| 38 return json.loads(read_file(filename)) |
| 39 except: |
| 40 print 'ERROR: Failed to parse %s' % filename |
| 41 raise |
| 42 |
| 43 |
| 36 def concatenate_scripts(file_names, module_dir, output_dir, output): | 44 def concatenate_scripts(file_names, module_dir, output_dir, output): |
| 37 for file_name in file_names: | 45 for file_name in file_names: |
| 38 output.write('/* %s */\n' % file_name) | 46 output.write('/* %s */\n' % file_name) |
| 39 file_path = path.join(module_dir, file_name) | 47 file_path = path.join(module_dir, file_name) |
| 40 if not path.isfile(file_path): | 48 if not path.isfile(file_path): |
| 41 file_path = path.join(output_dir, path.basename(module_dir), file_na
me) | 49 file_path = path.join(output_dir, path.basename(module_dir), file_na
me) |
| 42 output.write(read_file(file_path)) | 50 output.write(read_file(file_path)) |
| 43 output.write(';') | 51 output.write(';') |
| 44 | 52 |
| 45 | 53 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 144 |
| 137 def load_application(self, application_descriptor_name): | 145 def load_application(self, application_descriptor_name): |
| 138 return self.load_applications([application_descriptor_name]) | 146 return self.load_applications([application_descriptor_name]) |
| 139 | 147 |
| 140 def load_applications(self, application_descriptor_names): | 148 def load_applications(self, application_descriptor_names): |
| 141 merged_application_descriptor = {} | 149 merged_application_descriptor = {} |
| 142 all_module_descriptors = {} | 150 all_module_descriptors = {} |
| 143 for application_descriptor_name in application_descriptor_names: | 151 for application_descriptor_name in application_descriptor_names: |
| 144 module_descriptors = {} | 152 module_descriptors = {} |
| 145 application_descriptor_filename = path.join(self.application_dir, ap
plication_descriptor_name) | 153 application_descriptor_filename = path.join(self.application_dir, ap
plication_descriptor_name) |
| 146 application_descriptor_json = read_file(application_descriptor_filen
ame) | 154 application_descriptor = {desc['name']: desc for desc in load_and_pa
rse_json(application_descriptor_filename)} |
| 147 application_descriptor = {desc['name']: desc for desc in json.loads(
application_descriptor_json)} | 155 |
| 148 for name in application_descriptor: | 156 for name in application_descriptor: |
| 149 merged_application_descriptor[name] = application_descriptor[nam
e] | 157 merged_application_descriptor[name] = application_descriptor[nam
e] |
| 150 | 158 |
| 151 for (module_name, module) in application_descriptor.items(): | 159 for (module_name, module) in application_descriptor.items(): |
| 152 if module_descriptors.get(module_name): | 160 if module_descriptors.get(module_name): |
| 153 bail_error('Duplicate definition of module "%s" in %s' % (mo
dule_name, application_descriptor_filename)) | 161 bail_error('Duplicate definition of module "%s" in %s' % (mo
dule_name, application_descriptor_filename)) |
| 154 if not all_module_descriptors.get(module_name): | 162 if not all_module_descriptors.get(module_name): |
| 155 module_descriptors[module_name] = self._read_module_descript
or(module_name, application_descriptor_filename) | 163 module_descriptors[module_name] = self._read_module_descript
or(module_name, application_descriptor_filename) |
| 156 all_module_descriptors[module_name] = module_descriptors[mod
ule_name] | 164 all_module_descriptors[module_name] = module_descriptors[mod
ule_name] |
| 157 | 165 |
| 158 for module in module_descriptors.values(): | 166 for module in module_descriptors.values(): |
| 159 deps = module.get('dependencies', []) | 167 deps = module.get('dependencies', []) |
| 160 for dep in deps: | 168 for dep in deps: |
| 161 if dep not in application_descriptor: | 169 if dep not in application_descriptor: |
| 162 bail_error('Module "%s" (dependency of "%s") not listed
in application descriptor %s' % (dep, module['name'], application_descriptor_fil
ename)) | 170 bail_error('Module "%s" (dependency of "%s") not listed
in application descriptor %s' % (dep, module['name'], application_descriptor_fil
ename)) |
| 163 | 171 |
| 164 return Descriptors(self.application_dir, merged_application_descriptor,
all_module_descriptors) | 172 return Descriptors(self.application_dir, merged_application_descriptor,
all_module_descriptors) |
| 165 | 173 |
| 166 def _read_module_descriptor(self, module_name, application_descriptor_filena
me): | 174 def _read_module_descriptor(self, module_name, application_descriptor_filena
me): |
| 167 json_filename = path.join(self.application_dir, module_name, 'module.jso
n') | 175 json_filename = path.join(self.application_dir, module_name, 'module.jso
n') |
| 168 if not path.exists(json_filename): | 176 if not path.exists(json_filename): |
| 169 bail_error('Module descriptor %s referenced in %s is missing' % (jso
n_filename, application_descriptor_filename)) | 177 bail_error('Module descriptor %s referenced in %s is missing' % (jso
n_filename, application_descriptor_filename)) |
| 170 module_json = json.loads(read_file(json_filename)) | 178 module_json = load_and_parse_json(json_filename) |
| 171 module_json['name'] = module_name | 179 module_json['name'] = module_name |
| 172 return module_json | 180 return module_json |
| OLD | NEW |