Exemple #1
0
def check_complete(_):
    """Checks whether the 'complete' build references every file.

  This is used by the build script to ensure that every file is included in at
  least one build type.

  Returns:
    True on success, False on failure.
  """
    logging.info('Checking that the build files are complete...')

    complete_build = complete_build_files()
    if not complete_build:
        return False

    base = shakaBuildHelpers.get_source_base()
    all_files = set()
    all_files.update(shakaBuildHelpers.get_all_js_files('lib'))
    all_files.update(shakaBuildHelpers.get_all_js_files('ui'))
    all_files.update(shakaBuildHelpers.get_all_js_files('third_party'))
    missing_files = all_files - complete_build

    if missing_files:
        logging.error('There are files missing from the complete build:')
        for missing in missing_files:
            # Convert to a path relative to source base.
            logging.error('  ' + os.path.relpath(missing, base))
        return False
    return True
Exemple #2
0
    def build_library(self, name, locales, force, is_debug):
        """Builds Shaka Player using the files in |self.include|.

    Args:
      name: The name of the build.
      locales: A list of strings of locale identifiers.
      force: True to rebuild, False to ignore if no changes are detected.
      is_debug: True to compile for debugging, false for release.

    Returns:
      True on success; False on failure.
    """
        self.add_closure()
        if not self.add_core():
            return False
        if self.has_ui():
            self.generate_localizations(locales, force)

        if is_debug:
            name += '.debug'

        build_name = 'shaka-player.' + name
        closure = compiler.ClosureCompiler(self.include, build_name)

        closure_opts = common_closure_opts + common_closure_defines
        if is_debug:
            closure_opts += debug_closure_opts + debug_closure_defines
        else:
            closure_opts += release_closure_opts + release_closure_defines

        if not closure.compile(closure_opts, force):
            return False

        # Don't pass local node modules to the extern generator.  But don't simply
        # exclude the string 'node_modules', either, since Shaka Player could be
        # rebuilt after installing it as a node module.
        node_modules_path = os.path.join(shakaBuildHelpers.get_source_base(),
                                         'node_modules')
        local_include = set(
            [f for f in self.include if node_modules_path not in f])
        extern_generator = compiler.ExternGenerator(local_include, build_name)

        if not extern_generator.generate(force):
            return False

        generated_externs = [extern_generator.output]
        shaka_externs = shakaBuildHelpers.get_all_js_files('externs')
        if self.has_ui():
            shaka_externs += shakaBuildHelpers.get_all_js_files('ui/externs')
        ts_def_generator = compiler.TsDefGenerator(
            generated_externs + shaka_externs, build_name)

        if not ts_def_generator.generate(force):
            return False

        return True
Exemple #3
0
def check_spelling(_):
    """Checks that source files don't have any common misspellings."""
    logging.info('Checking for common misspellings...')

    complete_build = complete_build_files()
    if not complete_build:
        return False

    base = shakaBuildHelpers.get_source_base()
    complete_build.update(shakaBuildHelpers.get_all_js_files('test'))
    complete_build.update(shakaBuildHelpers.get_all_js_files('demo'))
    complete_build.update(shakaBuildHelpers.get_all_js_files('externs'))
    complete_build.update(
        shakaBuildHelpers.get_all_files(os.path.join(base, 'build'),
                                        re.compile(r'.*\.(js|py)$')))

    with shakaBuildHelpers.open_file(
            os.path.join(base, 'build', 'misspellings.txt')) as f:
        misspellings = ast.literal_eval(f.read())
    has_error = False
    for path in complete_build:
        with shakaBuildHelpers.open_file(path) as f:
            for i, line in enumerate(f):
                for regex, replace_pattern in misspellings.items():
                    for match in re.finditer(regex, line):
                        repl = match.expand(replace_pattern).lower()
                        if match.group(0).lower() == repl:
                            continue  # No-op suggestion

                        if not has_error:
                            logging.error(
                                'The following file(s) have misspellings:')
                        logging.error(
                            '  %s:%d:%d: Did you mean %r?' % (os.path.relpath(
                                path, base), i + 1, match.start() + 1, repl))
                        has_error = True

    return not has_error
