Ejemplo n.º 1
0
  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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
  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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
    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]
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
def _canonicalize_source_files(source_files):
    """Canonicalize a set or list of source files.

  This makes all path names cygwin-safe and sorted."""

    files = [shakaBuildHelpers.cygwin_safe_path(f) for f in source_files]
    files.sort()
    return files
Ejemplo n.º 11
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
Ejemplo n.º 12
0
  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
Ejemplo n.º 13
0
    def build_raw(self, extra_opts):
        """Builds the files in |self.include| using the given extra Closure options.

    Args:
      extra_opts: An array of extra options to give to Closure.

    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:
            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
Ejemplo n.º 14
0
  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
Ejemplo n.º 15
0
    def build_raw(self, closure_opts):
        """Builds the files in |self.include| using the given extra Closure options.

    Args:
      closure_opts: An array of options to give to Closure.

    Returns:
      True on success; False on failure.
    """
        jar = self._get_closure_jar_path()
        files = [shakaBuildHelpers.cygwin_safe_path(f) for f in self.include]
        files.sort()

        cmd_line = ['java', '-jar', jar] + closure_opts + files
        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Build failed')
            return False

        return True
Ejemplo n.º 16
0
def _get_source_path(path):
    """Take path components of a source file as arguments and return an absolute,
     cygwin-safe path."""
    return shakaBuildHelpers.cygwin_safe_path(
        os.path.join(shakaBuildHelpers.get_source_base(), path))
Ejemplo n.º 17
0
closure_opts = [
    "--language_in",
    "ECMASCRIPT5",
    "--language_out",
    "ECMASCRIPT3",
    "--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",
    "--extra_annotation_name=listens",
    "--extra_annotation_name=exportDoc",
    "--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.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",
Ejemplo n.º 18
0
 def _get_closure_jar_path(self):
     jar = os.path.join(shakaBuildHelpers.get_source_base(), 'third_party',
                        'closure', 'compiler.jar')
     return shakaBuildHelpers.cygwin_safe_path(jar)
Ejemplo n.º 19
0
import shakaBuildHelpers

common_closure_opts = [
    '--language_out',
    'ECMASCRIPT3',
    '--jscomp_error=*',

    # Turn off complaints like:
    #   "Private property foo_ is never modified, use the @const annotation"
    '--jscomp_off=jsdocMissingConst',
    '--extra_annotation_name=listens',
    '--extra_annotation_name=exportDoc',
    '--extra_annotation_name=exportInterface',
    '--conformance_configs',
    ('%s/build/conformance.textproto' %
     shakaBuildHelpers.cygwin_safe_path(shakaBuildHelpers.get_source_base())),
    '--generate_exports',
]
common_closure_defines = [
    '-D',
    'COMPILED=true',
    '-D',
    'goog.STRICT_MODE_COMPATIBLE=true',
    '-D',
    'goog.ENABLE_DEBUG_LOADER=false',
]
debug_closure_opts = [
    # Don't use a wrapper script in debug mode so all the internals are visible
    # on the global object.
    '-O',
    'SIMPLE',
Ejemplo n.º 20
0
import shakaBuildHelpers


common_closure_opts = [
    '--language_out', 'ECMASCRIPT3',

    '--jscomp_error=*',

    '--extra_annotation_name=listens',
    '--extra_annotation_name=exportDoc',
    '--extra_annotation_name=exportInterface',

    '--conformance_configs',
    ('%s/build/conformance.textproto' %
     shakaBuildHelpers.cygwin_safe_path(shakaBuildHelpers.get_source_base())),

    '--generate_exports',
]
common_closure_defines = [
    '-D', 'COMPILED=true',
    '-D', 'goog.STRICT_MODE_COMPATIBLE=true',
    '-D', 'goog.ENABLE_DEBUG_LOADER=false',
]
debug_closure_opts = [
    # Don't use a wrapper script in debug mode so all the internals are visible
    # on the global object.
    '-O', 'SIMPLE',
]
debug_closure_defines = [
    '-D', 'goog.DEBUG=true',