| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # -*- coding: UTF-8 -*- | 2 # -*- coding: UTF-8 -*- |
| 3 # | 3 # |
| 4 # Copyright 2016 The Chromium Authors. All rights reserved. | 4 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
| 7 | 7 |
| 8 """ | 8 """ |
| 9 Builds applications in release mode: | 9 Builds applications in release mode: |
| 10 - Concatenates autostart modules, application modules' module.json descriptors, | 10 - Concatenates autostart modules, application modules' module.json descriptors, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 from modular_build import read_file, write_file, bail_error | 24 from modular_build import read_file, write_file, bail_error |
| 25 import modular_build | 25 import modular_build |
| 26 import rjsmin | 26 import rjsmin |
| 27 | 27 |
| 28 try: | 28 try: |
| 29 import simplejson as json | 29 import simplejson as json |
| 30 except ImportError: | 30 except ImportError: |
| 31 import json | 31 import json |
| 32 | 32 |
| 33 special_case_namespaces_path = path.join(path.dirname(path.dirname(path.abspath(
__file__))), 'special_case_namespaces.json') |
| 34 |
| 33 | 35 |
| 34 def main(argv): | 36 def main(argv): |
| 35 try: | 37 try: |
| 36 input_path_flag_index = argv.index('--input_path') | 38 input_path_flag_index = argv.index('--input_path') |
| 37 input_path = argv[input_path_flag_index + 1] | 39 input_path = argv[input_path_flag_index + 1] |
| 38 output_path_flag_index = argv.index('--output_path') | 40 output_path_flag_index = argv.index('--output_path') |
| 39 output_path = argv[output_path_flag_index + 1] | 41 output_path = argv[output_path_flag_index + 1] |
| 40 application_names = argv[1:input_path_flag_index] | 42 application_names = argv[1:input_path_flag_index] |
| 41 except: | 43 except: |
| 42 print('Usage: %s app_1 app_2 ... app_N --input_path <input_path> --outpu
t_path <output_path>' % argv[0]) | 44 print('Usage: %s app_1 app_2 ... app_N --input_path <input_path> --outpu
t_path <output_path>' % argv[0]) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 # Outputs: | 88 # Outputs: |
| 87 # <app_name>.html | 89 # <app_name>.html |
| 88 # <app_name>.js | 90 # <app_name>.js |
| 89 # <module_name>_module.js | 91 # <module_name>_module.js |
| 90 class ReleaseBuilder(object): | 92 class ReleaseBuilder(object): |
| 91 def __init__(self, application_name, descriptors, application_dir, output_di
r): | 93 def __init__(self, application_name, descriptors, application_dir, output_di
r): |
| 92 self.application_name = application_name | 94 self.application_name = application_name |
| 93 self.descriptors = descriptors | 95 self.descriptors = descriptors |
| 94 self.application_dir = application_dir | 96 self.application_dir = application_dir |
| 95 self.output_dir = output_dir | 97 self.output_dir = output_dir |
| 98 with open(special_case_namespaces_path) as json_file: |
| 99 self._special_case_namespaces = json.load(json_file) |
| 96 | 100 |
| 97 def app_file(self, extension): | 101 def app_file(self, extension): |
| 98 return self.application_name + '.' + extension | 102 return self.application_name + '.' + extension |
| 99 | 103 |
| 100 def core_resource_names(self): | 104 def core_resource_names(self): |
| 101 result = [] | 105 result = [] |
| 102 for module in self.descriptors.sorted_modules(): | 106 for module in self.descriptors.sorted_modules(): |
| 103 if self.descriptors.application[module].get('type') != 'autostart': | 107 if self.descriptors.application[module].get('type') != 'autostart': |
| 104 continue | 108 continue |
| 105 | 109 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 sorted_module_names = self.descriptors.sorted_modules() | 186 sorted_module_names = self.descriptors.sorted_modules() |
| 183 for name in sorted_module_names: | 187 for name in sorted_module_names: |
| 184 desc = self.descriptors.modules[name] | 188 desc = self.descriptors.modules[name] |
| 185 name = desc['name'] | 189 name = desc['name'] |
| 186 type = self.descriptors.application[name].get('type') | 190 type = self.descriptors.application[name].get('type') |
| 187 if type == 'autostart': | 191 if type == 'autostart': |
| 188 deps = set(desc.get('dependencies', [])) | 192 deps = set(desc.get('dependencies', [])) |
| 189 non_autostart_deps = deps & non_autostart | 193 non_autostart_deps = deps & non_autostart |
| 190 if len(non_autostart_deps): | 194 if len(non_autostart_deps): |
| 191 bail_error('Non-autostart dependencies specified for the aut
ostarted module "%s": %s' % (name, non_autostart_deps)) | 195 bail_error('Non-autostart dependencies specified for the aut
ostarted module "%s": %s' % (name, non_autostart_deps)) |
| 192 | 196 namespace = self._map_module_to_namespace(name) |
| 193 namespace = name.replace('_lazy', '') | |
| 194 if namespace == 'sdk' or namespace == 'ui': | |
| 195 namespace = namespace.upper(); | |
| 196 namespace = "".join(map(lambda x: x[0].upper() + x[1:], namespac
e.split('_'))) | |
| 197 output.write('\n/* Module %s */\n' % name) | 197 output.write('\n/* Module %s */\n' % name) |
| 198 output.write('\nself[\'%s\'] = self[\'%s\'] || {};\n' % (namespa
ce, namespace)) | 198 output.write('\nself[\'%s\'] = self[\'%s\'] || {};\n' % (namespa
ce, namespace)) |
| 199 modular_build.concatenate_scripts(desc.get('scripts'), join(self
.application_dir, name), self.output_dir, output) | 199 modular_build.concatenate_scripts(desc.get('scripts'), join(self
.application_dir, name), self.output_dir, output) |
| 200 else: | 200 else: |
| 201 non_autostart.add(name) | 201 non_autostart.add(name) |
| 202 | 202 |
| 203 def _map_module_to_namespace(self, module): |
| 204 camel_case_namespace = "".join(map(lambda x: x[0].upper() + x[1:], modul
e.split('_'))) |
| 205 return self._special_case_namespaces.get(module, camel_case_namespace) |
| 206 |
| 203 def _concatenate_application_script(self, output): | 207 def _concatenate_application_script(self, output): |
| 204 runtime_contents = read_file(join(self.application_dir, 'Runtime.js')) | 208 runtime_contents = read_file(join(self.application_dir, 'Runtime.js')) |
| 205 runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescript
ors = %s;' % self._release_module_descriptors().replace('\\', '\\\\'), runtime_c
ontents, 1) | 209 runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescript
ors = %s;' % self._release_module_descriptors().replace('\\', '\\\\'), runtime_c
ontents, 1) |
| 206 output.write('/* Runtime.js */\n') | 210 output.write('/* Runtime.js */\n') |
| 207 output.write(runtime_contents) | 211 output.write(runtime_contents) |
| 208 output.write('\n/* Autostart modules */\n') | 212 output.write('\n/* Autostart modules */\n') |
| 209 self._concatenate_autostart_modules(output) | 213 self._concatenate_autostart_modules(output) |
| 210 output.write('/* Application descriptor %s */\n' % self.app_file('json')
) | 214 output.write('/* Application descriptor %s */\n' % self.app_file('json')
) |
| 211 output.write('applicationDescriptor = ') | 215 output.write('applicationDescriptor = ') |
| 212 output.write(self.descriptors.application_json()) | 216 output.write(self.descriptors.application_json()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 225 modular_build.concatenate_scripts(scripts, module_dir, self.output_d
ir, output) | 229 modular_build.concatenate_scripts(scripts, module_dir, self.output_d
ir, output) |
| 226 if resources: | 230 if resources: |
| 227 self._write_module_resources(resources, output) | 231 self._write_module_resources(resources, output) |
| 228 output_file_path = concatenated_module_filename(module_name, self.output
_dir) | 232 output_file_path = concatenated_module_filename(module_name, self.output
_dir) |
| 229 write_file(output_file_path, minify_js(output.getvalue())) | 233 write_file(output_file_path, minify_js(output.getvalue())) |
| 230 output.close() | 234 output.close() |
| 231 | 235 |
| 232 | 236 |
| 233 if __name__ == '__main__': | 237 if __name__ == '__main__': |
| 234 sys.exit(main(sys.argv)) | 238 sys.exit(main(sys.argv)) |
| OLD | NEW |