Пример #1
0
def HasFormatErrors():
    print('Running git cl format and gn format')
    # For more options, see vendor/depot_tools/git_cl.py
    cmd = ['cl', 'format', '--diff']
    diff = git_cl.RunGit(cmd)
    print(diff)
    return bool(diff)
Пример #2
0
def HasFormatErrors(base_commit):
    print('Running git cl format and gn format on the diff from %s...' %
          base_commit)
    # For more options, see vendor/depot_tools/git_cl.py
    cmd = ['cl', 'format', '--diff']
    diff = git_cl.RunGit(cmd)
    print(diff)
    return bool(diff)
Пример #3
0
def HasFormatErrors():
  # For more options, see vendor/depot_tools/git_cl.py
  cmd = ['cl', 'format', '--diff']
  diff = git_cl.RunGit(cmd).encode('utf-8')
  if diff:
    # Verify that git cl format generates a diff
    if git_common.is_dirty_git_tree('git cl format'):
      # Skip verification if there are uncommitted changes
      print(diff)
      print('Format errors detected. Run npm format locally to fix.')
      return True
    git_cl.RunGit(['cl', 'format'])
    git_diff = git_common.run('diff').encode('utf-8')
    if git_diff:
      print(git_diff)
      print('Format errors have been auto-fixed. Please review and commit these changes if lint was run locally. Otherwise run npm format to fix.')
      return True
  return False
Пример #4
0
def RunFormatCheck(upstream_branch):  # pylint: disable=inconsistent-return-statements
    upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch])
    print('Running git cl/gn format on the diff from %s...' % upstream_commit)
    try:
        if HasFormatErrors():
            return 'Format check failed.'
    except Exception:
        e = traceback.format_exc()
        return 'Error running format check:\n' + e
Пример #5
0
def RunFormatCheck(upstream_branch):
  # XXX: upstream_branch is hard-coded in git_cl and is not changed
  # by the --base_branch arg
  upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch])
  print('Running git cl/gn format on the diff from %s...' % upstream_commit)
  try:
    if HasFormatErrors():
      return 'Format check failed.'
  except:
    e = traceback.format_exc()
    return 'Error running format check:\n' + e
Пример #6
0
def main(args):
    """Runs clang-format and gn format on the current changelist."""
    parser = git_cl.OptionParser()
    options, args = parser.parse_args(args)

    # Change the current working directory before calling so that it
    # shows the correct base.
    settings = git_cl.settings
    previous_cwd = os.getcwd()
    os.chdir(settings.GetRoot())
    try:
        cmd = ['cl', 'format', '--full'] + args
        git_cl.RunGit(cmd)
    except:
        e = sys.exc_info()[1]
        print('Could not run format: %s' % e.message)
        return 1
    finally:
        os.chdir(previous_cwd)
    print('Formatting done.')
    return 0
Пример #7
0
def main(args):
    """Runs cpplint on the current changelist."""
    """Adapted from git_cl.py CMDlint """
    parser = git_cl.OptionParser()
    parser.add_option(
        '--filter',
        action='append',
        metavar='-x,+y',
        help='Comma-separated list of cpplint\'s category-filters')
    parser.add_option('--project_root')
    parser.add_option('--base_branch')
    options, args = parser.parse_args(args)

    # Access to a protected member _XX of a client class
    # pylint: disable=protected-access
    try:
        import cpplint
        import cpplint_chromium
    except ImportError:
        print(
            'Your depot_tools is missing cpplint.py and/or cpplint_chromium.py.'
        )
        return 1

    # Change the current working directory before calling lint so that it
    # shows the correct base.
    settings = git_cl.settings
    previous_cwd = os.getcwd()
    os.chdir(settings.GetRoot())

    exit_code = 0

    # Check for clang/gn format errors.
    cl = git_cl.Changelist()
    upstream_branch = cl.GetUpstreamBranch()
    upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch])
    try:
        if HasFormatErrors(upstream_commit):
            print('Format check failed. Run npm format to fix.')
            exit_code = 1
    except:
        e = sys.exc_info()[1]
        print('Error running format check: %s' % e.info)
        exit_code = 1

    if exit_code == 0:
        print('Format check succeeded.')

    print('Running cpplint...')
    try:
        files = cl.GetAffectedFiles(
            git_common.get_or_create_merge_base(cl.GetBranch(),
                                                options.base_branch))
        if not files:
            print('Cannot lint an empty CL')
            return 0

        # Process cpplints arguments if any.
        command = args + files
        if options.filter:
            command = ['--filter=' + ','.join(options.filter)] + command
        if options.project_root:
            command = ['--project_root=' + options.project_root] + command
        filenames = cpplint.ParseArguments(command)

        white_regex = re.compile(settings.GetLintRegex())
        black_regex = re.compile(settings.GetLintIgnoreRegex())
        extra_check_functions = [
            cpplint_chromium.CheckPointerDeclarationWhitespace
        ]
        for filename in filenames:
            if white_regex.match(filename):
                if black_regex.match(filename):
                    print('Ignoring file %s' % filename)
                else:
                    cpplint.ProcessFile(filename,
                                        cpplint._cpplint_state.verbose_level,
                                        extra_check_functions)
            else:
                print('Skipping file %s' % filename)
    finally:
        os.chdir(previous_cwd)
    print('cpplint errors found: %d\n' % cpplint._cpplint_state.error_count)
    if cpplint._cpplint_state.error_count != 0:
        return 1
    return exit_code