Reland "Add export_targets.py to presubmit"
This is a reland of c40a21f353a2d0a37e83f3dce3a1c3096574be64
Changes: Fixed presubmit failing on Windows due to being unable
to find gn, fixed export_targets.py failing on Windows for
Googlers due to being unable to find Visual Studio files.
Original change's description:
> Add export_targets.py to presubmit
>
> Adds export_targets.py to run as part of presubmit in order to help
> prevent breaking Firefox with BUILD.gn changes.
>
> Bug: chromium:1003151
> Change-Id: I5a7ab00891cd7c094c797e6150f642f803a726b6
> Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1802038
> Commit-Queue: Jamie Madill <jmadill@chromium.org>
> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Bug: chromium:1003151
Change-Id: I321ade86f2d969601afb8e1ed61c36bf166887b5
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1842127
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index de83d12..25b7d87 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -7,7 +7,11 @@
for more details on the presubmit API built into depot_tools.
"""
-from subprocess import call
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
# Fragment of a regular expression that matches C++ and Objective-C++ implementation files.
_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
@@ -15,6 +19,13 @@
# Fragment of a regular expression that matches C++ and Objective-C++ header files.
_HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$'
+_PRIMARY_EXPORT_TARGETS = [
+ '//:libEGL',
+ '//:libGLESv1_CM',
+ '//:libGLESv2',
+ '//:translator',
+]
+
def _CheckChangeHasBugField(input_api, output_api):
"""Requires that the changelist have a Bug: field."""
@@ -102,12 +113,46 @@
return []
+def _CheckExportValidity(input_api, output_api):
+ outdir = tempfile.mkdtemp()
+ # shell=True is necessary on Windows, as otherwise subprocess fails to find
+ # either 'gn' or 'vpython3' even if they are findable via PATH.
+ use_shell = input_api.is_windows
+ try:
+ try:
+ subprocess.check_output(['gn', 'gen', outdir], shell=use_shell)
+ except subprocess.CalledProcessError as e:
+ return [
+ output_api.PresubmitError(
+ 'Unable to run gn gen for export_targets.py: %s' % e.output)
+ ]
+ export_target_script = os.path.join(input_api.PresubmitLocalPath(), 'scripts',
+ 'export_targets.py')
+ try:
+ subprocess.check_output(
+ ['vpython3', export_target_script, outdir] + _PRIMARY_EXPORT_TARGETS,
+ stderr=subprocess.STDOUT,
+ shell=use_shell)
+ except subprocess.CalledProcessError as e:
+ if input_api.is_committing:
+ return [output_api.PresubmitError('export_targets.py failed: %s' % e.output)]
+ return [
+ output_api.PresubmitPromptWarning(
+ 'export_targets.py failed, this may just be due to your local checkout: %s' %
+ e.output)
+ ]
+ return []
+ finally:
+ shutil.rmtree(outdir)
+
+
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CheckCodeGeneration(input_api, output_api))
results.extend(_CheckChangeHasBugField(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api))
results.extend(_CheckNewHeaderWithoutGnChange(input_api, output_api))
+ results.extend(_CheckExportValidity(input_api, output_api))
results.extend(
input_api.canned_checks.CheckPatchFormatted(
input_api, output_api, result_factory=output_api.PresubmitError))
@@ -121,5 +166,6 @@
input_api.canned_checks.CheckPatchFormatted(
input_api, output_api, result_factory=output_api.PresubmitError))
results.extend(_CheckChangeHasBugField(input_api, output_api))
+ results.extend(_CheckExportValidity(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api))
return results