shaka-player 4.1.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/.github/workflows/build-and-test.yaml +67 -15
  2. package/.github/workflows/compute-incremental-coverage.py +251 -0
  3. package/.github/workflows/report-incremental-coverage.yaml +39 -0
  4. package/.github/workflows/selenium-lab-tests.yaml +44 -1
  5. package/AUTHORS +1 -0
  6. package/CHANGELOG.md +36 -8
  7. package/CONTRIBUTORS +3 -0
  8. package/README.md +20 -6
  9. package/demo/common/assets.js +25 -0
  10. package/demo/common/message_ids.js +2 -0
  11. package/demo/config.js +5 -1
  12. package/demo/index.html +1 -3
  13. package/demo/locales/en.json +2 -0
  14. package/demo/locales/source.json +8 -0
  15. package/dist/controls.css +1 -1
  16. package/dist/demo.compiled.debug.js +25 -23
  17. package/dist/demo.compiled.debug.map +3 -3
  18. package/dist/demo.compiled.js +25 -23
  19. package/dist/demo.compiled.map +3 -3
  20. package/dist/deps.js +6 -5
  21. package/dist/locales.js +30 -30
  22. package/dist/receiver.compiled.debug.js +24 -22
  23. package/dist/receiver.compiled.debug.map +3 -3
  24. package/dist/receiver.compiled.js +24 -22
  25. package/dist/receiver.compiled.map +3 -3
  26. package/dist/shaka-player.compiled.d.ts +69 -5
  27. package/dist/shaka-player.compiled.debug.d.ts +69 -5
  28. package/dist/shaka-player.compiled.debug.externs.js +111 -42
  29. package/dist/shaka-player.compiled.debug.js +352 -301
  30. package/dist/shaka-player.compiled.debug.map +4 -4
  31. package/dist/shaka-player.compiled.externs.js +111 -42
  32. package/dist/shaka-player.compiled.js +823 -802
  33. package/dist/shaka-player.compiled.map +4 -4
  34. package/dist/shaka-player.ui.d.ts +69 -5
  35. package/dist/shaka-player.ui.debug.d.ts +69 -5
  36. package/dist/shaka-player.ui.debug.externs.js +111 -42
  37. package/dist/shaka-player.ui.debug.js +360 -310
  38. package/dist/shaka-player.ui.debug.map +4 -4
  39. package/dist/shaka-player.ui.externs.js +111 -42
  40. package/dist/shaka-player.ui.js +980 -957
  41. package/dist/shaka-player.ui.map +4 -4
  42. package/docs/tutorials/fairplay.md +149 -0
  43. package/docs/tutorials/ui.md +6 -6
  44. package/docs/tutorials/upgrade.md +1 -0
  45. package/docs/tutorials/welcome.md +6 -3
  46. package/externs/shaka/abr_manager.js +8 -0
  47. package/externs/shaka/manifest.js +43 -0
  48. package/externs/shaka/player.js +13 -2
  49. package/karma.conf.js +3 -11
  50. package/lib/abr/simple_abr_manager.js +72 -4
  51. package/lib/ads/client_side_ad_manager.js +1 -1
  52. package/lib/dash/dash_parser.js +5 -0
  53. package/lib/hls/hls_parser.js +123 -27
  54. package/lib/media/drm_engine.js +1 -3
  55. package/lib/media/media_source_engine.js +57 -24
  56. package/lib/media/presentation_timeline.js +24 -1
  57. package/lib/media/segment_index.js +8 -0
  58. package/lib/media/segment_reference.js +7 -1
  59. package/lib/media/streaming_engine.js +42 -6
  60. package/lib/media/time_ranges_utils.js +46 -0
  61. package/lib/net/networking_engine.js +1 -0
  62. package/lib/player.js +8 -6
  63. package/lib/polyfill/media_capabilities.js +9 -0
  64. package/lib/polyfill/patchedmediakeys_apple.js +729 -0
  65. package/lib/polyfill/videoplaybackquality.js +3 -1
  66. package/lib/text/cue.js +0 -5
  67. package/lib/text/simple_text_displayer.js +21 -9
  68. package/lib/text/ui_text_displayer.js +83 -19
  69. package/lib/text/vtt_text_parser.js +61 -4
  70. package/lib/util/buffer_utils.js +3 -0
  71. package/lib/util/error.js +21 -1
  72. package/lib/util/fairplay_utils.js +100 -2
  73. package/lib/util/object_utils.js +1 -0
  74. package/lib/util/platform.js +30 -1
  75. package/lib/util/player_configuration.js +3 -10
  76. package/lib/util/stream_utils.js +23 -3
  77. package/lib/util/string_utils.js +102 -13
  78. package/maintained-branches.md +15 -0
  79. package/package.json +3 -5
  80. package/shaka-player.uncompiled.js +1 -0
  81. package/test/hls/hls_parser_unit.js +49 -33
  82. package/test/media/drm_engine_integration.js +24 -8
  83. package/test/media/media_source_engine_integration.js +24 -10
  84. package/test/media/media_source_engine_unit.js +53 -38
  85. package/test/media/streaming_engine_unit.js +107 -32
  86. package/test/test/util/fake_media_source_engine.js +10 -9
  87. package/test/test/util/simple_fakes.js +4 -0
  88. package/test/test/util/streaming_engine_util.js +10 -2
  89. package/test/text/simple_text_displayer_unit.js +27 -0
  90. package/test/text/ui_text_displayer_unit.js +65 -0
  91. package/test/text/vtt_text_parser_unit.js +26 -0
  92. package/test/util/string_utils_unit.js +46 -8
  93. package/ui/text_selection.js +2 -2
  94. package/app-engine/README.md +0 -9
  95. package/app-engine/demo-version-index/README.md +0 -14
  96. package/app-engine/demo-version-index/app.yaml +0 -28
  97. package/app-engine/demo-version-index/generate.py +0 -164
  98. package/app-engine/demo-version-index/main.py +0 -11
  99. package/app-engine/demo-version-index/requirements.txt +0 -5
  100. package/app-engine/demo-version-index/templates/index.html +0 -114
  101. package/app-engine/shaka-player-demo/README.md +0 -18
  102. package/app-engine/shaka-player-demo/app.yaml +0 -61
  103. package/app-engine/shaka-player-demo/main.py +0 -95
  104. package/app-engine/shaka-player-demo/posters/10yo.png +0 -0
  105. package/app-engine/shaka-player-demo/posters/10yo.xcf +0 -0
  106. package/app-engine/shaka-player-demo/posters/1yo.jpg +0 -0
  107. package/app-engine/shaka-player-demo/posters/2yo.png +0 -0
  108. package/app-engine/shaka-player-demo/posters/2yo.xcf +0 -0
  109. package/app-engine/shaka-player-demo/posters/3yo.png +0 -0
  110. package/app-engine/shaka-player-demo/posters/3yo.xcf +0 -0
  111. package/app-engine/shaka-player-demo/posters/4yo.png +0 -0
  112. package/app-engine/shaka-player-demo/posters/4yo.xcf +0 -0
  113. package/app-engine/shaka-player-demo/posters/5yo.png +0 -0
  114. package/app-engine/shaka-player-demo/posters/5yo.xcf +0 -0
  115. package/app-engine/shaka-player-demo/posters/6yo.png +0 -0
  116. package/app-engine/shaka-player-demo/posters/6yo.xcf +0 -0
  117. package/app-engine/shaka-player-demo/posters/7yo.png +0 -0
  118. package/app-engine/shaka-player-demo/posters/7yo.xcf +0 -0
  119. package/app-engine/shaka-player-demo/posters/8yo.png +0 -0
  120. package/app-engine/shaka-player-demo/posters/8yo.xcf +0 -0
  121. package/app-engine/shaka-player-demo/posters/9yo.png +0 -0
  122. package/app-engine/shaka-player-demo/posters/9yo.xcf +0 -0
  123. package/app-engine/shaka-player-demo/posters/audioOnly.gif +0 -0
  124. package/app-engine/shaka-player-demo/posters/audioRickRoll.gif +0 -0
  125. package/app-engine/shaka-player-demo/posters/colorbars.gif +0 -0
  126. package/app-engine/shaka-player-demo/posters/fireworks.jpg +0 -0
  127. package/app-engine/shaka-player-demo/posters/party-hat.png +0 -0
  128. package/app-engine/shaka-player-demo/posters/sources.txt +0 -46
  129. package/app-engine/shaka-player-demo/posters/standard.png +0 -0
  130. package/app-engine/shaka-player-demo/posters/trek.jpg +0 -0
  131. package/app-engine/shaka-player-demo/posters/valentines.png +0 -0
  132. package/app-engine/shaka-player-demo/posters/zombie.jpg +0 -0
  133. package/app-engine/shaka-player-demo/posters.py +0 -110
  134. package/app-engine/shaka-player-demo/requirements.txt +0 -5
  135. package/app-engine/shaka-player-demo/time.txt +0 -1
  136. package/build/README.md +0 -127
  137. package/build/__init__.py +0 -0
  138. package/build/all.py +0 -150
  139. package/build/apps.py +0 -186
  140. package/build/build.py +0 -392
  141. package/build/check.py +0 -354
  142. package/build/checkversion.py +0 -84
  143. package/build/compiler.py +0 -513
  144. package/build/conformance.textproto +0 -335
  145. package/build/docker/Dockerfile +0 -20
  146. package/build/docker/docker-compose.yml +0 -10
  147. package/build/docs.py +0 -54
  148. package/build/eslint-plugin-shaka-rules/arg-comment-spacing.js +0 -72
  149. package/build/eslint-plugin-shaka-rules/index.js +0 -24
  150. package/build/eslint-plugin-shaka-rules/package.json +0 -7
  151. package/build/eslint-plugin-shaka-rules/private.js +0 -109
  152. package/build/gendeps.py +0 -71
  153. package/build/generateExterns.js +0 -867
  154. package/build/generateLocalizations.py +0 -262
  155. package/build/generateTsDefs.py +0 -137
  156. package/build/install-linux-prereqs.sh +0 -136
  157. package/build/license-header +0 -5
  158. package/build/misspellings.txt +0 -39
  159. package/build/pixelsChanged.js +0 -35
  160. package/build/shaka-lab.yaml +0 -161
  161. package/build/shakaBuildHelpers.py +0 -356
  162. package/build/stats.py +0 -816
  163. package/build/subprocessWindowsPatch.py +0 -103
  164. package/build/test.py +0 -541
  165. package/build/types/ads +0 -8
  166. package/build/types/cast +0 -6
  167. package/build/types/cea +0 -13
  168. package/build/types/complete +0 -9
  169. package/build/types/core +0 -108
  170. package/build/types/dash +0 -8
  171. package/build/types/hls +0 -9
  172. package/build/types/manifests +0 -5
  173. package/build/types/networking +0 -6
  174. package/build/types/offline +0 -22
  175. package/build/types/polyfill +0 -18
  176. package/build/types/text +0 -11
  177. package/build/types/ui +0 -39
  178. package/build/updateScreenshots.py +0 -85
  179. package/build/wrapper.template.js +0 -52