Exemple #4
0
    def __init__(self, config_path):
        self.config_path = config_path
        self.source_files = shakaBuildHelpers.get_all_files(
            _get_source_path('docs/tutorials'))
        self.source_files += shakaBuildHelpers.get_all_files(
            _get_source_path('docs/jsdoc-template'))
        self.source_files += [
            _get_source_path('docs/jsdoc-plugin.js'),
            _get_source_path('docs/api-mainpage.md'),
        ]

        # Just one of many output files, used to check the freshness of the docs.
        self.output = _get_source_path('docs/api/index.html')

        # To avoid getting out of sync with the source files jsdoc actually reads,
        # parse the config file and locate all source files based on that.
        with open(self.config_path, 'r') as f:
            config = json.load(f)
        for path in config['source']['include']:
            full_path = _get_source_path(path)
            self.source_files += shakaBuildHelpers.get_all_js_files(full_path)
Exemple #5
0
def check_eslint_disable(_):
    """Checks that source files correctly use "eslint-disable".

  - Rules are disabled/enabled in nested blocks.
  - Rules are not disabled multiple times.
  - Rules are enabled again by the end of the file.

  Returns:
    True on success, False on failure.
  """
    logging.info('Checking correct usage of eslint-disable...')

    complete_build = complete_build_files()
    if not complete_build:
        return False

    base = shakaBuildHelpers.get_source_base()
    complete_build.update(shakaBuildHelpers.get_all_js_files('test'))
    complete_build.update(shakaBuildHelpers.get_all_js_files('demo'))

    has_error = False
    for path in complete_build:
        # The stack of rules that are disabled.
        disabled = []

        with shakaBuildHelpers.open_file(path, 'r') as f:
            rel_path = os.path.relpath(path, base)
            for i, line in enumerate(f):
                match = re.match(
                    r'^\s*/\* eslint-(disable|enable) ([\w-]*) \*/$', line)
                if match:
                    if match.group(1) == 'disable':
                        # |line| disables a rule; validate it isn't already disabled.
                        if match.group(2) in disabled:
                            logging.error('%s:%d Rule %r already disabled',
                                          rel_path, i + 1, match.group(2))
                            has_error = True
                        else:
                            disabled.append(match.group(2))
                    else:
                        # |line| enabled a rule; validate it's already disabled and it's
                        # enabled in the correct order.
                        if not disabled or match.group(2) not in disabled:
                            logging.error("%s:%d Rule %r isn't disabled",
                                          rel_path, i + 1, match.group(2))
                            has_error = True
                        elif disabled[-1] != match.group(2):
                            logging.error('%s:%d Rule %r enabled out of order',
                                          rel_path, i + 1, match.group(2))
                            has_error = True
                            disabled = [
                                x for x in disabled if x != match.group(2)
                            ]
                        else:
                            disabled = disabled[:-1]
                else:
                    # |line| is not a normal eslint-disable or eslint-enable line.  Verify
                    # we don't have this text elsewhere where eslint will ignore it.
                    if re.search(r'eslint-(disable|enable)(?!-(next-)?line)',
                                 line):
                        logging.error('%s:%d Invalid eslint-disable', rel_path,
                                      i + 1)
                        has_error = True

            for rule in disabled:
                logging.error('%s:%d Rule %r still disabled at end of file',
                              rel_path, i + 1, rule)
                has_error = True

    return not has_error
Exemple #6
0
 def add_closure(self):
     """Adds the closure library and externs."""
     # Add externs and closure dependencies.
     self.include |= set([shakaBuildHelpers.get_closure_base_js_path()] +
                         shakaBuildHelpers.get_all_js_files('externs'))