| 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 Release: | 8 Release: |
| 9 - Concatenates autostart modules, application modules' module.json descriptors
, | 9 - Concatenates autostart modules, application modules' module.json descriptors
, |
| 10 and the application loader into a single script. | 10 and the application loader into a single script. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 def resource_source_url(url): | 36 def resource_source_url(url): |
| 37 return '\n/*# sourceURL=' + url + ' */' | 37 return '\n/*# sourceURL=' + url + ' */' |
| 38 | 38 |
| 39 | 39 |
| 40 def minify_js(javascript): | 40 def minify_js(javascript): |
| 41 return rjsmin.jsmin(javascript) | 41 return rjsmin.jsmin(javascript) |
| 42 | 42 |
| 43 | 43 |
| 44 def concatenated_module_filename(module_name, output_dir): | 44 def concatenated_module_filename(module_name, output_dir): |
| 45 return join(output_dir, module_name + '_module.js') | 45 return join(output_dir, module_name + '/' + module_name + '_module.js') |
| 46 | 46 |
| 47 | 47 |
| 48 def symlink_or_copy_file(src, dest, safe=False): | 48 def symlink_or_copy_file(src, dest, safe=False): |
| 49 if safe and path.exists(dest): | 49 if safe and path.exists(dest): |
| 50 os.remove(dest) | 50 os.remove(dest) |
| 51 if hasattr(os, 'symlink'): | 51 if hasattr(os, 'symlink'): |
| 52 os.symlink(src, dest) | 52 os.symlink(src, dest) |
| 53 else: | 53 else: |
| 54 shutil.copy(src, dest) | 54 shutil.copy(src, dest) |
| 55 | 55 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 # Outputs: | 94 # Outputs: |
| 95 # <app_name>.html | 95 # <app_name>.html |
| 96 # <app_name>.js | 96 # <app_name>.js |
| 97 # <module_name>_module.js | 97 # <module_name>_module.js |
| 98 class ReleaseBuilder(AppBuilder): | 98 class ReleaseBuilder(AppBuilder): |
| 99 def __init__(self, application_name, descriptors, application_dir, output_di
r): | 99 def __init__(self, application_name, descriptors, application_dir, output_di
r): |
| 100 AppBuilder.__init__(self, application_name, descriptors, application_dir
, output_dir) | 100 AppBuilder.__init__(self, application_name, descriptors, application_dir
, output_dir) |
| 101 | 101 |
| 102 def build_app(self): | 102 def build_app(self): |
| 103 for module in self.descriptors.application.values(): |
| 104 if 'type' in module and module['type'] == 'remoteInRelease': |
| 105 module['type'] = 'remote' |
| 103 if self.descriptors.has_html: | 106 if self.descriptors.has_html: |
| 104 self._build_html() | 107 self._build_html() |
| 105 self._build_app_script() | 108 self._build_app_script() |
| 106 for module in filter(lambda desc: (not desc.get('type') or desc.get('typ
e') == 'remote'), self.descriptors.application.values()): | 109 for module in filter(lambda desc: (not desc.get('type') or desc.get('typ
e') == 'remote'), self.descriptors.application.values()): |
| 107 self._concatenate_dynamic_module(module['name']) | 110 self._concatenate_dynamic_module(module['name']) |
| 108 | 111 |
| 109 def _build_html(self): | 112 def _build_html(self): |
| 110 html_name = self.app_file('html') | 113 html_name = self.app_file('html') |
| 111 output = StringIO() | 114 output = StringIO() |
| 112 with open(join(self.application_dir, html_name), 'r') as app_input_html: | 115 with open(join(self.application_dir, html_name), 'r') as app_input_html: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 if (resource_path.endswith('.js')): | 134 if (resource_path.endswith('.js')): |
| 132 return ' <script type="text/javascript" src="%s"></script>\n' % r
esource_path | 135 return ' <script type="text/javascript" src="%s"></script>\n' % r
esource_path |
| 133 else: | 136 else: |
| 134 assert resource_path | 137 assert resource_path |
| 135 | 138 |
| 136 def _release_module_descriptors(self): | 139 def _release_module_descriptors(self): |
| 137 module_descriptors = self.descriptors.modules | 140 module_descriptors = self.descriptors.modules |
| 138 result = [] | 141 result = [] |
| 139 for name in module_descriptors: | 142 for name in module_descriptors: |
| 140 module = copy.copy(module_descriptors[name]) | 143 module = copy.copy(module_descriptors[name]) |
| 144 module_type = self.descriptors.application[name].get('type') |
| 141 # Clear scripts, as they are not used at runtime | 145 # Clear scripts, as they are not used at runtime |
| 142 # (only the fact of their presence is important). | 146 # (only the fact of their presence is important). |
| 143 resources = module.get('resources', None) | 147 resources = module.get('resources', None) |
| 144 if module.get('scripts') or resources: | 148 if module.get('scripts') or resources: |
| 145 module['scripts'] = [] | 149 if module_type == 'autostart': |
| 146 # Resources list is not used at runtime. | 150 # Autostart modules are already baked in. |
| 151 del module['scripts'] |
| 152 else: |
| 153 # Non-autostart modules are vulcanized. |
| 154 module['scripts'] = [name + '_module.js'] |
| 155 # Resources are already baked into scripts. |
| 147 if resources is not None: | 156 if resources is not None: |
| 148 del module['resources'] | 157 del module['resources'] |
| 149 condition = self.descriptors.application[name].get('condition') | |
| 150 if condition: | |
| 151 module['condition'] = condition | |
| 152 type = self.descriptors.application[name].get('type') | |
| 153 if type == 'remote': | |
| 154 module['remote'] = True | |
| 155 result.append(module) | 158 result.append(module) |
| 156 return json.dumps(result) | 159 return json.dumps(result) |
| 157 | 160 |
| 158 def _write_module_resources(self, resource_names, output): | 161 def _write_module_resources(self, resource_names, output): |
| 159 for resource_name in resource_names: | 162 for resource_name in resource_names: |
| 160 resource_name = path.normpath(resource_name).replace('\\', '/') | 163 resource_name = path.normpath(resource_name).replace('\\', '/') |
| 161 output.write('Runtime.cachedResources["%s"] = "' % resource_name) | 164 output.write('Runtime.cachedResources["%s"] = "' % resource_name) |
| 162 resource_content = read_file(path.join(self.application_dir, resourc
e_name)) + resource_source_url(resource_name) | 165 resource_content = read_file(path.join(self.application_dir, resourc
e_name)) + resource_source_url(resource_name) |
| 163 resource_content = resource_content.replace('\\', '\\\\') | 166 resource_content = resource_content.replace('\\', '\\\\') |
| 164 resource_content = resource_content.replace('\n', '\\n') | 167 resource_content = resource_content.replace('\n', '\\n') |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 symlink_or_copy_file(join(os.getcwd(), self.application_dir, html_name),
join(self.output_dir, html_name), True) | 241 symlink_or_copy_file(join(os.getcwd(), self.application_dir, html_name),
join(self.output_dir, html_name), True) |
| 239 | 242 |
| 240 | 243 |
| 241 def build_application(application_name, loader, application_dir, output_dir, rel
ease_mode): | 244 def build_application(application_name, loader, application_dir, output_dir, rel
ease_mode): |
| 242 descriptors = loader.load_application(application_name + '.json') | 245 descriptors = loader.load_application(application_name + '.json') |
| 243 if release_mode: | 246 if release_mode: |
| 244 builder = ReleaseBuilder(application_name, descriptors, application_dir,
output_dir) | 247 builder = ReleaseBuilder(application_name, descriptors, application_dir,
output_dir) |
| 245 else: | 248 else: |
| 246 builder = DebugBuilder(application_name, descriptors, application_dir, o
utput_dir) | 249 builder = DebugBuilder(application_name, descriptors, application_dir, o
utput_dir) |
| 247 builder.build_app() | 250 builder.build_app() |
| OLD | NEW |