Make build files consistent with Google python style guide.

Change-Id: I49d181c4dbe4fe12b73cdc4a5c78b3dcf1319b56
This commit is contained in:
Jacob Trimble
2016-06-15 12:21:31 -07:00
parent 2e86da6995
commit a1449e44dc
9 changed files with 729 additions and 577 deletions
+7 -4
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,13 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import check
"""Builds the dependencies, runs the checks, and compiles the library."""
import build
import check
import gendeps
import shakaBuildHelpers
def main(args):
code = gendeps.genDeps([])
code = gendeps.gen_deps([])
if code != 0:
return code
@@ -36,4 +39,4 @@ def main(args):
return build.main(build_args)
if __name__ == '__main__':
shakaBuildHelpers.runMain(main)
shakaBuildHelpers.run_main(main)
+143 -132
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Creates a build from the given commands. A command is either an addition or
a subtraction. An addition is prefixed with a +; a subtraction is when
prefixed with a -. After the character, there is a name of a file or a @ sign
and the name of a build file.
"""Creates a build from the given commands.
A command is either an addition or a subtraction. An addition is prefixed with
a +; a subtraction is when prefixed with a -. After the character, there is a
name of a file or a @ sign and the name of a build file.
Build files are the files found in build/types. These files are simply a
newline separated list of commands to execute. So if the "+@complete" command
@@ -35,58 +36,64 @@ Examples:
build.py +@complete
build.py +@complete -@networking
build.py --name custom +@manifests +@networking +../my_plugin.js"""
build.py --name custom +@manifests +@networking +../my_plugin.js
"""
import os
import re
import shakaBuildHelpers
import shutil
import subprocess
import sys
import shakaBuildHelpers
closure_opts = [
'--language_in', 'ECMASCRIPT5',
'--language_out', 'ECMASCRIPT3',
'--language_in', 'ECMASCRIPT5',
'--language_out', 'ECMASCRIPT3',
'--jscomp_error=*',
'--jscomp_error=*',
# 'deprecatedAnnotations' controls complains about @expose, but the new
# @nocollapse annotation does not do the same job for properties.
# So since we can't use the new annotations, we have to ignore complaints
# about the old one.
'--jscomp_off=deprecatedAnnotations',
# 'deprecatedAnnotations' controls complains about @expose, but the new
# @nocollapse annotation does not do the same job for properties.
# So since we can't use the new annotations, we have to ignore complaints
# about the old one.
'--jscomp_off=deprecatedAnnotations',
# 'analyzerChecks' complains about countless instances of implicitly nullable
# types, plus a few other issues. Even the closure library doesn't pass
# these checks, and the implicit nullability check in particular is over-
# zealous and unhelpful. So we disable the whole category of
# 'analyzerChecks'.
'--jscomp_off=analyzerChecks',
# 'analyzerChecks' complains about countless instances of implicitly
# nullable types, plus a few other issues. Even the closure library doesn't
# pass these checks, and the implicit nullability check in particular is
# over-zealous and unhelpful. So we disable the whole category of
# 'analyzerChecks'.
'--jscomp_off=analyzerChecks',
'--extra_annotation_name=listens',
'--extra_annotation_name=exportDoc',
'--extra_annotation_name=listens',
'--extra_annotation_name=exportDoc',
'--conformance_configs', '%s/build/conformance.textproto' % \
shakaBuildHelpers.cygwinSafePath(shakaBuildHelpers.getSourceBase()),
'--conformance_configs',
('%s/build/conformance.textproto' %
shakaBuildHelpers.cygwin_safe_path(shakaBuildHelpers.get_source_base())),
'-O', 'ADVANCED',
'--generate_exports',
'--output_wrapper_file=%s/build/wrapper.template.js' % \
shakaBuildHelpers.cygwinSafePath(shakaBuildHelpers.getSourceBase()),
'-O', 'ADVANCED',
'--generate_exports',
('--output_wrapper_file=%s/build/wrapper.template.js' %
shakaBuildHelpers.cygwin_safe_path(shakaBuildHelpers.get_source_base())),
'-D', 'COMPILED=true',
'-D', 'goog.DEBUG=false',
'-D', 'goog.STRICT_MODE_COMPATIBLE=true',
'-D', 'goog.ENABLE_DEBUG_LOADER=false',
'-D', 'goog.asserts.ENABLE_ASSERTS=false',
'-D', 'shaka.log.MAX_LOG_LEVEL=0',
'-D', 'GIT_VERSION="%s"' % shakaBuildHelpers.calculateVersion()
'-D', 'COMPILED=true',
'-D', 'goog.DEBUG=false',
'-D', 'goog.STRICT_MODE_COMPATIBLE=true',
'-D', 'goog.ENABLE_DEBUG_LOADER=false',
'-D', 'goog.asserts.ENABLE_ASSERTS=false',
'-D', 'shaka.log.MAX_LOG_LEVEL=0',
'-D', 'GIT_VERSION="%s"' % shakaBuildHelpers.calculate_version()
]
class Build:
"""Defines a build that has been parsed from a build file. This has
exclude files even though it will not be used at the top-level. This allows
combining builds. A file will only exist in at most one set.
class Build(object):
"""Defines a build that has been parsed from a build file.
This has exclude files even though it will not be used at the top-level. This
allows combining builds. A file will only exist in at most one set.
Members:
include - A set of files to include.
@@ -97,65 +104,67 @@ class Build:
self.include = include or set()
self.exclude = exclude or set()
def _getBuildFilePath(self, name, root):
"""Gets the full path to a build file, if it exists. Returns None if not.
def _get_build_file_path(self, name, root):
"""Gets the full path to a build file, if it exists.
Arguments:
name - The string name to check.
Args:
name: The string name to check.
root: The full path to the base directory.
Returns:
The full path to the build file.
The full path to the build file, or None if not found.
"""
sourceBase = shakaBuildHelpers.getSourceBase()
localPath = os.path.join(root, name)
buildPath = os.path.join(sourceBase, 'build', 'types', name)
if (os.path.isfile(localPath) and os.path.isfile(buildPath)
and localPath != buildPath):
source_base = shakaBuildHelpers.get_source_base()
local_path = os.path.join(root, name)
build_path = os.path.join(source_base, 'build', 'types', name)
if (os.path.isfile(local_path) and os.path.isfile(build_path)
and local_path != build_path):
print >> sys.stderr, 'Build file "%s" is ambiguous' % name
return None
elif os.path.isfile(localPath):
return localPath
elif os.path.isfile(buildPath):
return buildPath
elif os.path.isfile(local_path):
return local_path
elif os.path.isfile(build_path):
return build_path
else:
print >> sys.stderr, 'Build file not found: ' + name
return None
def _reverse(self):
def _combine(self, other):
include_all = self.include | other.include
exclude_all = self.exclude | other.exclude
self.include = include_all - exclude_all
self.exclude = exclude_all - include_all
def reverse(self):
return Build(self.exclude, self.include)
def _combine(self, other):
includeAll = self.include | other.include
excludeAll = self.exclude | other.exclude
self.include = includeAll - excludeAll
self.exclude = excludeAll - includeAll
def _addCore(self):
def add_core(self):
"""Adds the core library."""
# Add externs and closure dependencies.
sourceBase = shakaBuildHelpers.getSourceBase()
source_base = shakaBuildHelpers.get_source_base()
match = re.compile(r'.*\.js$')
self.include = self.include | set(
shakaBuildHelpers.getAllFiles(
os.path.join(sourceBase, 'externs'), match) +
shakaBuildHelpers.getAllFiles(
os.path.join(sourceBase, 'third_party', 'closure'), match))
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
coreBuild = Build()
coreBuild.parseBuild(['+@core'], os.getcwd())
coreFiles = coreBuild.include
if len(self.exclude & coreFiles) > 0:
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 = self.include | coreFiles
self.include |= core_files
def parseBuild(self, lines, root):
"""Parses a Build object from the given lines of commands. This will
recursively read and parse builds.
def parse_build(self, lines, root):
"""Parses a Build object from the given lines of commands.
Arguments:
lines - An array of strings defining commands.
root - The full path to the base directory.
This will recursively read and parse builds.
Args:
lines: An array of strings defining commands.
root: The full path to the base directory.
Returns:
True on success, False otherwise.
@@ -172,11 +181,11 @@ class Build:
if not line:
continue
isNeg = False
if line[0] == '+':
is_neg = False
line = line[1:].strip()
elif line[0] == '-':
isNeg = True
is_neg = True
line = line[1:].strip()
else:
print >> sys.stderr, 'Operation (+/-) required'
@@ -185,21 +194,21 @@ class Build:
if line[0] == '@':
line = line[1:].strip()
buildPath = self._getBuildFilePath(line, root)
if not buildPath:
build_path = self._get_build_file_path(line, root)
if not build_path:
return False
lines = open(buildPath).readlines()
subRoot = os.path.dirname(buildPath)
lines = open(build_path).readlines()
sub_root = os.path.dirname(build_path)
# If this is a build file, then recurse and combine the builds.
subBuild = Build()
if not subBuild.parseBuild(lines, subRoot):
sub_build = Build()
if not sub_build.parse_build(lines, sub_root):
return False
if isNeg:
self._combine(subBuild._reverse())
if is_neg:
self._combine(sub_build.reverse())
else:
self._combine(subBuild)
self._combine(sub_build)
else:
if not os.path.isabs(line):
line = os.path.abspath(os.path.join(root, line))
@@ -207,7 +216,7 @@ class Build:
print >> sys.stderr, 'Unable to find file ' + line
return False
if isNeg:
if is_neg:
self.include.discard(line)
self.exclude.add(line)
else:
@@ -216,80 +225,81 @@ class Build:
return True
def buildRaw(self, extra_opts):
def build_raw(self, extra_opts):
"""Builds the files in |self.include| using the given extra Closure options.
Arguments:
extra_opts - An array of extra options to give to Closure.
Args:
extra_opts: An array of extra options to give to Closure.
Returns:
True on success; False on failure.
"""
jar = os.path.join(shakaBuildHelpers.getSourceBase(),
'third_party', 'closure', 'compiler.jar')
jar = shakaBuildHelpers.cygwinSafePath(jar)
files = map(shakaBuildHelpers.cygwinSafePath, list(self.include))
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]
try:
cmdLine = ['java', '-jar', jar] + closure_opts + extra_opts + files
shakaBuildHelpers.printCmdLine(cmdLine)
subprocess.check_call(cmdLine)
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 buildLibrary(self, name, rebuild):
def build_library(self, name, rebuild):
"""Builds Shaka Player using the files in |self.include|.
Arguments:
name - The name of the build.
rebuild - True to rebuild, False to ignore if no changes are detected.
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._addCore()
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.
sourceBase = shakaBuildHelpers.getSourceBase().replace('\\', '/')
source_base = shakaBuildHelpers.get_source_base().replace('\\', '/')
resultPrefix = shakaBuildHelpers.cygwinSafePath(
os.path.join(sourceBase, 'dist', 'shaka-player.' + name))
resultFile = resultPrefix + '.js'
resultDebug = resultPrefix + '.debug.js'
resultMap = resultPrefix + '.debug.map'
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(resultFile):
buildTime = os.path.getmtime(resultFile)
completeBuild = Build()
if completeBuild.parseBuild(['+@complete'], os.getcwd()):
completeBuild._addCore()
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.
editedFiles = filter(lambda x: os.path.getmtime(x) > buildTime,
completeBuild.include)
if len(editedFiles) == 0:
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', resultMap, '--js_output_file', resultDebug,
'--source_map_location_mapping', sourceBase + '|..']
if not self.buildRaw(opts):
opts = ['--create_source_map', result_map, '--js_output_file', result_debug,
'--source_map_location_mapping', source_base + '|..']
if not self.build_raw(opts):
return False
shutil.copyfile(resultDebug, resultFile)
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(resultDebug, 'a') as f:
with open(result_debug, 'a') as f:
f.write('//# sourceMappingURL=shaka-player.' + name + '.debug.map')
return True
def usage():
print 'Usage:', sys.argv[0], """[options] [commands]
@@ -300,6 +310,7 @@ Options:
"""
print __doc__
def main(args):
name = 'compiled'
lines = []
@@ -307,7 +318,7 @@ def main(args):
i = 0
while i < len(args):
if args[i] == '--name':
i = i + 1
i += 1
if i == len(args):
print >> sys.stderr, '--name requires an argument'
return 1
@@ -323,17 +334,17 @@ def main(args):
return 1
else:
lines.append(args[i])
i = i + 1
i += 1
if len(lines) == 0:
if not lines:
lines = ['+@complete']
print 'Compiling the library...'
customBuild = Build()
if not customBuild.parseBuild(lines, os.getcwd()):
custom_build = Build()
if not custom_build.parse_build(lines, os.getcwd()):
return 1
return 0 if customBuild.buildLibrary(name, rebuild) else 1
return 0 if custom_build.build_library(name, rebuild) else 1
if __name__ == '__main__':
shakaBuildHelpers.runMain(main)
shakaBuildHelpers.run_main(main)
+55 -43
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,26 +19,28 @@
This checks:
* All files in lib/ appear when compiling +@complete
* Runs a compiler pass over the test code to check for type errors
* Run the linter to check for style violations."""
* Run the linter to check for style violations.
"""
import build
import os
import re
import shakaBuildHelpers
import subprocess
import sys
def getLintFiles():
"""Returns an array of absolute paths to all the files to run the linter
over.
"""
import build
import shakaBuildHelpers
def get_lint_files():
"""Returns the absolute paths to all the files to run the linter over."""
match = re.compile(r'.*\.js$')
base = shakaBuildHelpers.getSourceBase()
base = shakaBuildHelpers.get_source_base()
def get(arg):
return shakaBuildHelpers.getAllFiles(os.path.join(base, arg), match)
return shakaBuildHelpers.get_all_files(os.path.join(base, arg), match)
return get('test') + get('lib') + get('externs') + get('demo')
def checkLint():
def check_lint():
"""Runs the linter over the library files."""
print 'Running Closure linter...'
@@ -46,36 +48,43 @@ def checkLint():
'static', 'summary', 'namespace', 'event', 'description', 'property',
'fires', 'listens', 'example', 'exportDoc'])
args = ['--nobeep', '--custom_jsdoc_tags', jsdoc3_tags, '--strict']
base = shakaBuildHelpers.getSourceBase()
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.
cmdLine = ['python', cmd] + args + getLintFiles()
shakaBuildHelpers.printCmdLine(cmdLine)
return (subprocess.call(cmdLine) == 0)
cmd_line = ['python', cmd] + args + get_lint_files()
shakaBuildHelpers.print_cmd_line(cmd_line)
return subprocess.call(cmd_line) == 0
def checkHtmlLint():
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.getNodeBinaryPath('htmlhint')
htmlhint_path = shakaBuildHelpers.get_node_binary_path('htmlhint')
if not os.path.exists(htmlhint_path):
return True
print 'Running htmlhint...'
base = shakaBuildHelpers.getSourceBase()
base = shakaBuildHelpers.get_source_base()
files = ['index.html', 'demo/index.html', 'support.html']
file_paths = [os.path.join(base, x) for x in files]
cmdLine = [htmlhint_path] + file_paths
shakaBuildHelpers.printCmdLine(cmdLine)
return (subprocess.call(cmdLine) == 0)
cmd_line = [htmlhint_path] + file_paths
shakaBuildHelpers.print_cmd_line(cmd_line)
return subprocess.call(cmd_line) == 0
def checkComplete():
"""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.
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.
@@ -86,24 +95,25 @@ def checkComplete():
# 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.parseBuild(['+@complete', '+@core'], os.getcwd()):
if not complete.parse_build(['+@complete', '+@core'], os.getcwd()):
print >> sys.stderr, 'Error parsing complete build'
return False
match = re.compile(r'.*\.js$')
base = shakaBuildHelpers.getSourceBase()
allFiles = shakaBuildHelpers.getAllFiles(os.path.join(base, 'lib'), match)
missingFiles = set(allFiles) - complete.include
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 len(missingFiles) > 0:
if missing_files:
print >> sys.stderr, 'There are files missing from the complete build:'
for missing in missingFiles:
for missing in missing_files:
# Convert to a path relative to source base.
print >> sys.stderr, ' ' + os.path.relpath(missing, base)
return False
return True
def checkTests():
def check_tests():
"""Runs an extra compile pass over the test code to check for type errors.
Returns:
@@ -112,23 +122,25 @@ def checkTests():
print 'Checking the tests for type errors...'
match = re.compile(r'.*\.js$')
base = shakaBuildHelpers.getSourceBase()
base = shakaBuildHelpers.get_source_base()
def get(*args):
return shakaBuildHelpers.getAllFiles(os.path.join(base, *args), match)
return shakaBuildHelpers.get_all_files(os.path.join(base, *args), match)
files = (get('lib') + get('externs') + get('test') + get('demo') +
get('third_party', 'closure'))
testBuild = build.Build(set(files))
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 testBuild.buildRaw(opts)
return test_build.build_raw(opts)
def usage():
print 'Usage:', sys.argv[0]
print
print __doc__
def main(args):
for arg in args:
if arg == '--help':
@@ -139,17 +151,17 @@ def main(args):
usage()
return 1
if not checkLint():
if not check_lint():
return 1
elif not checkHtmlLint():
elif not check_html_lint():
return 1
elif not checkComplete():
elif not check_complete():
return 1
elif not checkTests():
elif not check_tests():
return 1
else:
return 0
if __name__ == '__main__':
shakaBuildHelpers.runMain(main)
if __name__ == '__main__':
shakaBuildHelpers.run_main(main)
+19 -12
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,31 +14,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Checks that all the versions match."""
import os
import re
import shakaBuildHelpers
import sys
def playerVersion():
import shakaBuildHelpers
def player_version():
"""Gets the version of the library from player.js."""
path = os.path.join(shakaBuildHelpers.getSourceBase(), 'lib', '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 changelogVersion():
def changelog_version():
"""Gets the version of the library from the CHANGELOG."""
path = os.path.join(shakaBuildHelpers.getSourceBase(), 'CHANGELOG.md')
path = os.path.join(shakaBuildHelpers.get_source_base(), 'CHANGELOG.md')
with open(path, 'r') as f:
match = re.search(r'## (.*) \(', f.read())
return match.group(1) if match else ''
def checkVersion(_):
def check_version(_):
"""Checks that all the versions in the library match."""
changelog = changelogVersion()
player = playerVersion()
git = shakaBuildHelpers.gitVersion()
npm = shakaBuildHelpers.npmVersion()
changelog = changelog_version()
player = player_version()
git = shakaBuildHelpers.git_version()
npm = shakaBuildHelpers.npm_version()
print 'git version:', git
print 'npm version:', npm
@@ -71,5 +77,6 @@ def checkVersion(_):
return ret
if __name__ == '__main__':
shakaBuildHelpers.runMain(checkVersion)
shakaBuildHelpers.run_main(check_version)
+16 -12
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,33 +14,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Builds the documentation from the source code. This deletes the old
documentation first.
"""Builds the documentation from the source code.
This deletes the old documentation first.
"""
import os
import shakaBuildHelpers
import shutil
import subprocess
import sys
def buildDocs(_):
import shakaBuildHelpers
def build_docs(_):
"""Builds the source code documentation."""
print 'Building the docs...'
base = shakaBuildHelpers.getSourceBase()
base = shakaBuildHelpers.get_source_base()
shutil.rmtree(os.path.join(base, 'docs', 'api'), ignore_errors=True)
os.chdir(base)
if shakaBuildHelpers.isWindows() or shakaBuildHelpers.isCygwin():
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')
cmdLine = [jsdoc, '-c', 'docs/jsdoc.conf.json', '-R', 'docs/api-mainpage.md']
shakaBuildHelpers.printCmdLine(cmdLine)
return subprocess.call(cmdLine)
cmd_line = [jsdoc, '-c', 'docs/jsdoc.conf.json', '-R', 'docs/api-mainpage.md']
shakaBuildHelpers.print_cmd_line(cmd_line)
return subprocess.call(cmd_line)
if __name__ == '__main__':
shakaBuildHelpers.runMain(buildDocs)
shakaBuildHelpers.run_main(build_docs)
+18 -15
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,40 +14,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Creates the Closure dependencies file required to run in uncompiled mode.
"""
"""Creates the Closure dependencies file required to run in uncompiled mode."""
import os
import shakaBuildHelpers
import subprocess
import sys
depsArgs = [
'--root_with_prefix=lib ../../../lib',
'--root_with_prefix=third_party/closure ../../../third_party/closure'
import shakaBuildHelpers
deps_args = [
'--root_with_prefix=lib ../../../lib',
'--root_with_prefix=third_party/closure ../../../third_party/closure'
]
def genDeps(_):
def gen_deps(_):
"""Generates the uncompiled dependencies files."""
print 'Generating Closure dependencies...'
# Make the dist/ folder, ignore errors.
base = shakaBuildHelpers.getSourceBase()
base = shakaBuildHelpers.get_source_base()
try:
os.mkdir(os.path.join(base, 'dist'))
except OSError:
pass
os.chdir(base)
depsWriter = os.path.join('third_party', 'closure', 'deps', 'depswriter.py')
deps_writer = os.path.join('third_party', 'closure', 'deps', 'depswriter.py')
try:
cmdLine = ['python', depsWriter] + depsArgs
shakaBuildHelpers.printCmdLine(cmdLine)
deps = subprocess.check_output(cmdLine)
cmd_line = ['python', deps_writer] + deps_args
shakaBuildHelpers.print_cmd_line(cmd_line)
deps = subprocess.check_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
if __name__ == '__main__':
shakaBuildHelpers.runMain(genDeps)
shakaBuildHelpers.run_main(gen_deps)
+100 -62
View File
@@ -1,5 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains helper functions used in the build scripts. This uses two
environment variables to help with debugging the scripts:
"""Contains helper functions used in the build scripts.
This uses two environment variables to help with debugging the scripts:
PRINT_ARGUMENTS - If set, will print any arguments to subprocess.
RAISE_INTERRUPT - Will raise keyboard interrupts rather than swallowing them.
@@ -26,32 +28,48 @@ import re
import subprocess
import sys
def _parseVersion(s):
return tuple([int(i) for i in s.split('.')])
def getSourceBase():
def _parse_version(version):
"""Converts the given string version to a tuple of numbers."""
return tuple([int(i) for i in version.split('.')])
def get_source_base():
"""Returns the absolute path to the source code base."""
return os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
def isLinux():
def is_linux():
"""Determines if the system is Linux."""
return platform.uname()[0] == 'Linux'
def isDarwin():
def is_darwin():
"""Determines if the system is a Mac."""
return platform.uname()[0] == 'Darwin'
def isWindows():
def is_windows():
"""Determines if the system is native Windows (i.e. not Cygwin)."""
return platform.uname()[0] == 'Windows'
def isCygwin():
def is_cygwin():
"""Determines if the system is Cygwin (i.e. not native Windows)."""
return 'CYGWIN' in platform.uname()[0]
def quoteArgument(arg):
"""Quotes shell arguments so that printCmdLine output can be copied and pasted
into a shell."""
def quote_argument(arg):
"""Wraps the given argument in quotes if needed.
This is so print_cmd_line output can be copied and pasted into a shell.
Args:
arg: The string to convert.
Returns:
The quoted argument.
"""
if '"' in arg:
assert "'" not in arg
return "'" + arg + "'"
@@ -62,80 +80,92 @@ def quoteArgument(arg):
return '"' + arg + '"'
return arg
def printCmdLine(args):
"""Prints the given command line if the environment variable PRINT_ARGUMENTS
is set."""
if os.environ.get('PRINT_ARGUMENTS'):
print ' '.join([quoteArgument(x) for x in args])
def cygwinSafePath(path):
"""If the system is Cygwin, converts the given Cygwin path to a Windows path;
this does nothing if not Cygwin"""
if isCygwin():
cmdLine = ['cygpath', '-w', path]
printCmdLine(cmdLine)
return subprocess.check_output(cmdLine).strip()
def print_cmd_line(args):
"""Prints the given command line if needed.
This uses the environment variable PRINT_ARGUMENTS.
Args:
args: The arguments to print.
"""
if os.environ.get('PRINT_ARGUMENTS'):
print ' '.join([quote_argument(x) for x in args])
def cygwin_safe_path(path):
"""Converts the given path to a Cygwin path, if needed."""
if is_cygwin():
cmd_line = ['cygpath', '-w', path]
print_cmd_line(cmd_line)
return subprocess.check_output(cmd_line).strip()
else:
return path
def gitVersion():
def git_version():
"""Gets the version of the library from git."""
try:
# Check git tags for a version number, noting if the sources are dirty.
cmdLine = ['git', '-C', getSourceBase(), 'describe', '--tags', '--dirty']
printCmdLine(cmdLine)
return subprocess.check_output(cmdLine).strip()
cmd_line = ['git', '-C', get_source_base(), 'describe', '--tags', '--dirty']
print_cmd_line(cmd_line)
return subprocess.check_output(cmd_line).strip()
except subprocess.CalledProcessError:
raise RuntimeError('Unable to determine library version!')
def npmVersion(isDirty=False):
def npm_version(is_dirty=False):
"""Gets the version of the library from NPM."""
try:
base = cygwinSafePath(getSourceBase())
cmd = 'npm.cmd' if isWindows() else 'npm'
cmdLine = [cmd, '--prefix', base, 'ls', 'shaka-player']
printCmdLine(cmdLine)
text = subprocess.check_output(cmdLine)
base = cygwin_safe_path(get_source_base())
cmd = 'npm.cmd' if is_windows() else 'npm'
cmd_line = [cmd, '--prefix', base, 'ls', 'shaka-player']
print_cmd_line(cmd_line)
text = subprocess.check_output(cmd_line)
except subprocess.CalledProcessError as e:
text = e.output
match = re.search(r'shaka-player@(.*) ', text)
if match:
return match.group(1) + ('-npm-dirty' if isDirty else '')
return match.group(1) + ('-npm-dirty' if is_dirty else '')
raise RuntimeError('Unable to determine library version!')
def calculateVersion():
def calculate_version():
"""Returns the version of the library."""
# Fall back to NPM's installed package version, and assume the sources
# are dirty since the build scripts are being run at all after install.
try:
return gitVersion()
return git_version()
except RuntimeError:
# If there is an error in |gitVersion|, ignore it and try NPM. If there
# If there is an error in |git_version|, ignore it and try NPM. If there
# is an error with NPM, propagate the error.
return npmVersion(isDirty=True)
return npm_version(is_dirty=True)
def getAllFiles(dirPath, exp):
"""Returns an array of absolute paths to all the files at the given path that
match the given regex (if given).
Arguments:
dirPath - The string path to search.
exp - A regex to match, can be None.
def get_all_files(dir_path, exp=None):
"""Returns an array of absolute paths to all the files at the given path.
This optionally will filter the output using the given regex.
Args:
dir_path: The string path to search.
exp: A regex to match, can be None.
Returns:
An array of absolute paths to all the files.
"""
ret = []
for root, _, files in os.walk(dirPath):
for root, _, files in os.walk(dir_path):
for f in files:
if not exp or exp.match(f):
ret.append(os.path.join(root, f))
ret.sort()
return ret
def getNodeBinaryPath(name):
def get_node_binary_path(name):
# Try local modules first.
base = getSourceBase()
base = get_source_base()
path = os.path.join(base, 'node_modules', '.bin', name)
if os.path.isfile(path):
return path
@@ -143,28 +173,36 @@ def getNodeBinaryPath(name):
# Not found locally, assume it can be found in os.environ['PATH'].
return name
def updateNodeModules():
base = cygwinSafePath(getSourceBase())
cmd = 'npm.cmd' if isWindows() else 'npm'
def update_node_modules():
"""Updates the node modules using 'npm'."""
base = cygwin_safe_path(get_source_base())
cmd = 'npm.cmd' if is_windows() else 'npm'
# Check the version of npm.
cmdLine = [cmd, '-v']
printCmdLine(cmdLine)
version = subprocess.check_output(cmdLine)
if _parseVersion(version) < _parseVersion('1.3.12'):
cmd_line = [cmd, '-v']
print_cmd_line(cmd_line)
version = subprocess.check_output(cmd_line)
if _parse_version(version) < _parse_version('1.3.12'):
print >> sys.stderr, 'npm version is too old, please upgrade. e.g.:'
print >> sys.stderr, ' npm install -g npm'
return False
# Update the modules.
cmdLine = [cmd, '--prefix', base, 'update']
printCmdLine(cmdLine)
subprocess.check_call(cmdLine)
cmd_line = [cmd, '--prefix', base, 'update']
print_cmd_line(cmd_line)
subprocess.check_call(cmd_line)
return True
def runMain(main):
"""Executes the given function with the current command-line arguments,
calling exit with the return value. This ignores keyboard interrupts."""
def run_main(main):
"""Executes the given function with the current command-line arguments.
This calls exit with the return value. This ignores keyboard interrupts.
Args:
main: The main function to call.
"""
try:
sys.exit(main(sys.argv[1:]))
except KeyboardInterrupt:
+345 -274
View File
File diff suppressed because it is too large Load Diff
+26 -23
View File
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright 2016 Google Inc.
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,23 +14,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import build
import gendeps
import os
"""Runs unit and integrations tests on the library."""
import platform
import shakaBuildHelpers
import subprocess
import sys
def runTests(args):
import build
import gendeps
import shakaBuildHelpers
def run_tests(args):
"""Runs all the karma tests."""
# Update node modules if needed.
if not shakaBuildHelpers.updateNodeModules():
if not shakaBuildHelpers.update_node_modules():
return 1
# Generate dependencies and compile library.
# This is required for the tests.
if gendeps.genDeps([]) != 0:
if gendeps.gen_deps([]) != 0:
return 1
build_args = []
@@ -45,50 +48,50 @@ def runTests(args):
return 1
karma_command_name = 'karma'
if shakaBuildHelpers.isWindows():
if shakaBuildHelpers.is_windows():
# Windows karma program has a different name
karma_command_name = 'karma.cmd'
karma_path = shakaBuildHelpers.getNodeBinaryPath(karma_command_name)
karma_path = shakaBuildHelpers.get_node_binary_path(karma_command_name)
cmd = [karma_path, 'start']
# Get the browsers supported on the local system.
browsers = _GetBrowsers()
browsers = _get_browsers()
if not browsers:
print >> sys.stderr, 'Unrecognized system "%s"' % platform.uname()[0]
return 1
print 'Starting tests...'
if len(args) == 0:
if not args:
# Run tests in all available browsers.
print 'Running with platform default:', '--browsers', browsers
cmdLine = cmd + ['--browsers', browsers]
shakaBuildHelpers.printCmdLine(cmdLine)
return subprocess.call(cmdLine)
cmd_line = cmd + ['--browsers', browsers]
shakaBuildHelpers.print_cmd_line(cmd_line)
return subprocess.call(cmd_line)
else:
# Run with command-line arguments from the user.
if '--browsers' not in args:
print 'No --browsers specified.'
print 'In this mode, browsers must be manually connected to karma.'
cmdLine = cmd + args
shakaBuildHelpers.printCmdLine(cmdLine)
return subprocess.call(cmdLine)
cmd_line = cmd + args
shakaBuildHelpers.print_cmd_line(cmd_line)
return subprocess.call(cmd_line)
def _GetBrowsers():
def _get_browsers():
"""Uses the platform name to configure which browsers will be tested."""
browsers = None
if shakaBuildHelpers.isLinux():
if shakaBuildHelpers.is_linux():
# For MP4 support on Linux Firefox, install gstreamer1.0-libav.
# Opera on Linux only supports MP4 for Ubuntu 15.04+, so it is not in the
# default list of browsers for Linux at this time.
browsers = 'Chrome,Firefox'
elif shakaBuildHelpers.isDarwin():
elif shakaBuildHelpers.is_darwin():
browsers = 'Chrome,Firefox,Safari'
elif shakaBuildHelpers.isWindows() or shakaBuildHelpers.isCygwin():
elif shakaBuildHelpers.is_windows() or shakaBuildHelpers.is_cygwin():
browsers = 'Chrome,Firefox,IE'
return browsers
if __name__ == '__main__':
shakaBuildHelpers.runMain(runTests)
shakaBuildHelpers.run_main(run_tests)