package/build/apps.py DELETED
@@ -1,186 +0,0 @@
1
- #!/usr/bin/env python
2
- #
3
- # Copyright 2016 Google LLC
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- """Build our various applications."""
18
-
19
- import argparse
20
- import logging
21
- import os
22
- import re
23
-
24
- import build
25
- import compiler
26
- import shakaBuildHelpers
27
-
28
-
29
- def compile_demo(force, is_debug):
30
- """Compile the demo application.
31
-
32
- Args:
33
- force: True to rebuild, False to ignore if no changes are detected.
34
- is_debug: True to compile for debugging, false for release.
35
-
36
- Returns:
37
- True on success, False on failure.
38
- """
39
- logging.info('Compiling the demo app (%s)...',
40
- 'debug' if is_debug else 'release')
41
-
42
- base = shakaBuildHelpers.get_source_base()
43
- closure_base_js = shakaBuildHelpers.get_closure_base_js_path()
44
- get = shakaBuildHelpers.get_all_js_files
45
- cast_receiver = set(get('demo', 'cast_receiver'))
46
- files = set(
47
- get('demo') +
48
- get('externs') +
49
- get('ui', 'externs') +
50
- [closure_base_js]) - cast_receiver
51
-
52
- # Make sure we don't compile in load.js, which will be used to bootstrap
53
- # everything else. If we build that into the output, we will get an
54
- # infinite loop of scripts adding themselves.
55
- files.remove(os.path.join(base, 'demo', 'load.js'))
56
- # Remove service_worker.js as well. This executes in a different context.
57
- files.remove(os.path.join(base, 'demo', 'service_worker.js'))
58
- # Don't compile in the uncompiled require file.
59
- files.remove(os.path.join(base, 'demo', 'demo_uncompiled.js'))
60
- # Add lib/debug/asserts.js, which is required for goog.assert.
61
- files.add(os.path.join(base, 'lib', 'debug', 'asserts.js'))
62
-
63
- # Add in the generated externs, so that the demo compilation knows the
64
- # definitions of the library APIs.
65
- externs = ('shaka-player.ui.debug.externs.js' if is_debug
66
- else 'shaka-player.ui.externs.js')
67
-
68
- files.add(os.path.join(base, 'dist', externs))
69
-
70
- name = 'demo.compiled' + ('.debug' if is_debug else '')
71
-
72
- # TODO: Why do we always use debug_closure_opts? Nobody remembers.
73
- closure_opts = build.common_closure_opts + build.debug_closure_opts
74
- closure_opts += [
75
- # Ignore missing goog.require since we assume the whole library is
76
- # already included.
77
- '--jscomp_off=missingRequire',
78
- '-D', 'COMPILED=true',
79
- ]
80
-
81
- closure = compiler.ClosureCompiler(files, name)
82
- # The output wrapper is only designed for the library. It can't be used
83
- # for apps. TODO: Should we add a simple function wrapper for apps?
84
- closure.add_wrapper = False
85
- if not closure.compile(closure_opts, force):
86
- return False
87
-
88
- return True
89
-
90
-
91
- def compile_receiver(force, is_debug):
92
- """Compile the cast receiver application.
93
-
94
- Args:
95
- force: True to rebuild, False to ignore if no changes are detected.
96
- is_debug: True to compile for debugging, false for release.
97
-
98
- Returns:
99
- True on success, False on failure.
100
- """
101
- logging.info('Compiling the receiver app (%s)...',
102
- 'debug' if is_debug else 'release')
103
-
104
- base = shakaBuildHelpers.get_source_base()
105
- closure_base_js = shakaBuildHelpers.get_closure_base_js_path()
106
- get = shakaBuildHelpers.get_all_js_files
107
- files = set(get('demo', 'common') +
108
- get('demo', 'cast_receiver') +
109
- get('externs') +
110
- get('ui', 'externs') +
111
- [closure_base_js])
112
-
113
- # Add in the generated externs, so that the receiver compilation knows the
114
- # definitions of the library APIs.
115
- externs = ('shaka-player.ui.debug.externs.js' if is_debug
116
- else 'shaka-player.ui.externs.js')
117
-
118
- files.add(os.path.join(base, 'dist', externs))
119
- files.add(os.path.join(base, 'lib', 'debug', 'asserts.js'))
120
-
121
- name = 'receiver.compiled' + ('.debug' if is_debug else '')
122
-
123
- # TODO: Why do we always use debug_closure_opts? Nobody remembers.
124
- closure_opts = build.common_closure_opts + build.debug_closure_opts
125
- closure_opts += [
126
- # Ignore missing goog.require since we assume the whole library is
127
- # already included.
128
- '--jscomp_off=missingRequire',
129
- '-D', 'COMPILED=true',
130
- ]
131
-
132
- closure = compiler.ClosureCompiler(files, name)
133
- # The output wrapper is only designed for the library. It can't be used
134
- # for apps. TODO: Should we add a simple function wrapper for apps?
135
- closure.add_wrapper = False
136
- if not closure.compile(closure_opts, force):
137
- return False
138
-
139
- return True
140
-
141
-
142
- def build_all(force, is_debug):
143
- if not compile_demo(force, is_debug):
144
- return False
145
-
146
- if not compile_receiver(force, is_debug):
147
- return False
148
-
149
- return True
150
-
151
-
152
- def main(args):
153
- parser = argparse.ArgumentParser(
154
- description=__doc__,
155
- formatter_class=argparse.RawDescriptionHelpFormatter)
156
-
157
- parser.add_argument(
158
- '--force',
159
- '-f',
160
- help='Force building the library even if no files have changed.',
161
- action='store_true')
162
-
163
- parsed_args = parser.parse_args(args)
164
-
165
- # Make the dist/ folder, ignore errors.
166
- base = shakaBuildHelpers.get_source_base()
167
- try:
168
- os.mkdir(os.path.join(base, 'dist'))
169
- except OSError:
170
- pass
171
-
172
- force = parsed_args.force
173
-
174
- # Update node modules if needed.
175
- if not shakaBuildHelpers.update_node_modules():
176
- return 1
177
-
178
- for is_debug in [True, False]:
179
- if not build_all(force, is_debug):
180
- return 1
181
-
182
- return 0
183
-
184
-
185
- if __name__ == '__main__':
186
- shakaBuildHelpers.run_main(main)
package/build/build.py DELETED
@@ -1,392 +0,0 @@
1
- #!/usr/bin/env python
2
- #
3
- # Copyright 2016 Google LLC
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- """Creates a build from the given commands.
18
-
19
- A command is either an addition or a subtraction. An addition is prefixed with
20
- a +; a subtraction is when prefixed with a -. After the character, there is a
21
- name of a file or a @ sign and the name of a build file.
22
-
23
- Build files are the files found in build/types. These files are simply a
24
- newline separated list of commands to execute. So if the "+@complete" command
25
- is given, it will open the complete file and run it (which may in turn open
26
- other build files). Subtracting a build file will reverse all actions applied
27
- by the given file. So "-@networking" will remove all the networking plugins,
28
- and "-@ui" will remove the UI.
29
-
30
- The core library is always included so does not have to be listed. The default
31
- is to use the name 'ui'; if no commands are given, it will build the complete
32
- build, including the UI.
33
-
34
- Examples:
35
- # Equivalent to +@complete
36
- build.py
37
-
38
- build.py +@complete
39
- build.py +@complete -@networking
40
- build.py +@complete -@ui
41
- build.py --name custom +@manifests +@networking +../my_plugin.js
42
- """
43
-
44
- import argparse
45
- import logging
46
- import os
47
- import re
48
-
49
- import compiler
50
- import generateLocalizations
51
- import shakaBuildHelpers
52
-
53
-
54
- shaka_version = shakaBuildHelpers.calculate_version()
55
-
56
- common_closure_opts = [
57
- '--language_out', 'ECMASCRIPT3',
58
-
59
- '--jscomp_error=*',
60
-
61
- # Turn off complaints like:
62
- # "Private property foo_ is never modified, use the @const annotation"
63
- '--jscomp_off=jsdocMissingConst',
64
-
65
- # Turn off complaints like:
66
- # "Object is a reference type with no nullability modifier that is
67
- # explicitly set to null."
68
- # and:
69
- # "Property defineClass of type goog has been deprecated"
70
- # Even the Closure Library's base.js doesn't pass these checks yet as of
71
- # the 20200406 release.
72
- '--jscomp_off=lintChecks',
73
- '--jscomp_off=deprecated',
74
- # Turn off complaints like:
75
- # "Built-in 'Reflect.setPrototypeOf' not supported in output version es3."
76
- '--jscomp_off=missingPolyfill',
77
- '--extra_annotation_name=listens',
78
- '--extra_annotation_name=exportDoc',
79
- '--extra_annotation_name=exportInterface',
80
-
81
- '--conformance_configs',
82
- ('%s/build/conformance.textproto' %
83
- shakaBuildHelpers.cygwin_safe_path(shakaBuildHelpers.get_source_base())),
84
-
85
- '--generate_exports',
86
- ]
87
- common_closure_defines = [
88
- '-D', 'COMPILED=true',
89
- '-D', 'goog.ENABLE_DEBUG_LOADER=false',
90
- ]
91
-
92
- debug_closure_opts = [
93
- '-O', 'SIMPLE',
94
- ]
95
- debug_closure_defines = [
96
- '-D', 'goog.DEBUG=true',
97
- '-D', 'goog.asserts.ENABLE_ASSERTS=true',
98
- '-D', 'shaka.log.MAX_LOG_LEVEL=4', # shaka.log.Level.DEBUG
99
- '-D', 'shaka.Player.version="%s-debug"' % shaka_version,
100
- ]
101
-
102
- release_closure_opts = [
103
- '-O', 'ADVANCED',
104
- ]
105
- release_closure_defines = [
106
- '-D', 'goog.DEBUG=false',
107
- '-D', 'goog.asserts.ENABLE_ASSERTS=false',
108
- '-D', 'shaka.log.MAX_LOG_LEVEL=0',
109
- '-D', 'shaka.Player.version="%s"' % shaka_version,
110
- ]
111
-
112
-
113
- class Build(object):
114
- """Defines a build that has been parsed from a build file.
115
-
116
- This has exclude files even though it will not be used at the top-level. This
117
- allows combining builds. A file will only exist in at most one set.
118
-
119
- Members:
120
- include - A set of files to include.
121
- exclude - A set of files to remove.
122
- """
123
-
124
- def __init__(self, include=None, exclude=None):
125
- self.include = include or set()
126
- self.exclude = exclude or set()
127
-
128
- def _get_build_file_path(self, name, root):
129
- """Gets the full path to a build file, if it exists.
130
-
131
- Args:
132
- name: The string name to check.
133
- root: The full path to the base directory.
134
-
135
- Returns:
136
- The full path to the build file, or None if not found.
137
- """
138
- source_base = shakaBuildHelpers.get_source_base()
139
- local_path = os.path.join(root, name)
140
- build_path = os.path.join(source_base, 'build', 'types', name)
141
- if (os.path.isfile(local_path) and os.path.isfile(build_path)
142
- and local_path != build_path):
143
- logging.error('Build file "%s" is ambiguous', name)
144
- return None
145
- elif os.path.isfile(local_path):
146
- return local_path
147
- elif os.path.isfile(build_path):
148
- return build_path
149
- else:
150
- logging.error('Build file not found: %s', name)
151
- return None
152
-
153
- def _combine(self, other):
154
- include_all = self.include | other.include
155
- exclude_all = self.exclude | other.exclude
156
- self.include = include_all - exclude_all
157
- self.exclude = exclude_all - include_all
158
-
159
- def reverse(self):
160
- return Build(self.exclude, self.include)
161
-
162
- def add_closure(self):
163
- """Adds the closure library and externs."""
164
- # Add externs and closure dependencies.
165
- self.include |= set(
166
- [shakaBuildHelpers.get_closure_base_js_path()] +
167
- shakaBuildHelpers.get_all_js_files('externs'))
168
-
169
- def add_core(self):
170
- """Adds the core library."""
171
- # Check that there are no files in 'core' that are removed
172
- core_build = Build()
173
- core_build.parse_build(['+@core'], os.getcwd())
174
- core_files = core_build.include
175
- if self.exclude & core_files:
176
- logging.error('Cannot exclude files from core')
177
- return False
178
- self.include |= core_files
179
- return True
180
-
181
- def has_ui(self):
182
- """Returns True if the UI library is in the build."""
183
- for path in self.include:
184
- if 'ui' in path.split(os.path.sep):
185
- return True
186
- return False
187
-
188
- def generate_localizations(self, locales, force):
189
- localizations = compiler.GenerateLocalizations(locales)
190
- localizations.generate(force)
191
- self.include.add(os.path.abspath(localizations.output))
192
-
193
- def parse_build(self, lines, root):
194
- """Parses a Build object from the given lines of commands.
195
-
196
- This will recursively read and parse builds.
197
-
198
- Args:
199
- lines: An array of strings defining commands.
200
- root: The full path to the base directory.
201
-
202
- Returns:
203
- True on success, False otherwise.
204
- """
205
- for line in lines:
206
- # Strip comments
207
- try:
208
- line = line[:line.index('#')]
209
- except ValueError:
210
- pass
211
-
212
- # Strip whitespace and ignore empty lines.
213
- line = line.strip()
214
- if not line:
215
- continue
216
-
217
- if line[0] == '+':
218
- is_neg = False
219
- line = line[1:].strip()
220
- elif line[0] == '-':
221
- is_neg = True
222
- line = line[1:].strip()
223
- else:
224
- logging.error('Operation (+/-) required')
225
- return False
226
-
227
- if line[0] == '@':
228
- line = line[1:].strip()
229
-
230
- build_path = self._get_build_file_path(line, root)
231
- if not build_path:
232
- return False
233
- lines = shakaBuildHelpers.open_file(build_path).readlines()
234
- sub_root = os.path.dirname(build_path)
235
-
236
- # If this is a build file, then recurse and combine the builds.
237
- sub_build = Build()
238
- if not sub_build.parse_build(lines, sub_root):
239
- return False
240
-
241
- if is_neg:
242
- self._combine(sub_build.reverse())
243
- else:
244
- self._combine(sub_build)
245
- else:
246
- if not os.path.isabs(line):
247
- line = os.path.abspath(os.path.join(root, line))
248
- if not os.path.isfile(line):
249
- logging.error('Unable to find file: %s', line)
250
- return False
251
-
252
- if is_neg:
253
- self.include.discard(line)
254
- self.exclude.add(line)
255
- else:
256
- self.include.add(line)
257
- self.exclude.discard(line)
258
-
259
- return True
260
-
261
- def build_library(self, name, locales, force, is_debug):
262
- """Builds Shaka Player using the files in |self.include|.
263
-
264
- Args:
265
- name: The name of the build.
266
- locales: A list of strings of locale identifiers.
267
- force: True to rebuild, False to ignore if no changes are detected.
268
- is_debug: True to compile for debugging, false for release.
269
-
270
- Returns:
271
- True on success; False on failure.
272
- """
273
- self.add_closure()
274
- if not self.add_core():
275
- return False
276
- if self.has_ui():
277
- self.generate_localizations(locales, force)
278
-
279
- if is_debug:
280
- name += '.debug'
281
-
282
- build_name = 'shaka-player.' + name
283
- closure = compiler.ClosureCompiler(self.include, build_name)
284
-
285
- closure_opts = common_closure_opts + common_closure_defines
286
- if is_debug:
287
- closure_opts += debug_closure_opts + debug_closure_defines
288
- else:
289
- closure_opts += release_closure_opts + release_closure_defines
290
-
291
- if not closure.compile(closure_opts, force):
292
- return False
293
-
294
- # Don't pass local node modules to the extern generator. But don't simply
295
- # exclude the string 'node_modules', either, since Shaka Player could be
296
- # rebuilt after installing it as a node module.
297
- node_modules_path = os.path.join(
298
- shakaBuildHelpers.get_source_base(), 'node_modules')
299
- local_include = set([f for f in self.include if node_modules_path not in f])
300
- extern_generator = compiler.ExternGenerator(local_include, build_name)
301
-
302
- if not extern_generator.generate(force):
303
- return False
304
-
305
- generated_externs = [extern_generator.output]
306
- shaka_externs = shakaBuildHelpers.get_all_js_files('externs')
307
- if self.has_ui():
308
- shaka_externs += shakaBuildHelpers.get_all_js_files('ui/externs')
309
- ts_def_generator = compiler.TsDefGenerator(
310
- generated_externs + shaka_externs, build_name)
311
-
312
- if not ts_def_generator.generate(force):
313
- return False
314
-
315
- return True
316
-
317
-
318
- def main(args):
319
- parser = argparse.ArgumentParser(
320
- description=__doc__,
321
- formatter_class=argparse.RawDescriptionHelpFormatter)
322
-
323
- parser.add_argument(
324
- '--locales',
325
- type=str,
326
- nargs='+',
327
- default=generateLocalizations.DEFAULT_LOCALES,
328
- help='The list of locales to compile in (requires UI, default %(default)r)')
329
-
330
- parser.add_argument(
331
- '--force',
332
- '-f',
333
- help='Force building the library even if no files have changed.',
334
- action='store_true')
335
-
336
- parser.add_argument(
337
- '--mode',
338
- help='Specify which build mode to use.',
339
- choices=['debug', 'release'],
340
- default='release')
341
-
342
- parser.add_argument(
343
- '--debug',
344
- help='Same as using "--mode debug".',
345
- action='store_const',
346
- dest='mode',
347
- const='debug')
348
-
349
- parser.add_argument(
350
- '--name',
351
- help='Set the name of the build. Uses "ui" if not given.',
352
- type=str,
353
- default='ui')
354
-
355
- parsed_args, commands = parser.parse_known_args(args)
356
-
357
- # Make the dist/ folder, ignore errors.
358
- base = shakaBuildHelpers.get_source_base()
359
- try:
360
- os.mkdir(os.path.join(base, 'dist'))
361
- except OSError:
362
- pass
363
-
364
- # Update node modules if needed.
365
- if not shakaBuildHelpers.update_node_modules():
366
- return 1
367
-
368
- # If no commands are given then use complete by default.
369
- if len(commands) == 0:
370
- commands.append('+@complete')
371
-
372
- logging.info('Compiling the library (%s, %s)...',
373
- parsed_args.name, parsed_args.mode)
374
-
375
- custom_build = Build()
376
-
377
- if not custom_build.parse_build(commands, os.getcwd()):
378
- return 1
379
-
380
- name = parsed_args.name
381
- locales = parsed_args.locales
382
- force = parsed_args.force
383
- is_debug = parsed_args.mode == 'debug'
384
-
385
- if not custom_build.build_library(name, locales, force, is_debug):
386
- return 1
387
-
388
- return 0
389
-
390
-
391
- if __name__ == '__main__':
392
- shakaBuildHelpers.run_main(main)