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 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 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 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 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) make_deps = shakaBuildHelpers.get_node_binary( 'google-closure-deps', 'closure-make-deps') try: cmd_line = make_deps + [ # Folders to search for sources using goog.require/goog.provide '-r', 'demo', 'lib', 'ui', 'third_party', # Individual files to add to those '-f', 'dist/locales.js', # The path to the folder containing the Closure library's base.js '--closure-path', 'node_modules/google-closure-library/closure/goog', ] deps = shakaBuildHelpers.execute_get_output(cmd_line) # This command doesn't use exit codes for some stupid reason. # TODO: Remove when https://github.com/google/closure-library/issues/1162 # is resolved and we have upgraded. if len(deps) == 0: return 1 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 gen_deps(_): """Generates the uncompiled dependencies files.""" print '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('third_party', 'closure', 'deps', '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'), 'w') as f: f.write(deps) return 0 except subprocess.CalledProcessError as e: return e.returncode
def gen_deps(_): """Generates the uncompiled dependencies files.""" 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('third_party', 'closure', 'deps', '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'), 'w') as f: f.write(deps) return 0 except subprocess.CalledProcessError as e: return e.returncode
def GenerateTsDefs(inputs, output): """Generates TypeScript defs from Closure externs. Args: inputs: A list of paths to Closure extern files. output: A path to a TypeScript def output file. """ clutz = shakaBuildHelpers.get_node_binary('@teppeis/clutz', 'clutz') command = clutz + [ '--closure_env', 'BROWSER', '--externs', ] + inputs + [ '-o', '-', ] # Get the output of Clutz, then transform it to make it independent of Clutz # and usable directly in TypeScript projects. contents = shakaBuildHelpers.execute_get_output(command) # Remove the prefix clutz puts on all namespaces. contents = contents.replace('\xe0\xb2\xa0_\xe0\xb2\xa0.clutz.', '') # Replace "GlobalObject" (from Clutz) with TypeScript-native "object". contents = re.sub(r'\bGlobalObject\b', 'object', contents) # Remove "Global" from Clutz's Global{Date,Element,Event,EventTarget} and use # their original definitions instead. contents = re.sub(r'\bGlobal(Date|Element|Event|EventTarget)\b', r'\1', contents) # Remove "protected", which appears on some fields, and is only supported on # methods. contents = re.sub(r'^\s*protected ', '', contents, flags=re.MULTILINE) # Clutz really likes EventTargets, so it wants IAdManager to extend it twice. contents = contents.replace('extends EventTarget extends EventTarget', 'extends EventTarget') # Some types allow you to return a Promise or nothing, but the Clutz output of # "Promise | null | undefined" doesn't work in TypeScript. We need to use # "Promise | void" instead. contents = contents.replace('| null | undefined', '| void') # shaka.util.Error extends Error and implements shaka.extern.Error, but this # confuses TypeScript when both are called "Error" in context of the namespace # declaration for "shaka.util". Therefore we need to declare this # "GlobalError" type, which is already referenced by Clutz but never defined. global_error_def = 'declare class GlobalError extends Error {}\n\n' contents = global_error_def + contents # There are some types that implement multiple interfaces, such as IReleasable # and Iteratable. Also, there are tools used inside Google that (for some # reason) want to convert TS defs _BACK_ into Closure Compiler externs. When # that happens, these multiple implementors generate externs with broken # @implements annotations. Since this team can't control that process or # those tools, we need to adjust our TS defs instead. In these particular # cases, thankfully, we can just remove the reference to the IReleasable # interface, which is not needed outside the library. # TODO: This only covers one very specific pattern, and could be brittle. contents = contents.replace('implements shaka.util.IReleasable , ', 'implements ') # Finally, Clutz includes a bunch of basic defs for a browser environment # generated from Closure compiler's builtins. Remove these. sections = re.split(r'\n(?=// Generated from .*)', contents) sections = filter( lambda s: not s.startswith('// Generated from externs.zip'), sections) contents = '\n'.join(sections) + '\n' license_header_path = os.path.join(shakaBuildHelpers.get_source_base(), 'build/license-header') with open(license_header_path, 'r') as f: license_header = f.read() with open(output, 'w') as f: f.write(license_header) f.write('\n') f.write(contents)