Exemplo n.º 1
0
def run_tests_single(args):
    """Runs all the karma tests."""
    karma_path = shakaBuildHelpers.get_node_binary_path('karma')
    cmd = [karma_path, 'start']

    if shakaBuildHelpers.is_linux() and '--use-xvfb' in args:
        cmd = ['xvfb-run', '--auto-servernum'] + cmd

    # Get the browsers supported on the local system.
    browsers = _get_browsers()
    if not browsers:
        print >> sys.stderr, 'Unrecognized system "%s"' % platform.uname()[0]
        return 1

    print 'Starting tests...'
    if not args:
        # Run tests in all available browsers.
        print 'Running with platform default:', '--browsers', browsers
        cmd_line = cmd + ['--browsers', browsers]
        return shakaBuildHelpers.execute_get_code(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.'
        cmd_line = cmd + args
        return shakaBuildHelpers.execute_get_code(cmd_line)
Exemplo n.º 2
0
def run_tests_single(args):
  """Runs all the karma tests."""
  karma_path = shakaBuildHelpers.get_node_binary_path('karma')
  cmd = [karma_path, 'start']

  if shakaBuildHelpers.is_linux() and '--use-xvfb' in args:
    cmd = ['xvfb-run', '--auto-servernum'] + cmd

  # Get the browsers supported on the local system.
  browsers = _get_browsers()
  if not browsers:
    print >> sys.stderr, 'Unrecognized system "%s"' % platform.uname()[0]
    return 1

  print 'Starting tests...'
  if not args:
    # Run tests in all available browsers.
    print 'Running with platform default:', '--browsers', browsers
    cmd_line = cmd + ['--browsers', browsers]
    return shakaBuildHelpers.execute_get_code(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.'
    cmd_line = cmd + args
    return shakaBuildHelpers.execute_get_code(cmd_line)
Exemplo n.º 3
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
Exemplo n.º 4
0
    def lint(self, force=False):
        """Run HTML linter checks on the files in |self.source_files|.

    Args:
      force: Run linter checks even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        deps = self.source_files + [self.config_path]
        if not force and not _must_build(self.output, deps):
            return True

        cmd_line = [
            'npx',
            'htmlhint',
            '--config=' + self.config_path,
        ] + self.source_files

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            return False

        # Update the timestamp of the file that tracks when we last updated.
        _update_timestamp(self.output)
        return True
Exemplo n.º 5
0
    def lint(self, fix=False, force=False):
        """Run CSS linter checks on the files in |self.source_files|.

    Args:
      fix: If True, ask the linter to fix what errors it can automatically.
      force: Run linter checks even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        deps = self.source_files + [self.config_path]
        if not force and not _must_build(self.output, deps):
            return True

        cmd_line = [
            'npx',
            'stylelint',
            '--config',
            self.config_path,
            # The "default ignores" is something like **/node_modules/**, which
            # means that if we run the build scripts from inside the installed node
            # modules of shaka-player, all our sources will be filtered out if we
            # don't disable the default ignores in stylelint.
            '--disable-default-ignores',
        ] + self.source_files

        if fix:
            cmd_line += ['--fix']

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            return False

        # Update the timestamp of the file that tracks when we last updated.
        _update_timestamp(self.output)
        return True
Exemplo n.º 6
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:
            print >> sys.stderr, 'Build failed'
            return False

        return True
Exemplo n.º 7
0
    def lint(self, fix=False, force=False):
        """Run linter checks on the files in |self.source_files|.

    Args:
      fix: If True, ask the linter to fix what errors it can automatically.
      force: Run linter checks even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        deps = self.source_files + [self.config_path]
        if not force and not _must_build(self.output, deps):
            return True

        eslint = shakaBuildHelpers.get_node_binary('eslint')
        cmd_line = eslint + ['--config', self.config_path] + self.source_files

        if fix:
            cmd_line += ['--fix']

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            return False

        # TODO: Add back Closure Compiler Linter

        # Update the timestamp of the file that tracks when we last updated.
        _update_timestamp(self.output)
        return True
Exemplo n.º 8
0
    def build(self, force=False):
        """Build the documentation.

    Args:
      force: Build the docs even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        deps = self.source_files + [self.config_path]
        if not force and not _must_build(self.output, deps):
            return True

        base = _get_source_path('')

        # Wipe out any old docs.
        shutil.rmtree(os.path.join(base, 'docs', 'api'), ignore_errors=True)

        # Jsdoc expects to run from the base dir.
        with shakaBuildHelpers.InDir(base):
            jsdoc = shakaBuildHelpers.get_node_binary('jsdoc')
            cmd_line = jsdoc + ['-c', self.config_path]
            if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
                return False

        return True
Exemplo n.º 9
0
    def lint(self, fix=False, force=False):
        """Run CSS linter checks on the files in |self.source_files|.

    Args:
      fix: If True, ask the linter to fix what errors it can automatically.
      force: Run linter checks even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        deps = self.source_files + [self.config_path]
        if not force and not _must_build(self.output, deps):
            return True

        stylelint = shakaBuildHelpers.get_node_binary('stylelint')
        cmd_line = stylelint + ['--config', self.config_path
                                ] + self.source_files
        # Disables globbing, since that messes up our nightly tests, and we don't
        # use it anyway.
        # This is currently a flag added in a fork we maintain, but there is a pull
        # request in progress for this.
        # See: https://github.com/stylelint/stylelint/issues/4193
        cmd_line += ['--disable-globbing']

        if fix:
            cmd_line += ['--fix']

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            return False

        # Update the timestamp of the file that tracks when we last updated.
        _update_timestamp(self.output)
        return True
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
def run_tests_single(args):
    """Runs all the karma tests."""
    # Update node modules if needed.
    if not shakaBuildHelpers.update_node_modules():
        return 1

    # Generate dependencies and compile library.
    # This is required for the tests.
    if gendeps.gen_deps([]) != 0:
        return 1

    build_args = []
    if '--force' in args:
        build_args.append('--force')
        args.remove('--force')

    if '--no-build' in args:
        args.remove('--no-build')
    else:
        if build.main(build_args) != 0:
            return 1

    karma_path = shakaBuildHelpers.get_node_binary_path('karma')
    cmd = [karma_path, 'start']

    if shakaBuildHelpers.is_linux() and '--use-xvfb' in args:
        cmd = ['xvfb-run', '--auto-servernum'] + cmd

    # Get the browsers supported on the local system.
    browsers = _get_browsers()
    if not browsers:
        print >> sys.stderr, 'Unrecognized system "%s"' % platform.uname()[0]
        return 1

    print 'Starting tests...'
    if not args:
        # Run tests in all available browsers.
        print 'Running with platform default:', '--browsers', browsers
        cmd_line = cmd + ['--browsers', browsers]
        return shakaBuildHelpers.execute_get_code(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.'
        cmd_line = cmd + args
        return shakaBuildHelpers.execute_get_code(cmd_line)
Exemplo n.º 13
0
def check_js_lint():
    """Runs the JavaScript linter."""
    # TODO: things not enforced: property doc requirements
    logging.info('Running eslint...')

    eslint = shakaBuildHelpers.get_node_binary('eslint')
    cmd_line = eslint + get_lint_files()
    return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 14
0
def check_js_lint():
  """Runs the JavaScript linter."""
  # TODO: things not enforced: property doc requirements
  logging.info('Running eslint...')

  eslint = shakaBuildHelpers.get_node_binary('eslint')
  cmd_line = eslint + get_lint_files()
  return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 15
0
    def RunCommand(self, karma_conf):
        """Build a command and send it to Karma for execution.

       Uses |self.parsed_args| and |self.karma_config| to build and run a Karma
       command.
    """
        if self.parsed_args.use_xvfb and not shakaBuildHelpers.is_linux():
            logging.error('xvfb can only be used on Linux')
            return 1

        if not shakaBuildHelpers.update_node_modules():
            logging.error('Failed to update node modules')
            return 1

        karma = shakaBuildHelpers.get_node_binary('karma')
        cmd = ['xvfb-run', '--auto-servernum'
               ] if self.parsed_args.use_xvfb else []
        cmd += karma + ['start']
        cmd += [karma_conf] if karma_conf else []
        cmd += ['--settings', json.dumps(self.karma_config)]

        # There is no need to print a status here as the gendep and build
        # calls will print their own status updates.
        if self.parsed_args.build:
            if gendeps.main([]) != 0:
                logging.error('Failed to generate project dependencies')
                return 1

            if build.main(['--force'] if self.parsed_args.force else []) != 0:
                logging.error('Failed to build project')
                return 1

        # Before Running the command, print the command.
        if self.parsed_args.print_command:
            logging.info('Karma Run Command')
            logging.info('%s', cmd)

        # Run the command.
        results = []
        for run in range(self.parsed_args.runs):
            logging.info('Running test (%d / %d, %d failed so far)...',
                         run + 1, self.parsed_args.runs,
                         len(results) - results.count(0))
            results.append(shakaBuildHelpers.execute_get_code(cmd))

        # Print a summary of the results.
        if self.parsed_args.runs > 1:
            logging.info('All runs completed. %d / %d runs passed.',
                         results.count(0), len(results))
            logging.info('Results (exit code): %r', results)
        else:
            logging.info('Run complete')
            logging.info('Result (exit code): %d', results[0])

        return 0 if all(result == 0 for result in results) else 1
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
  def RunCommand(self, karma_conf):
    """Build a command and send it to Karma for execution.

       Uses |self.parsed_args| and |self.karma_config| to build and run a Karma
       command.
    """
    if self.parsed_args.use_xvfb and not shakaBuildHelpers.is_linux():
      logging.error('xvfb can only be used on Linux')
      return 1

    if not shakaBuildHelpers.update_node_modules():
      logging.error('Failed to update node modules')
      return 1

    karma = shakaBuildHelpers.get_node_binary('karma')
    cmd = ['xvfb-run', '--auto-servernum'] if self.parsed_args.use_xvfb else []
    cmd += karma + ['start']
    cmd += [karma_conf] if karma_conf else []
    cmd += ['--settings', json.dumps(self.karma_config)]

    # There is no need to print a status here as the gendep and build
    # calls will print their own status updates.
    if self.parsed_args.build:
      if gendeps.gen_deps([]) != 0:
        logging.error('Failed to generate project dependencies')
        return 1

      if build.main(['--force'] if self.parsed_args.force else []) != 0:
        logging.error('Failed to build project')
        return 1

    # Before Running the command, print the command.
    if self.parsed_args.print_command:
      logging.info('Karma Run Command')
      logging.info('%s', cmd)

    # Run the command.
    results = []
    for run in range(self.parsed_args.runs):
      logging.info('Running test (%d / %d)...', run + 1, self.parsed_args.runs)
      results.append(shakaBuildHelpers.execute_get_code(cmd))

    # Print a summary of the results.
    if self.parsed_args.runs > 1:
      logging.info('All runs completed. %d / %d runs passed.',
                   results.count(0),
                   len(results))
      logging.info('Results (exit code): %r', results)
    else:
      logging.info('Run complete')
      logging.info('Result (exit code): %d', results[0])

    return 0 if all(result == 0 for result in results) else 1
Exemplo n.º 18
0
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
Exemplo n.º 19
0
def check_html_lint():
    """Runs the HTML linter over the HTML files.

  Returns:
    True on success, False on failure.
  """
    logging.info('Running htmlhint...')
    htmlhint_path = shakaBuildHelpers.get_node_binary_path('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_path, '--config=' + config_path] + file_paths
    return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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', 'tutorial'
    ])
    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 = [sys.executable or 'python', cmd] + args + get_lint_files()
    return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 22
0
def check_lint():
  """Runs the linter over the library files."""
  logging.info('Running Closure linter...')

  jsdoc3_tags = ','.join([
      'static', 'summary', 'namespace', 'event', 'description', 'property',
      'fires', 'listens', 'example', 'exportDoc', 'exportInterface',
      'tutorial'])
  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 = [sys.executable or 'python', cmd] + args + get_lint_files()
  return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 23
0
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)
Exemplo n.º 24
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
Exemplo n.º 25
0
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]
    config_path = os.path.join(base, '.htmlhintrc')
    cmd_line = [htmlhint_path, '--config=' + config_path] + file_paths
    return shakaBuildHelpers.execute_get_code(cmd_line) == 0
Exemplo n.º 26
0
    def compile(self, force=False):
        """Compiles the main less file in |self.main_source_file| into the
       |self.output| css file.

    Args:
      force: Generate the output even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        if not force and not _must_build(self.output, self.all_source_files):
            return True

        less_options = [
            # Enable the "clean-CSS" plugin to minify the output and strip out comments.
            '--clean-css',
            # Output a source map of the original CSS/less files.
            '--source-map=' + self.output + '.map',
        ]

        cmd_line = [
            'npx',
            'lessc',
        ] + less_options + [
            self.main_source_file,
            self.output,
        ]

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Externs generation failed')
            return False

        # We need to prepend the license header to the compiled CSS.
        with open(_get_source_path('build/license-header'), 'rb') as f:
            license_header = f.read()
        with open(self.output, 'rb') as f:
            contents = f.read()
        with open(self.output, 'wb') as f:
            f.write(license_header)
            f.write(contents)

        return True
Exemplo n.º 27
0
    def compile(self, force=False):
        """Compiles the main less file in |self.main_source_file| into the
       |self.output| css file.

    Args:
      force: Generate the output even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        if not force and not _must_build(self.output, self.all_source_files):
            return True

        lessc = shakaBuildHelpers.get_node_binary('less', 'lessc')

        cmd_line = lessc + [self.main_source_file, self.output]

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Externs generation failed')
            return False

        return True
Exemplo n.º 28
0
    def generate(self, force=False):
        """Generates externs for the files in |self.source_files|.

    Args:
      force: Generate the output even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        if not force and not _must_build(self.output, self.source_files):
            return True

        extern_generator = _get_source_path('build/generateExterns.js')

        cmd_line = ['node', extern_generator, '--output', self.output]
        cmd_line += self.source_files

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Externs generation failed')
            return False

        return True
Exemplo n.º 29
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
Exemplo n.º 30
0
    def compile(self, options, force=False):
        """Builds the files in |self.source_files| using the given Closure
    command-line options.

    Args:
      options: An array of options to give to Closure.
      force: Generate the output even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        if not force:
            if self.timestamp_file:
                if not _must_build(self.timestamp_file, self.source_files):
                    return True
            else:
                if not _must_build(self.compiled_js_path, self.source_files):
                    return True

        jar = _get_source_path('third_party/closure/compiler.jar')

        output_options = []
        if self.output_compiled_bundle:
            output_options += [
                '--js_output_file',
                self.compiled_js_path,
            ]

            if self.add_source_map:
                source_base = _get_source_path('')

                # The source map below would be silently broken if the format of
                # source_base changed without updating the source_map_location_mapping
                # argument below.  This assertion ensures that this doesn't happen.
                assert source_base[-1] == '/', 'Source base format changed!'

                output_options += [
                    '--create_source_map',
                    self.source_map_path,
                    '--source_map_location_mapping',
                    source_base + '|../',
                ]

            if self.add_wrapper:
                output_options += self._prepare_wrapper()

        cmd_line = ['java', '-jar', jar] + output_options + options
        cmd_line += self.source_files

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Build failed')
            return False

        if self.output_compiled_bundle and self.add_source_map:
            # 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(self.compiled_js_path, 'a') as f:
                f.write('//# sourceMappingURL=%s' %
                        os.path.basename(self.source_map_path))

        if self.timestamp_file:
            _update_timestamp(self.timestamp_file)

        return True
Exemplo n.º 31
0
    def compile(self, options, force=False):
        """Builds the files in |self.source_files| using the given Closure
    command-line options.

    Args:
      options: An array of options to give to Closure.
      force: Generate the output even if the inputs have not changed.

    Returns:
      True on success; False on failure.
    """
        if not force:
            if self.timestamp_file:
                if not _must_build(self.timestamp_file, self.source_files):
                    return True
            else:
                if not _must_build(self.compiled_js_path, self.source_files):
                    return True

        jar = _get_source_path(
            'node_modules/google-closure-compiler-java/compiler.jar')

        output_options = []
        if self.output_compiled_bundle:
            output_options += [
                '--js_output_file',
                self.compiled_js_path,
            ]

            if self.add_source_map:
                source_base = _get_source_path('')

                output_options += [
                    '--create_source_map',
                    self.source_map_path,
                    # This uses a simple string replacement to create relative paths.
                    # "source|replacement".
                    '--source_map_location_mapping',
                    source_base + '|../',
                ]
                if shakaBuildHelpers.is_windows(
                ) or shakaBuildHelpers.is_cygwin():
                    output_options += [
                        # On Windows, the source map needs to use '/' for paths, so we
                        # need to have this mapping so it creates the correct relative
                        # paths.  For some reason, we still need the mapping above for
                        # other parts of the source map.
                        '--source_map_location_mapping',
                        source_base.replace('\\', '/') + '|../',
                    ]

            if self.add_wrapper:
                output_options += self._prepare_wrapper()

        cmd_line = ['java', '-jar', jar] + output_options + options
        cmd_line += self.source_files

        if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
            logging.error('Build failed')
            return False

        if self.output_compiled_bundle and self.add_source_map:
            # 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 shakaBuildHelpers.open_file(self.compiled_js_path, 'a') as f:
                f.write('//# sourceMappingURL=%s' %
                        os.path.basename(self.source_map_path))

        if self.timestamp_file:
            _update_timestamp(self.timestamp_file)

        return True