Bug 1538760 - Parse all output from checkstyle. r=nalexander

Previously |mach android checkstyle| would only parse one file output form
checkstyle (the app one).

This change makes it so it parses all files, also it reduces noise by
suppressing most output when the test passes.

Differential Revision: https://phabricator.services.mozilla.com/D24737

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2019-04-01 16:20:28 +00:00
parent ad9b0890dd
commit 0578d20e29
2 changed files with 45 additions and 22 deletions

View File

@ -242,6 +242,25 @@ def gradle_android_checkstyle_tasks(build_config):
set_config('GRADLE_ANDROID_CHECKSTYLE_TASKS', gradle_android_checkstyle_tasks)
@depends(gradle_android_build_config)
def gradle_android_checkstyle_output_files(build_config):
def uncapitalize(s):
if s:
return s[0].lower() + s[1:]
else:
return s
variant = uncapitalize(build_config.geckoview.variant.name)
'''Output folder for checkstyle'''
return [
'gradle/build/mobile/android/geckoview/reports/checkstyle/{}.xml'.format(variant),
'gradle/build/mobile/android/app/reports/checkstyle/checkstyle.xml',
]
set_config('GRADLE_ANDROID_CHECKSTYLE_OUTPUT_FILES', gradle_android_checkstyle_output_files)
@depends(gradle_android_build_config)
def gradle_android_findbugs_tasks(build_config):
'''Gradle tasks run by |mach android findbugs|.'''

View File

@ -276,46 +276,40 @@ class MachCommands(MachCommandBase):
return ret
@SubCommand('android', 'checkstyle',
"""Run Android checkstyle.
See https://developer.mozilla.org/en-US/docs/Mozilla/Android-specific_test_suites#android-checkstyle""") # NOQA: E501
@CommandArgument('args', nargs=argparse.REMAINDER)
def android_checkstyle(self, args):
ret = self.gradle(self.substs['GRADLE_ANDROID_CHECKSTYLE_TASKS'] +
args, verbose=True)
def _parse_checkstyle_output(self, output_path):
ret = 0
# Checkstyle produces both HTML and XML reports. Visit the
# XML report(s) to report errors and link to the HTML
# report(s) for human consumption.
import xml.etree.ElementTree as ET
f = open(os.path.join(self.topobjdir,
'gradle/build/mobile/android/app/reports/checkstyle/checkstyle.xml'),
'rt')
output_absolute_path = os.path.join(self.topobjdir, output_path)
f = open(output_absolute_path, 'rt')
tree = ET.parse(f)
root = tree.getroot()
# Now the reports, linkified.
root_url = self._root_url(
report_xml = self._root_url(
artifactdir='public/android/checkstyle',
objdir='gradle/build/mobile/android/app/reports/checkstyle')
# Log reports for Tree Herder "Job Details".
print('TinderboxPrint: report<br/><a href="{}/checkstyle.html">HTML checkstyle report</a>, visit "Inspect Task" link for details'.format(root_url)) # NOQA: E501
print('TinderboxPrint: report<br/><a href="{}/checkstyle.xml">XML checkstyle report</a>, visit "Inspect Task" link for details'.format(root_url)) # NOQA: E501
objdir=output_absolute_path)
report_html = self._root_url(
artifactdir='public/android/checkstyle',
objdir=os.path.splitext(output_absolute_path)[0] + '.html')
# And make the report display as soon as possible.
if root.findall('file/error'):
ret |= 1
if ret:
print('TEST-UNEXPECTED-FAIL | android-checkstyle | Checkstyle rule violations were found. See the report at: {}/checkstyle.html'.format(root_url)) # NOQA: E501
# Log reports for Tree Herder "Job Details".
print('TinderboxPrint: report<br/><a href="{}">HTML checkstyle report</a>, visit "Inspect Task" link for details'.format(report_xml)) # NOQA: E501
print('TinderboxPrint: report<br/><a href="{}">XML checkstyle report</a>, visit "Inspect Task" link for details'.format(report_html)) # NOQA: E501
print('TEST-UNEXPECTED-FAIL | android-checkstyle | Checkstyle rule violations were found. See the report at: {}'.format(report_html)) # NOQA: E501
print('SUITE-START | android-checkstyle')
for file in root.findall('file'):
name = file.get('name')
print('TEST-START | {}'.format(name))
error_count = 0
for error in file.findall('error'):
# There's no particular advantage to formatting the
@ -326,8 +320,18 @@ class MachCommands(MachCommandBase):
print('TEST-UNEXPECTED-FAIL | {}'.format(line))
error_count += 1
if not error_count:
print('TEST-PASS | {}'.format(name))
return ret
@SubCommand('android', 'checkstyle',
"""Run Android checkstyle.
See https://developer.mozilla.org/en-US/docs/Mozilla/Android-specific_test_suites#android-checkstyle""") # NOQA: E501
@CommandArgument('args', nargs=argparse.REMAINDER)
def android_checkstyle(self, args):
ret = self.gradle(self.substs['GRADLE_ANDROID_CHECKSTYLE_TASKS'] +
args, verbose=True)
print('SUITE-START | android-checkstyle')
for filePath in self.substs['GRADLE_ANDROID_CHECKSTYLE_OUTPUT_FILES']:
ret |= self._parse_checkstyle_output(filePath)
print('SUITE-END | android-checkstyle')
return ret