0

Allow use of checkstyle outside of main PRESUBMIT.py

This commit allows the use of checkstyle outside of the main PRESUBMIT
script in src. Since checkstyle can possibly be called from a subfolder
of src the absolute path to the java files are used instead of relative
to src.

We also honor the EXCLUDED_PATH blacklist for Java files.

BUG=446633

Review URL: https://codereview.chromium.org/839583006

Cr-Commit-Position: refs/heads/master@{#312287}
This commit is contained in:
davileen
2015-01-20 14:30:09 -08:00
committed by Commit bot
parent 620cd76da6
commit 72d7653361
2 changed files with 6 additions and 4 deletions
PRESUBMIT.py
tools/android/checkstyle

@ -1217,7 +1217,8 @@ def _CheckJavaStyle(input_api, output_api):
sys.path = original_sys_path
return checkstyle.RunCheckstyle(
input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml',
black_list=_EXCLUDED_PATHS)
def _CheckForCopyrightedCode(input_api, output_api):

@ -16,14 +16,15 @@ CHECKSTYLE_ROOT = os.path.join(CHROMIUM_SRC, 'third_party', 'checkstyle',
'checkstyle-6.1-all.jar')
def RunCheckstyle(input_api, output_api, style_file):
def RunCheckstyle(input_api, output_api, style_file, black_list=None):
if not os.path.exists(style_file):
file_error = (' Java checkstyle configuration file is missing: '
+ style_file)
return [output_api.PresubmitError(file_error)]
# Filter out non-Java files and files that were deleted.
java_files = [x.LocalPath() for x in input_api.AffectedFiles(False, False)
java_files = [x.AbsoluteLocalPath() for x in input_api.AffectedSourceFiles(
lambda f: input_api.FilterSourceFile(f, black_list=black_list))
if os.path.splitext(x.LocalPath())[1] == '.java']
if not java_files:
return []
@ -36,7 +37,7 @@ def RunCheckstyle(input_api, output_api, style_file):
CHECKSTYLE_ROOT,
'com.puppycrawl.tools.checkstyle.Main', '-c',
style_file, '-f', 'xml'] + java_files,
stdout=subprocess.PIPE, env=checkstyle_env)
stdout=subprocess.PIPE, env=checkstyle_env)
stdout, _ = check.communicate()
except OSError as e:
import errno