Commit 6ff391dc authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

checkperms: Add a --file-list option.

And use it from //PRESUBMIT.py instead of passing --file <file> for each
file that needs to be processed.

The idea is to read the list of files we want to process from a text file
instead of reading everything from the command-line.

web-platform-test imports were hitting an "argument list too long" error
because there's a particularly huge import with several directories being
renamed; at one point, we ended up with a command-line with ~260k
characters.

Bug: 780055, 780629
Change-Id: Ib1c8b902c42ade77ccbd2662905301d7f766f9d9
Reviewed-on: https://chromium-review.googlesource.com/751504Reviewed-by: default avatarAaron Gable <agable@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarQuinten Yearsley <qyearsley@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Raphael Kubo da Costa (rakuco) <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#515960}
parent 9c9c6f24
......@@ -926,16 +926,20 @@ def _CheckFilePermissions(input_api, output_api):
'tools', 'checkperms', 'checkperms.py')
args = [input_api.python_executable, checkperms_tool,
'--root', input_api.change.RepositoryRoot()]
for f in input_api.AffectedFiles():
# checkperms.py file/directory arguments must be relative to the repository.
args += ['--file', f.LocalPath()]
try:
input_api.subprocess.check_output(args)
return []
except input_api.subprocess.CalledProcessError as error:
return [output_api.PresubmitError(
'checkperms.py failed:',
long_text=error.output)]
with input_api.CreateTemporaryFile() as file_list:
for f in input_api.AffectedFiles():
# checkperms.py file/directory arguments must be relative to the
# repository.
file_list.write(f.LocalPath() + '\n')
file_list.close()
args += ['--file-list', file_list.name]
try:
input_api.subprocess.check_output(args)
return []
except input_api.subprocess.CalledProcessError as error:
return [output_api.PresubmitError(
'checkperms.py failed:',
long_text=error.output)]
def _CheckTeamTags(input_api, output_api):
......
......@@ -440,6 +440,10 @@ Examples:
'--file', action='append', dest='files',
help='Specifics a list of files to check the permissions of. Only these '
'files will be checked')
parser.add_option(
'--file-list',
help='Specifies a file with a list of files (one per line) to check the '
'permissions of. Only these files will be checked')
parser.add_option('--json', help='Path to JSON output file')
options, args = parser.parse_args()
......@@ -449,11 +453,18 @@ Examples:
if len(args) > 1:
parser.error('Too many arguments used')
if options.files and options.file_list:
parser.error('--file and --file-list are mutually exclusive options')
if options.root:
options.root = os.path.abspath(options.root)
if options.files:
errors = check_files(options.root, options.files)
elif options.file_list:
with open(options.file_list) as file_list:
files = file_list.read().splitlines()
errors = check_files(options.root, files)
else:
api = get_scm(options.root, options.bare)
start_dir = args[0] if args else api.root_dir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment