def generate_externs(self, name): """Generates externs for the files in |self.include|. Args: name: The name of the build. Returns: True on success; False on failure. """ # Update node modules if needed. if not shakaBuildHelpers.update_node_modules(): return False files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] extern_generator = shakaBuildHelpers.cygwin_safe_path( os.path.join(shakaBuildHelpers.get_source_base(), 'build', 'generateExterns.js')) output = shakaBuildHelpers.cygwin_safe_path( os.path.join(shakaBuildHelpers.get_source_base(), 'dist', 'shaka-player.' + name + '.externs.js')) # TODO: support Windows builds cmd_line = ['node', extern_generator, '--output', output] + files if shakaBuildHelpers.execute_get_code(cmd_line) != 0: print >> sys.stderr, 'Externs generation failed' return False return True
def generate_externs(self, name): """Generates externs for the files in |self.include|. Args: name: The name of the build. Returns: True on success; False on failure. """ files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] extern_generator = shakaBuildHelpers.cygwin_safe_path( os.path.join(shakaBuildHelpers.get_source_base(), 'build', 'generateExterns.js')) output = shakaBuildHelpers.cygwin_safe_path( os.path.join(shakaBuildHelpers.get_source_base(), 'dist', 'shaka-player.' + name + '.externs.js')) cmd_line = ['node', extern_generator, '--output', output] + files if shakaBuildHelpers.execute_get_code(cmd_line) != 0: logging.error('Externs generation failed') return False return True
def compile_demo(rebuild): """Compile the demo application. Args: rebuild: True to rebuild, False to ignore if no changes are detected. Returns: True on success, False on failure. """ logging.info('Compiling the demo app...') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set(get('demo') + get('externs')) - set(get('demo/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')) # Add in the generated externs, so that the demo compilation knows the # definitions of the library APIs. files.add(os.path.join(base, 'dist', 'shaka-player.compiled.externs.js')) demo_build = Build(files) result_file, result_map = compute_output_files('demo.compiled') # Don't build if we don't have to. if not rebuild and not demo_build.should_build(result_file): return True source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') closure_opts = common_closure_opts + debug_closure_opts closure_opts += [ # Ignore missing goog.require since we assume the whole library is # already included. '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..', '-D', 'COMPILED=true', ] if not demo_build.build_raw(closure_opts): return False demo_build.add_source_map(result_file, result_map) return True
def compile_receiver(rebuild, is_debug): """Compile the cast receiver application. Args: rebuild: 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') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set( get('demo/common') + get('demo/cast_receiver') + get('externs')) # Add in the generated externs, so that the receiver compilation knows the # definitions of the library APIs. extern_name = ('shaka-player.compiled.debug.externs.js' if is_debug else 'shaka-player.compiled.externs.js') files.add(os.path.join(base, 'dist', extern_name)) receiver_build = Build(files) name = 'receiver.compiled' + ('.debug' if is_debug else '') result_file, result_map = compute_output_files(name) # Don't build if we don't have to. if not rebuild and not receiver_build.should_build(result_file): return True source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') closure_opts = common_closure_opts + debug_closure_opts closure_opts += [ # Ignore missing goog.require since we assume the whole library is # already included. '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..', '-D', 'COMPILED=true', ] if not receiver_build.build_raw(closure_opts): return False receiver_build.add_source_map(result_file, result_map) return True
def compile_demo(rebuild, is_debug): """Compile the demo application. Args: rebuild: 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') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set(get('demo') + get('externs')) - set(get('demo/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')) # Add in the generated externs, so that the demo compilation knows the # definitions of the library APIs. extern_name = ('shaka-player.compiled.debug.externs.js' if is_debug else 'shaka-player.compiled.externs.js') files.add(os.path.join(base, 'dist', extern_name)) demo_build = Build(files) name = 'demo.compiled' + ('.debug' if is_debug else '') result_file, result_map = compute_output_files(name) # Don't build if we don't have to. if not rebuild and not demo_build.should_build(result_file): return True source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') closure_opts = common_closure_opts + debug_closure_opts closure_opts += [ # Ignore missing goog.require since we assume the whole library is # already included. '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..', '-D', 'COMPILED=true', ] if not demo_build.build_raw(closure_opts): return False demo_build.add_source_map(result_file, result_map) return True
def compile_receiver(rebuild, is_debug): """Compile the cast receiver application. Args: rebuild: 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') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set(get('demo/common') + get('demo/cast_receiver') + get('externs')) # Add in the generated externs, so that the receiver compilation knows the # definitions of the library APIs. extern_name = ('shaka-player.compiled.debug.externs.js' if is_debug else 'shaka-player.compiled.externs.js') files.add(os.path.join(base, 'dist', extern_name)) receiver_build = Build(files) name = 'receiver.compiled' + ('.debug' if is_debug else '') result_file, result_map = compute_output_files(name) # Don't build if we don't have to. if not rebuild and not receiver_build.should_build(result_file): return True source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') closure_opts = common_closure_opts + debug_closure_opts closure_opts += [ # Ignore missing goog.require since we assume the whole library is # already included. '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..', '-D', 'COMPILED=true', ] if not receiver_build.build_raw(closure_opts): return False receiver_build.add_source_map(result_file, result_map) return True
def check_tests(): """Runs an extra compile pass over the test code to check for type errors. Returns: True on success, False on failure. """ print 'Checking the tests for type errors...' match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = (get('lib') + get('externs') + get('test') + get('demo') + get('third_party', 'closure')) test_build = build.Build(set(files)) # Ignore missing goog.require since we assume the whole library is # already included. opts = [ '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--checks-only', '-O', 'SIMPLE' ] return test_build.build_raw(opts, is_debug=True)
def process(text, options): """Decodes a JSON string containing source map data. Args: text: A JSON string containing source map data. options: An object containing the command-line options. """ # The spec allows a map file to start with )]} to prevent javascript from # including it. if text.startswith(')]}\'\n') or text.startswith(')]}\n'): _, text = text.split('\n', 1) # Decode the JSON data and get the parts we need. data = json.loads(text) # Paths are relative to the output directory. base = os.path.join(shakaBuildHelpers.get_source_base(), 'dist') with open(os.path.join(base, data['file']), 'r') as f: file_lines = f.readlines() names = data['names'] mappings = data['mappings'] tokens = decode_mappings(mappings, names) sizes = process_sizes(tokens, file_lines) # Print out one of the results. if options.all_tokens: print_tokens(tokens, file_lines, sizes) elif options.function_sizes: print_sizes(sizes) elif options.function_deps or options.class_deps: temp = process_deps(tokens, file_lines, options.class_deps) print_deps(temp, options.dot_format)
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
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', '--jscomp_off=strictMissingRequire', '-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 check_tests(_): """Runs an extra compile pass over the test code to check for type errors. Returns: True on success, False on failure. """ logging.info('Checking the tests for type errors...') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set(get('lib') + get('externs') + get('test') + get('third_party', 'closure')) files.add(os.path.join(base, 'demo', 'common', 'assets.js')) test_build = build.Build(files) closure_opts = build.common_closure_opts + build.common_closure_defines closure_opts += build.debug_closure_opts + build.debug_closure_defines # Ignore missing goog.require since we assume the whole library is # already included. closure_opts += [ '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--checks-only', '-O', 'SIMPLE' ] return test_build.build_raw(closure_opts)
def add_wrapper(self): """Prepares an output wrapper and returns a list of command line arguments for Closure Compiler to use it.""" # Load the wrapper and use Closure to strip whitespace and comments. # This requires %output% in the template to be protected, so Closure doesn't # fail to parse it. base = shakaBuildHelpers.cygwin_safe_path( shakaBuildHelpers.get_source_base()) wrapper_input_path = '%s/build/wrapper.template.js' % base wrapper_output_path = '%s/dist/wrapper.js' % base with open(wrapper_input_path, 'rb') as f: wrapper_code = f.read().decode('utf8').replace( '%output%', '"%output%"') jar = self._get_closure_jar_path() cmd_line = ['java', '-jar', jar, '-O', 'WHITESPACE_ONLY'] proc = shakaBuildHelpers.execute_subprocess(cmd_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stripped_wrapper_code = proc.communicate( wrapper_code.encode('utf8'))[0] if proc.returncode != 0: raise RuntimeError('Failed to strip whitespace from wrapper!') with open(wrapper_output_path, 'wb') as f: code = stripped_wrapper_code.decode('utf8') f.write(code.replace('"%output%"', '%output%').encode('utf8')) return ['--output_wrapper_file=%s' % wrapper_output_path]
def check_tests(): """Runs an extra compile pass over the test code to check for type errors. Returns: True on success, False on failure. """ logging.info('Checking the tests for type errors...') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = set( get('lib') + get('externs') + get('test') + get('third_party', 'closure')) files.add(os.path.join(base, 'demo', 'common', 'assets.js')) test_build = build.Build(files) closure_opts = build.common_closure_opts + build.common_closure_defines closure_opts += build.debug_closure_opts + build.debug_closure_defines # Ignore missing goog.require since we assume the whole library is # already included. closure_opts += [ '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--checks-only', '-O', 'SIMPLE' ] return test_build.build_raw(closure_opts)
def build_raw(self, extra_opts, is_debug): """Builds the files in |self.include| using the given extra Closure options. Args: extra_opts: An array of extra options to give to Closure. is_debug: True to compile for debugging, false for release. Returns: True on success; False on failure. """ jar = os.path.join(shakaBuildHelpers.get_source_base(), 'third_party', 'closure', 'compiler.jar') jar = shakaBuildHelpers.cygwin_safe_path(jar) files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] files.sort() if is_debug: closure_opts = common_closure_opts + debug_closure_opts else: closure_opts = common_closure_opts + release_closure_opts cmd_line = ['java', '-jar', jar] + closure_opts + extra_opts + files if shakaBuildHelpers.execute_get_code(cmd_line) != 0: logging.error('Build failed') return False return True
def check_complete(_): """Checks whether the 'complete' build references every file. This is used by the build script to ensure that every file is included in at least one build type. Returns: True on success, False on failure. """ logging.info('Checking that the build files are complete...') complete = build.Build() # Normally we don't need to include @core, but because we look at the build # object directly, we need to include it here. When using main(), it will # call addCore which will ensure core is included. if not complete.parse_build(['+@complete', '+@core'], os.getcwd()): logging.error('Error parsing complete build') return False match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() all_files = shakaBuildHelpers.get_all_files(os.path.join(base, 'lib'), match) missing_files = set(all_files) - complete.include if missing_files: logging.error('There are files missing from the complete build:') for missing in missing_files: # Convert to a path relative to source base. logging.error(' ' + os.path.relpath(missing, base)) return False return True
def check_complete(_): """Checks whether the 'complete' build references every file. This is used by the build script to ensure that every file is included in at least one build type. Returns: True on success, False on failure. """ logging.info('Checking that the build files are complete...') complete_build = complete_build_files() if not complete_build: return False match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() all_files = set() all_files.update( shakaBuildHelpers.get_all_files(os.path.join(base, 'lib'), match)) all_files.update( shakaBuildHelpers.get_all_files(os.path.join(base, 'ui'), match)) missing_files = all_files - complete_build if missing_files: logging.error('There are files missing from the complete build:') for missing in missing_files: # Convert to a path relative to source base. logging.error(' ' + os.path.relpath(missing, base)) return False return True
def compute_output_files(base_name): source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') prefix = shakaBuildHelpers.cygwin_safe_path( os.path.join(source_base, 'dist', base_name)) js_path = prefix + '.js' map_path = prefix + '.map' return js_path, map_path
def compute_output_files(base_name): source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') prefix = shakaBuildHelpers.cygwin_safe_path( os.path.join(source_base, 'dist', base_name)) js_path = prefix + '.js' map_path = prefix + '.map' return js_path, map_path
def main(_): """Generates the uncompiled dependencies files.""" # Update node modules if needed. if not shakaBuildHelpers.update_node_modules(): return 1 logging.info('Generating Closure dependencies...') # Make the dist/ folder, ignore errors. base = shakaBuildHelpers.get_source_base() try: os.mkdir(os.path.join(base, 'dist')) except OSError: pass os.chdir(base) deps_writer = os.path.join('node_modules', 'google-closure-library', 'closure', 'bin', 'build', 'depswriter.py') try: cmd_line = [sys.executable or 'python', deps_writer] + deps_args deps = shakaBuildHelpers.execute_get_output(cmd_line) with open(os.path.join(base, 'dist', 'deps.js'), 'wb') as f: f.write(deps) return 0 except subprocess.CalledProcessError as e: return e.returncode
def player_version(): """Gets the version of the library from player.js.""" path = os.path.join(shakaBuildHelpers.get_source_base(), 'lib', 'player.js') with open(path, 'r') as f: match = re.search(r'shaka\.Player\.version = \'(.*)\'', f.read()) return match.group(1) if match else ''
def CreateParser(): """Create the argument parser for this application.""" base = shakaBuildHelpers.get_source_base() parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--locales', type=str, nargs='+', default=DEFAULT_LOCALES, help='The list of locales to compile in (default %(default)r)') parser.add_argument( '--source', type=str, default=os.path.join(base, 'ui', 'locales'), help='The folder path for JSON inputs') parser.add_argument( '--output', type=str, default=os.path.join(base, 'dist', 'locales.js'), help='The file path for JavaScript output') parser.add_argument( '--class-name', type=str, default='shaka.ui.Locales', help='The fully qualified class name for the JavaScript output') return parser
def build_raw(self, extra_opts, is_debug): """Builds the files in |self.include| using the given extra Closure options. Args: extra_opts: An array of extra options to give to Closure. is_debug: True to compile for debugging, false for release. Returns: True on success; False on failure. """ jar = os.path.join(shakaBuildHelpers.get_source_base(), 'third_party', 'closure', 'compiler.jar') jar = shakaBuildHelpers.cygwin_safe_path(jar) files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] files.sort() if is_debug: closure_opts = common_closure_opts + debug_closure_opts else: closure_opts = common_closure_opts + release_closure_opts cmd_line = ['java', '-jar', jar] + closure_opts + extra_opts + files if shakaBuildHelpers.execute_get_code(cmd_line) != 0: logging.error('Build failed') return False return True
def process(text, options): """Decodes a JSON string containing source map data. Args: text: A JSON string containing source map data. options: An object containing the command-line options. """ # The spec allows a map file to start with )]} to prevent javascript from # including it. if text.startswith(')]}\'\n') or text.startswith(')]}\n'): _, text = text.split('\n', 1) # Decode the JSON data and get the parts we need. data = json.loads(text) # Paths are relative to the output directory. base = os.path.join(shakaBuildHelpers.get_source_base(), 'dist') with shakaBuildHelpers.open_file(os.path.join(base, data['file']), 'r') as f: file_lines = f.readlines() names = data['names'] mappings = data['mappings'] tokens = decode_mappings(mappings, names) sizes = process_sizes(tokens, file_lines) # Print out one of the results. if options.all_tokens: print_tokens(tokens, file_lines, sizes) elif options.function_sizes: print_sizes(sizes) elif options.function_deps or options.class_deps: temp = process_deps(tokens, file_lines, options.class_deps) print_deps(temp, options.dot_format)
def build_raw(self, extra_opts, is_debug): """Builds the files in |self.include| using the given extra Closure options. Args: extra_opts: An array of extra options to give to Closure. is_debug: True to compile for debugging, false for release. Returns: True on success; False on failure. """ jar = os.path.join(shakaBuildHelpers.get_source_base(), 'third_party', 'closure', 'compiler.jar') jar = shakaBuildHelpers.cygwin_safe_path(jar) files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] files.sort() try: if is_debug: closure_opts = common_closure_opts + debug_closure_opts else: closure_opts = common_closure_opts + release_closure_opts cmd_line = ['java', '-jar', jar] + closure_opts + extra_opts + files shakaBuildHelpers.print_cmd_line(cmd_line) subprocess.check_call(cmd_line) return True except subprocess.CalledProcessError: print >> sys.stderr, 'Build failed' return False
def check_complete(): """Checks whether the 'complete' build references every file. This is used by the build script to ensure that every file is included in at least one build type. Returns: True on success, False on failure. """ logging.info('Checking that the build files are complete...') complete = build.Build() # Normally we don't need to include @core, but because we look at the build # object directly, we need to include it here. When using main(), it will # call addCore which will ensure core is included. if not complete.parse_build(['+@complete', '+@core'], os.getcwd()): logging.error('Error parsing complete build') return False match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() all_files = shakaBuildHelpers.get_all_files(os.path.join(base, 'lib'), match) missing_files = set(all_files) - complete.include if missing_files: logging.error('There are files missing from the complete build:') for missing in missing_files: # Convert to a path relative to source base. logging.error(' ' + os.path.relpath(missing, base)) return False return True
def get_lint_files(): """Returns the absolute paths to all the files to run the linter over.""" match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(arg): return shakaBuildHelpers.get_all_files(os.path.join(base, arg), match) return get('test') + get('lib') + get('externs') + get('demo')
def CreateParser(): """Create the argument parser for this application.""" base = shakaBuildHelpers.get_source_base() parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--locales', type=str, nargs='+', default=DEFAULT_LOCALES, help='The list of locales to compile in (default %(default)r)') parser.add_argument( '--source', type=str, default=os.path.join(base, 'ui', 'locales'), help='The folder path for JSON inputs') parser.add_argument( '--output', type=str, default=os.path.join(base, 'dist', 'locales.js'), help='The file path for JavaScript output') parser.add_argument( '--class-name', type=str, default='shaka.ui.Locales', help='The fully qualified class name for the JavaScript output') return parser
def build_library(self, name, rebuild, is_debug): """Builds Shaka Player using the files in |self.include|. Args: name: The name of the build. rebuild: 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. """ self.add_core() # In the build files, we use '/' in the paths, however Windows uses '\'. # Although Windows supports both, the source mapping will not work. So # use Linux-style paths for arguments. source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') if is_debug: name += '.debug' result_prefix = shakaBuildHelpers.cygwin_safe_path( os.path.join(source_base, 'dist', 'shaka-player.' + name)) result_file = result_prefix + '.js' result_map = result_prefix + '.map' # Detect changes to the library and only build if changes have been made. if not rebuild and os.path.isfile(result_file): build_time = os.path.getmtime(result_file) complete_build = Build() if complete_build.parse_build(['+@complete'], os.getcwd()): complete_build.add_core() # Get a list of files modified since the build file was. edited_files = [ f for f in complete_build.include if os.path.getmtime(f) > build_time ] if not edited_files: logging.warning( 'No changes detected, not building. Use --force ' 'to override.') return True opts = [ '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..' ] if not self.build_raw(opts, is_debug): return False # Add a special source-mapping comment so that Chrome and Firefox can map # line and character numbers from the compiled library back to the original # source locations. with open(result_file, 'a') as f: f.write('//# sourceMappingURL=shaka-player.' + name + '.map') if not self.generate_externs(name): return False return True
def player_version(): """Gets the version of the library from player.js.""" path = os.path.join(shakaBuildHelpers.get_source_base(), 'lib', 'player.js') with open(path, 'r') as f: match = re.search(r'goog\.define\(\'GIT_VERSION\', \'(.*)\'\)', f.read()) return match.group(1) if match else ''
def main(args): base = shakaBuildHelpers.get_source_base() screenshotsFolder = os.path.join(base, 'test', 'test', 'assets', 'screenshots') pixelsChangedTool = os.path.join(base, 'build', 'pixelsChanged.js') for platform in os.listdir(screenshotsFolder): # This is a subfolder with actual screenshots. platformFolder = os.path.join(screenshotsFolder, platform) if not os.path.isdir(platformFolder): # Skip hidden files like .gitignore and non-folders continue for child in os.listdir(platformFolder): # If any args were specified, use them to filter. Either the platform or # base of the filename must match the filter. if args and not platform in args and not child.split( '.')[0] in args: continue fullPath = os.path.join(platformFolder, child) # If this has the "-new" suffix, it was just written by the layout tests. # Rename it to overwrite the "official" version, which is stored in # git-lfs. if fullPath.endswith('-new'): officialPath = fullPath[:-4] # Finally, check to see if the pixels have changed before updating it. # The png file itself can be slightly different byte-for-byte even when # the image is visibly the same, and the git repo history will carry # every revision forever, getting larger with each change. So we only # want to update the image if the new one is _visibly_ different. For # this, we use the same tools we use to measure screenshot differences # in Karma. if os.path.exists(officialPath): output = shakaBuildHelpers.execute_get_output([ 'node', pixelsChangedTool, officialPath, fullPath, ]) pixelsChanged = float(output) else: # No original? Then everything has changed! pixelsChanged = 1e6 if pixelsChanged == 0: # Nothing changed, so don't update the image. This will keep the git # history from getting bigger for no reason. continue shutil.move(fullPath, officialPath) print('Updated: ' + officialPath) return 0
def main(args): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-d', '--dot-format', action='store_true', help='Prints in DOT format.') parser.add_argument('source_map', nargs='?', default='shaka-player.compiled.map', help='The source map or the name of the build to use.') print_types = parser.add_mutually_exclusive_group(required=True) print_types.add_argument('-c', '--class-deps', action='store_true', help='Prints the class dependencies.') print_types.add_argument('-f', '--function-deps', action='store_true', help='Prints the function dependencies.') print_types.add_argument( '-s', '--function-sizes', action='store_true', help='Prints the function sizes (in number of characters).') print_types.add_argument( '-t', '--all-tokens', action='store_true', help='Prints all tokens in the source map.') options = parser.parse_args(args) # Verify arguments are correct. if (options.dot_format and not options.function_deps and not options.class_deps): parser.error('--dot-format only valid with --function-deps or ' '--class-deps.') # Try to find the file name = options.source_map if not os.path.isfile(name): # Get the source code base directory base = shakaBuildHelpers.get_source_base() # Supports the following searches: # * File name given, map in dist/ # * Type given, map in working directory # * Type given, map in dist/ if os.path.isfile(os.path.join(base, 'dist', name)): name = os.path.join(base, 'dist', name) elif os.path.isfile( os.path.join('shaka-player.' + name + '.debug.map')): name = os.path.join('shaka-player.' + name + '.debug.map') elif os.path.isfile( os.path.join(base, 'dist', 'shaka-player.' + name + '.debug.map')): name = os.path.join(base, 'dist', 'shaka-player.' + name + '.debug.map') else: logging.error('"%s" not found; build Shaka first.', name) return 1 with open(name, 'r') as f: process(f.read(), options) return 0
def build_library(self, name, rebuild): """Builds Shaka Player using the files in |self.include|. Args: name: The name of the build. rebuild: True to rebuild, False to ignore if no changes are detected. Returns: True on success; False on failure. """ self.add_core() # In the build files, we use '/' in the paths, however Windows uses '\'. # Although Windows supports both, the source mapping will not work. So # use Linux-style paths for arguments. source_base = shakaBuildHelpers.get_source_base().replace("\\", "/") result_prefix = shakaBuildHelpers.cygwin_safe_path(os.path.join(source_base, "dist", "shaka-player." + name)) result_file = result_prefix + ".js" result_debug = result_prefix + ".debug.js" result_map = result_prefix + ".debug.map" # Detect changes to the library and only build if changes have been made. if not rebuild and os.path.isfile(result_file): build_time = os.path.getmtime(result_file) complete_build = Build() if complete_build.parse_build(["+@complete"], os.getcwd()): complete_build.add_core() # Get a list of files modified since the build file was. edited_files = [f for f in complete_build.include if os.path.getmtime(f) > build_time] if not edited_files: print "No changes detected, not building. Use --force to override." return True opts = [ "--create_source_map", result_map, "--js_output_file", result_debug, "--source_map_location_mapping", source_base + "|..", "--dependency_mode=LOOSE", "--js=shaka-player.uncompiled.js", ] if not self.build_raw(opts): return False shutil.copyfile(result_debug, result_file) # Add a special source-mapping comment so that Chrome and Firefox can map # line and character numbers from the compiled library back to the original # source locations. with open(result_debug, "a") as f: f.write("//# sourceMappingURL=shaka-player." + name + ".debug.map") return True
def build_library(self, name, locales, force, is_debug): """Builds Shaka Player using the files in |self.include|. Args: name: The name of the build. locales: A list of strings of locale identifiers. 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. """ self.add_closure() if not self.add_core(): return False if self.has_ui(): self.generate_localizations(locales, force) if is_debug: name += '.debug' build_name = 'shaka-player.' + name closure = compiler.ClosureCompiler(self.include, build_name) closure_opts = common_closure_opts + common_closure_defines if is_debug: closure_opts += debug_closure_opts + debug_closure_defines else: closure_opts += release_closure_opts + release_closure_defines if not closure.compile(closure_opts, force): return False # Don't pass local node modules to the extern generator. But don't simply # exclude the string 'node_modules', either, since Shaka Player could be # rebuilt after installing it as a node module. node_modules_path = os.path.join(shakaBuildHelpers.get_source_base(), 'node_modules') local_include = set( [f for f in self.include if node_modules_path not in f]) extern_generator = compiler.ExternGenerator(local_include, build_name) if not extern_generator.generate(force): return False generated_externs = [extern_generator.output] shaka_externs = shakaBuildHelpers.get_all_js_files('externs') if self.has_ui(): shaka_externs += shakaBuildHelpers.get_all_js_files('ui/externs') ts_def_generator = compiler.TsDefGenerator( generated_externs + shaka_externs, build_name) if not ts_def_generator.generate(force): return False return True
def main(args): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-d', '--dot-format', action='store_true', help='Prints in DOT format.') parser.add_argument('source_map', nargs='?', default='shaka-player.compiled.map', help='The source map or the name of the build to use.') print_types = parser.add_mutually_exclusive_group(required=True) print_types.add_argument('-c', '--class-deps', action='store_true', help='Prints the class dependencies.') print_types.add_argument('-f', '--function-deps', action='store_true', help='Prints the function dependencies.') print_types.add_argument( '-s', '--function-sizes', action='store_true', help='Prints the function sizes (in number of characters).') print_types.add_argument( '-t', '--all-tokens', action='store_true', help='Prints all tokens in the source map.') options = parser.parse_args(args) # Verify arguments are correct. if (options.dot_format and not options.function_deps and not options.class_deps): parser.error('--dot-format only valid with --function-deps or ' '--class-deps.') # Try to find the file name = options.source_map if not os.path.isfile(name): # Get the source code base directory base = shakaBuildHelpers.get_source_base() # Supports the following searches: # * File name given, map in dist/ # * Type given, map in working directory # * Type given, map in dist/ if os.path.isfile(os.path.join(base, 'dist', name)): name = os.path.join(base, 'dist', name) elif os.path.isfile( os.path.join('shaka-player.' + name + '.debug.map')): name = os.path.join('shaka-player.' + name + '.debug.map') elif os.path.isfile( os.path.join(base, 'dist', 'shaka-player.' + name + '.debug.map')): name = os.path.join(base, 'dist', 'shaka-player.' + name + '.debug.map') else: logging.error('"%s" not found; build Shaka first.', name) return 1 with open(name, 'r') as f: process(f.read(), options) return 0
def add_closure(self): """Adds the closure library and externs.""" # Add externs and closure dependencies. source_base = shakaBuildHelpers.get_source_base() match = re.compile(r'.*\.js$') self.include |= set( shakaBuildHelpers.get_all_files( os.path.join(source_base, 'externs'), match) + shakaBuildHelpers.get_all_files( os.path.join(source_base, 'third_party', 'closure'), match))
def compile_less(path_name, main_file_name, parsed_args): match = re.compile(r'.*\.less$') base = shakaBuildHelpers.get_source_base() main_less_src = os.path.join(base, path_name, main_file_name + '.less') all_less_srcs = shakaBuildHelpers.get_all_files( os.path.join(base, path_name), match) output = os.path.join(base, 'dist', main_file_name + '.css') less = compiler.Less(main_less_src, all_less_srcs, output) return less.compile(parsed_args.force)
def compile_less(path_name, main_file_name, parsed_args): match = re.compile(r'.*\.less$') base = shakaBuildHelpers.get_source_base() main_less_src = os.path.join(base, path_name, main_file_name + '.less') all_less_srcs = shakaBuildHelpers.get_all_files( os.path.join(base, path_name), match) output = os.path.join(base, 'dist', main_file_name + '.css') less = compiler.Less(main_less_src, all_less_srcs, output) return less.compile(parsed_args.force)
def add_closure(self): """Adds the closure library and externs.""" # Add externs and closure dependencies. source_base = shakaBuildHelpers.get_source_base() match = re.compile(r'.*\.js$') self.include |= set( shakaBuildHelpers.get_all_files( os.path.join(source_base, 'externs'), match) + shakaBuildHelpers.get_all_files( os.path.join(source_base, 'third_party', 'closure'), match))
def check_js_lint(args): """Runs the JavaScript linter.""" # TODO: things not enforced: property doc requirements logging.info('Linting JavaScript...') base = shakaBuildHelpers.get_source_base() config_path = os.path.join(base, '.eslintrc.js') linter = compiler.Linter(get_lint_files(), config_path) return linter.lint(fix=args.fix, force=args.force)
def check_js_lint(args): """Runs the JavaScript linter.""" # TODO: things not enforced: property doc requirements logging.info('Linting JavaScript...') base = shakaBuildHelpers.get_source_base() config_path = os.path.join(base, '.eslintrc.js') linter = compiler.Linter(get_lint_files(), config_path) return linter.lint(fix=args.fix, force=args.force)
def check_html_lint(args): """Runs the HTML linter.""" logging.info('Linting HTML...') base = shakaBuildHelpers.get_source_base() files = ['index.html', os.path.join('demo', 'index.html'), 'support.html'] file_paths = [os.path.join(base, x) for x in files] config_path = os.path.join(base, '.htmlhintrc') htmllinter = compiler.HtmlLinter(file_paths, config_path) return htmllinter.lint(force=args.force)
def build_library(self, name, rebuild, is_debug): """Builds Shaka Player using the files in |self.include|. Args: name: The name of the build. rebuild: 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. """ self.add_core() # In the build files, we use '/' in the paths, however Windows uses '\'. # Although Windows supports both, the source mapping will not work. So # use Linux-style paths for arguments. source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') if is_debug: name += '.debug' result_prefix = shakaBuildHelpers.cygwin_safe_path( os.path.join(source_base, 'dist', 'shaka-player.' + name)) result_file = result_prefix + '.js' result_map = result_prefix + '.map' # Detect changes to the library and only build if changes have been made. if not rebuild and os.path.isfile(result_file): build_time = os.path.getmtime(result_file) complete_build = Build() if complete_build.parse_build(['+@complete'], os.getcwd()): complete_build.add_core() # Get a list of files modified since the build file was. edited_files = [f for f in complete_build.include if os.path.getmtime(f) > build_time] if not edited_files: logging.warning('No changes detected, not building. Use --force ' 'to override.') return True opts = ['--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..'] if not self.build_raw(opts, is_debug): return False # Add a special source-mapping comment so that Chrome and Firefox can map # line and character numbers from the compiled library back to the original # source locations. with open(result_file, 'a') as f: f.write('//# sourceMappingURL=shaka-player.' + name + '.map') if not self.generate_externs(name): return False return True
def build_docs(_): """Builds the source code documentation.""" logging.info('Building the docs...') base = shakaBuildHelpers.get_source_base() shutil.rmtree(os.path.join(base, 'docs', 'api'), ignore_errors=True) os.chdir(base) jsdoc = shakaBuildHelpers.get_node_binary('jsdoc') cmd_line = jsdoc + ['-c', 'docs/jsdoc.conf.json'] return shakaBuildHelpers.execute_get_code(cmd_line)
def check_html_lint(args): """Runs the HTML linter.""" logging.info('Linting HTML...') base = shakaBuildHelpers.get_source_base() files = ['index.html', os.path.join('demo', 'index.html'), 'support.html'] file_paths = [os.path.join(base, x) for x in files] config_path = os.path.join(base, '.htmlhintrc') htmllinter = compiler.HtmlLinter(file_paths, config_path) return htmllinter.lint(force=args.force)
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') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*path_components): return shakaBuildHelpers.get_all_files( os.path.join(base, *path_components), match) files = set( get('demo', 'common') + get('demo', 'cast_receiver') + get('externs') + get('ui', 'externs') + get('lib', 'debug') + get('third_party', 'closure')) # 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)) 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', '--jscomp_off=strictMissingRequire', '-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 check_html_lint(_): """Runs the HTML linter over the HTML files. Returns: True on success, False on failure. """ logging.info('Running htmlhint...') htmlhint = shakaBuildHelpers.get_node_binary('htmlhint') base = shakaBuildHelpers.get_source_base() files = ['index.html', 'demo/index.html', 'support.html'] file_paths = [os.path.join(base, x) for x in files] config_path = os.path.join(base, '.htmlhintrc') cmd_line = htmlhint + ['--config=' + config_path] + file_paths return shakaBuildHelpers.execute_get_code(cmd_line) == 0
def check_closure_compiler_linter(_): """Runs the Closure Compiler linter.""" logging.info('Running Closure Compiler linter...') base = shakaBuildHelpers.get_source_base() closure_linter_path = os.path.join(base, 'third_party', 'closure', 'linter.jar') cmd_line = ['java', '-jar', closure_linter_path] + get_lint_files() # The compiler's linter tool doesn't return a status code (as of v20171203) # and has no options. Instead of checking status, success is no output. output = shakaBuildHelpers.execute_get_output(cmd_line) if output != '': print output return False return True
def generate_externs(self, name): """Generates externs for the files in |self.include|. Args: name: The name of the build. Returns: True on success; False on failure. """ files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include] extern_generator = shakaBuildHelpers.cygwin_safe_path(os.path.join( shakaBuildHelpers.get_source_base(), 'build', 'generateExterns.js')) output = shakaBuildHelpers.cygwin_safe_path(os.path.join( shakaBuildHelpers.get_source_base(), 'dist', 'shaka-player.' + name + '.externs.js')) cmd_line = ['node', extern_generator, '--output', output] + files if shakaBuildHelpers.execute_get_code(cmd_line) != 0: logging.error('Externs generation failed') return False return True
def build_docs(_): """Builds the source code documentation.""" print 'Building the docs...' base = shakaBuildHelpers.get_source_base() shutil.rmtree(os.path.join(base, 'docs', 'api'), ignore_errors=True) os.chdir(base) if shakaBuildHelpers.is_windows() or shakaBuildHelpers.is_cygwin(): # Windows has a different command name. The Unix version does not seem to # work on Cygwin, but the windows one does. jsdoc = os.path.join('third_party', 'jsdoc', 'jsdoc.cmd') else: jsdoc = os.path.join('third_party', 'jsdoc', 'jsdoc') cmd_line = [jsdoc, '-c', 'docs/jsdoc.conf.json', '-R', 'docs/api-mainpage.md'] return shakaBuildHelpers.execute_get_code(cmd_line)
def check_lint(): """Runs the linter over the library files.""" print 'Running Closure linter...' jsdoc3_tags = ','.join([ 'static', 'summary', 'namespace', 'event', 'description', 'property', 'fires', 'listens', 'example', 'exportDoc']) args = ['--nobeep', '--custom_jsdoc_tags', jsdoc3_tags, '--strict'] base = shakaBuildHelpers.get_source_base() cmd = os.path.join(base, 'third_party', 'gjslint', 'gjslint') # Even though this is python, don't import and execute since gjslint expects # command-line arguments using argv. Have to explicitly execute python so # it works on Windows. cmd_line = ['python', cmd] + args + get_lint_files() shakaBuildHelpers.print_cmd_line(cmd_line) return subprocess.call(cmd_line) == 0
def add_core(self): """Adds the core library.""" # Add externs and closure dependencies. source_base = shakaBuildHelpers.get_source_base() match = re.compile(r".*\.js$") self.include |= set( shakaBuildHelpers.get_all_files(os.path.join(source_base, "externs"), match) + shakaBuildHelpers.get_all_files(os.path.join(source_base, "third_party", "closure"), match) ) # Check that there are no files in 'core' that are removed core_build = Build() core_build.parse_build(["+@core"], os.getcwd()) core_files = core_build.include if self.exclude & core_files: print >> sys.stderr, "Cannot exclude files from core" self.include |= core_files
def check_externs(_): """Runs an extra compile pass over the generated externs to ensure that they are usable. Returns: True on success, False on failure. """ logging.info('Checking the usability of generated externs...') # Create a complete "build" object. externs_build = build.Build() if not externs_build.parse_build(['+@complete'], os.getcwd()): return False externs_build.add_core() # Use it to generate externs for the next check. if not externs_build.generate_externs('check'): return False # Create a custom "build" object, add all manually-written externs, then add # the generated externs we just generated. source_base = shakaBuildHelpers.get_source_base() manual_externs = shakaBuildHelpers.get_all_files( os.path.join(source_base, 'externs'), re.compile(r'.*\.js$')) generated_externs = os.path.join( source_base, 'dist', 'shaka-player.check.externs.js') check_build = build.Build() check_build.include = set(manual_externs) check_build.include.add(generated_externs) # Build with the complete set of externs, but without any application code. # This will help find issues in the generated externs, independent of the app. # Since we have no app, don't use the defines. Unused defines cause a # compilation error. closure_opts = build.common_closure_opts + build.debug_closure_opts + [ '--checks-only', '-O', 'SIMPLE' ] ok = check_build.build_raw(closure_opts) # Clean up the temporary externs we just generated. os.unlink(generated_externs) # Return the success/failure of the build above. return ok
def build_library(self, name, rebuild, is_debug): """Builds Shaka Player using the files in |self.include|. Args: name: The name of the build. rebuild: 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. """ self.add_core() # In the build files, we use '/' in the paths, however Windows uses '\'. # Although Windows supports both, the source mapping will not work. So # use Linux-style paths for arguments. source_base = shakaBuildHelpers.get_source_base().replace('\\', '/') if is_debug: name += '.debug' result_file, result_map = compute_output_files('shaka-player.' + name) # Don't build if we don't have to. if not rebuild and not self.should_build(result_file): return True closure_opts = common_closure_opts + common_closure_defines if is_debug: closure_opts += debug_closure_opts + debug_closure_defines else: closure_opts += release_closure_opts + release_closure_defines closure_opts += [ '--create_source_map', result_map, '--js_output_file', result_file, '--source_map_location_mapping', source_base + '|..' ] if not self.build_raw(closure_opts): return False self.add_source_map(result_file, result_map) if not self.generate_externs(name): return False return True
def add_core(self): """Adds the core library.""" # Add externs and closure dependencies. source_base = shakaBuildHelpers.get_source_base() match = re.compile(r'.*\.js$') self.include |= set( shakaBuildHelpers.get_all_files( os.path.join(source_base, 'externs'), match) + shakaBuildHelpers.get_all_files( os.path.join(source_base, 'third_party', 'closure'), match)) # Check that there are no files in 'core' that are removed core_build = Build() core_build.parse_build(['+@core'], os.getcwd()) core_files = core_build.include if self.exclude & core_files: logging.error('Cannot exclude files from core') self.include |= core_files
def check_html_lint(): """Runs the HTML linter over the HTML files. Skipped if htmlhint is not available. Returns: True on success, False on failure. """ htmlhint_path = shakaBuildHelpers.get_node_binary_path('htmlhint') if not os.path.exists(htmlhint_path): return True print 'Running htmlhint...' base = shakaBuildHelpers.get_source_base() files = ['index.html', 'demo/index.html', 'support.html'] file_paths = [os.path.join(base, x) for x in files] cmd_line = [htmlhint_path] + file_paths shakaBuildHelpers.print_cmd_line(cmd_line) return subprocess.call(cmd_line) == 0
def check_tests(args): """Runs an extra compile pass over the test code to check for type errors. Returns: True on success, False on failure. """ logging.info('Checking the tests for type errors...') match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*path_components): return shakaBuildHelpers.get_all_files( os.path.join(base, *path_components), match) files = set(get('lib') + get('externs') + get('test') + get('ui') + get('third_party', 'closure') + get('third_party', 'language-mapping-list')) files.add(os.path.join(base, 'demo', 'common', 'asset.js')) files.add(os.path.join(base, 'demo', 'common', 'assets.js')) localizations = compiler.GenerateLocalizations(None) localizations.generate(args.force) files.add(localizations.output) closure_opts = build.common_closure_opts + build.common_closure_defines closure_opts += build.debug_closure_opts + build.debug_closure_defines # Ignore missing goog.require since we assume the whole library is # already included. closure_opts += [ '--jscomp_off=missingRequire', '--jscomp_off=strictMissingRequire', '--checks-only', '-O', 'SIMPLE' ] # Set up a build with the build name of "dummy". With output_compiled_bundle # set to False, the build name is irrelevant, since we won't generate any # compiled output. closure = compiler.ClosureCompiler(files, 'dummy') closure.output_compiled_bundle = False # Instead of creating a compiled bundle, we will touch a timestamp file to # keep track of how recently we've run this check. closure.timestamp_file = os.path.join(base, 'dist', '.testcheckstamp') return closure.compile(closure_opts, args.force)
def check_tests(): """Runs an extra compile pass over the test code to check for type errors. Returns: True on success, False on failure. """ print 'Checking the tests for type errors...' match = re.compile(r'.*\.js$') base = shakaBuildHelpers.get_source_base() def get(*args): return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match) files = (get('lib') + get('externs') + get('test') + get('demo') + get('third_party', 'closure')) test_build = build.Build(set(files)) # Ignore missing goog.require since we assume the whole library is # already included. opts = ['--jscomp_off=missingRequire', '--checks-only', '-O', 'SIMPLE'] return test_build.build_raw(opts)
def main(args): """Builds the source code documentation.""" logging.info('Building the docs...') parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--force', '-f', help='Force the docs to be built, even if no files have changed.', action='store_true') parsed_args = parser.parse_args(args) base = shakaBuildHelpers.get_source_base() config_path = os.path.join(base, 'docs', 'jsdoc.conf.json') jsdoc = compiler.Jsdoc(config_path) if not jsdoc.build(parsed_args.force): return 1 return 0