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 Concatenates autostart modules, application modules' module.json descriptors, | 8 Concatenates autostart modules, application modules' module.json descriptors, |
9 and the application loader into a single script. | 9 and the application loader into a single script. |
10 Also concatenates all workers' dependencies into individual worker loader script
s. | 10 Also concatenates all workers' dependencies into individual worker loader script
s. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 write_file(path.join(output_dir, application_loader_name), minify_if_needed(
output.getvalue(), minify)) | 73 write_file(path.join(output_dir, application_loader_name), minify_if_needed(
output.getvalue(), minify)) |
74 output.close() | 74 output.close() |
75 | 75 |
76 | 76 |
77 def concatenate_worker(module_name, descriptors, application_dir, output_dir, mi
nify): | 77 def concatenate_worker(module_name, descriptors, application_dir, output_dir, mi
nify): |
78 descriptor = descriptors.modules[module_name] | 78 descriptor = descriptors.modules[module_name] |
79 scripts = descriptor.get('scripts') | 79 scripts = descriptor.get('scripts') |
80 if not scripts: | 80 if not scripts: |
81 return | 81 return |
82 worker_dir = path.join(application_dir, module_name) | 82 worker_dir = path.join(application_dir, module_name) |
83 output_file_path = path.join(output_dir, module_name, module_name + '_module
.js') | 83 output_file_path = path.join(output_dir, module_name, module_name + '.js') |
84 | 84 |
85 output = StringIO() | 85 output = StringIO() |
86 output.write('/* Worker %s */\n' % module_name) | 86 output.write('/* Worker %s */\n' % module_name) |
87 output.write('/* Runtime.js */\n') | 87 output.write('/* Runtime.js */\n') |
88 output.write(read_file(path.join(application_dir, 'Runtime.js'))) | 88 output.write(read_file(path.join(application_dir, 'Runtime.js'))) |
89 dependencies = descriptors.sorted_dependencies_closure(module_name) | 89 dependencies = descriptors.sorted_dependencies_closure(module_name) |
90 dep_descriptors = [] | 90 dep_descriptors = [] |
91 for dep_name in dependencies: | 91 for dep_name in dependencies: |
92 dep_descriptor = descriptors.modules[dep_name] | 92 dep_descriptor = descriptors.modules[dep_name] |
93 dep_descriptors.append(dep_descriptor) | 93 dep_descriptors.append(dep_descriptor) |
94 scripts = dep_descriptor.get('scripts') | 94 scripts = dep_descriptor.get('scripts') |
95 if scripts: | 95 if scripts: |
96 output.write('\n/* Module %s */\n' % dep_name) | 96 output.write('\n/* Module %s */\n' % dep_name) |
97 modular_build.concatenate_scripts(scripts, path.join(application_dir
, dep_name), output_dir, output) | 97 modular_build.concatenate_scripts(scripts, path.join(application_dir
, dep_name), output_dir, output) |
98 | 98 |
| 99 output.write('\n/* Initialize worker */\n') |
| 100 # Tell Runtime we are in the compiled mode. |
| 101 output.write('allDescriptors = ') |
| 102 output.write(json.dumps(dep_descriptors)) |
| 103 output.write(';\nRuntime.initializeWorker("%s");' % module_name) |
| 104 |
99 write_file(output_file_path, minify_if_needed(output.getvalue(), minify)) | 105 write_file(output_file_path, minify_if_needed(output.getvalue(), minify)) |
100 output.close() | 106 output.close() |
101 | 107 |
102 | 108 |
103 def build_application(application_name, loader, application_dir, output_dir, min
ify): | 109 def build_application(application_name, loader, application_dir, output_dir, min
ify): |
104 descriptors = loader.load_application(application_name + '.json') | 110 descriptors = loader.load_application(application_name + '.json') |
105 concatenate_application_script(application_name, descriptors, application_di
r, output_dir, minify) | 111 concatenate_application_script(application_name, descriptors, application_di
r, output_dir, minify) |
106 for module in filter(lambda desc: desc.get('type') == 'worker', descriptors.
application.values()): | 112 for module in filter(lambda desc: desc.get('type') == 'worker', descriptors.
application.values()): |
107 concatenate_worker(module['name'], descriptors, application_dir, output_
dir, minify) | 113 concatenate_worker(module['name'], descriptors, application_dir, output_
dir, minify) |
OLD | NEW |