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') auth.add_auth_options(parser) options, args = parser.parse_args(args) auth_config = auth.extract_auth_config_from_options(options) # 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()) try: cl = git_cl.Changelist(auth_config=auth_config) change = cl.GetChange(git_common.get_or_create_merge_base(cl.GetBranch(), options.base_branch), None) files = [f.LocalPath() for f in change.AffectedFiles()] 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('Total errors found: %d\n' % cpplint._cpplint_state.error_count) if cpplint._cpplint_state.error_count != 0: return 1 return 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
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()) cl = git_cl.Changelist() base_branch = options.base_branch try: print('Running cpplint...') files = cl.GetAffectedFiles(git_common.get_or_create_merge_base(cl.GetBranch(), 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.replace('\\', '/')] + 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) # Run format checks upstream_branch = cl.GetUpstreamBranch() format_output = None if base_branch and not (base_branch in upstream_branch): print('Skipping clang/gn format check because base_branch is %s instead of %s' % (base_branch, upstream_branch)) else: format_output = RunFormatCheck(upstream_branch) finally: os.chdir(previous_cwd) if format_output: print(format_output) return 1 if cpplint._cpplint_state.error_count != 0: print('cpplint errors found: %d\n' % cpplint._cpplint_state.error_count) return 1 print('lint and format checks succeeded') return 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