forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapps.py
executable file
·186 lines (145 loc) · 5.63 KB
/
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python
#
# Copyright 2016 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Build our various applications."""
import argparse
import logging
import os
import re
import build
import compiler
import shakaBuildHelpers
def compile_demo(force, is_debug):
"""Compile the demo application.
Args:
force: True to rebuild, False to ignore if no changes are detected.
is_debug: True to compile for debugging, false for release.
Returns:
True on success, False on failure.
"""
logging.info('Compiling the demo app (%s)...',
'debug' if is_debug else 'release')
base = shakaBuildHelpers.get_source_base()
closure_base_js = shakaBuildHelpers.get_closure_base_js_path()
get = shakaBuildHelpers.get_all_js_files
cast_receiver = set(get('demo', 'cast_receiver'))
files = set(
get('demo') +
get('externs') +
get('ui', 'externs') +
[closure_base_js]) - cast_receiver
# Make sure we don't compile in load.js, which will be used to bootstrap
# everything else. If we build that into the output, we will get an
# infinite loop of scripts adding themselves.
files.remove(os.path.join(base, 'demo', 'load.js'))
# Remove service_worker.js as well. This executes in a different context.
files.remove(os.path.join(base, 'demo', 'service_worker.js'))
# Don't compile in the uncompiled require file.
files.remove(os.path.join(base, 'demo', 'demo_uncompiled.js'))
# Add lib/debug/asserts.js, which is required for goog.assert.
files.add(os.path.join(base, 'lib', 'debug', 'asserts.js'))
# Add in the generated externs, so that the demo compilation knows the
# definitions of the library APIs.
externs = ('shaka-player.ui.debug.externs.js' if is_debug
else 'shaka-player.ui.externs.js')
files.add(os.path.join(base, 'dist', externs))
name = 'demo.compiled' + ('.debug' if is_debug else '')
# TODO: Why do we always use debug_closure_opts? Nobody remembers.
closure_opts = build.common_closure_opts + build.debug_closure_opts
closure_opts += [
# Ignore missing goog.require since we assume the whole library is
# already included.
'--jscomp_off=missingRequire',
'-D', 'COMPILED=true',
]
closure = compiler.ClosureCompiler(files, name)
# The output wrapper is only designed for the library. It can't be used
# for apps. TODO: Should we add a simple function wrapper for apps?
closure.add_wrapper = False
if not closure.compile(closure_opts, force):
return False
return True
def compile_receiver(force, is_debug):
"""Compile the cast receiver application.
Args:
force: True to rebuild, False to ignore if no changes are detected.
is_debug: True to compile for debugging, false for release.
Returns:
True on success, False on failure.
"""
logging.info('Compiling the receiver app (%s)...',
'debug' if is_debug else 'release')
base = shakaBuildHelpers.get_source_base()
closure_base_js = shakaBuildHelpers.get_closure_base_js_path()
get = shakaBuildHelpers.get_all_js_files
files = set(get('demo', 'common') +
get('demo', 'cast_receiver') +
get('externs') +
get('ui', 'externs') +
[closure_base_js])
# Add in the generated externs, so that the receiver compilation knows the
# definitions of the library APIs.
externs = ('shaka-player.ui.debug.externs.js' if is_debug
else 'shaka-player.ui.externs.js')
files.add(os.path.join(base, 'dist', externs))
files.add(os.path.join(base, 'lib', 'debug', 'asserts.js'))
name = 'receiver.compiled' + ('.debug' if is_debug else '')
# TODO: Why do we always use debug_closure_opts? Nobody remembers.
closure_opts = build.common_closure_opts + build.debug_closure_opts
closure_opts += [
# Ignore missing goog.require since we assume the whole library is
# already included.
'--jscomp_off=missingRequire',
'-D', 'COMPILED=true',
]
closure = compiler.ClosureCompiler(files, name)
# The output wrapper is only designed for the library. It can't be used
# for apps. TODO: Should we add a simple function wrapper for apps?
closure.add_wrapper = False
if not closure.compile(closure_opts, force):
return False
return True
def build_all(force, is_debug):
if not compile_demo(force, is_debug):
return False
if not compile_receiver(force, is_debug):
return False
return True
def main(args):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'--force',
'-f',
help='Force building the library even if no files have changed.',
action='store_true')
parsed_args = parser.parse_args(args)
# Make the dist/ folder, ignore errors.
base = shakaBuildHelpers.get_source_base()
try:
os.mkdir(os.path.join(base, 'dist'))
except OSError:
pass
force = parsed_args.force
# Update node modules if needed.
if not shakaBuildHelpers.update_node_modules():
return 1
for is_debug in [True, False]:
if not build_all(force, is_debug):
return 1
return 0
if __name__ == '__main__':
shakaBuildHelpers.run_main(main)