Add a PRESUBMIT.py script to check pregenerated files
This adds a PRESUBMIT.py script that calls the existing go script to
check pregenerated files. The goal is to catch errors due to
missing/out-of-date pregenerated files earlier, upon commit or upload.
This works with the presubmit API provided by depot_tools, and will only
help you if you use depot_tools to manage local boringssl changes via
`git cl upload`.
(We already run the pregenerate script on CQ via the boringssl.py
recipe. If we had a dedicated builder to run PRESUBMIT.py files on
boringssl CQ via the presubmit recipe (which we don't yet), this script
would also help catch the errors on dry run even earlier, even for folks
not using depot_tools.)
Output looks something like this:
Running presubmit commit checks on branch my-branch-name ...
** Presubmit ERRORS: 1 **
Found out-of-date generated files. Run `go run ./util/pregenerate` to update them.
Error in file "gen/crypto/chacha-armv4-linux.S": missing file
Error in file "gen/crypto/aes128gcmsiv-x86_64-linux.S": file out of date
Error: some files had errors
exit status 1
Presubmit checks took 1.7s to calculate.
There were presubmit errors.
Was the presubmit check useful? If not, run "git cl presubmit -v"
to figure out which PRESUBMIT.py was run, then run "git blame"
on the file to figure out who to ask for help.
Change-Id: Iad268831ad7353eb15c796906b3f73c12ab8cf80
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/82867
Auto-Submit: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
new file mode 100644
index 0000000..4f13a4e
--- /dev/null
+++ b/PRESUBMIT.py
@@ -0,0 +1,53 @@
+# Copyright 2025 The BoringSSL Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Presubmit checks for BoringSSL.
+
+Run by the presubmit API in depot_tools, e.g. by running `git cl presubmit`.
+"""
+
+PRESUBMIT_VERSION = '2.0.0'
+USE_PYTHON3 = True
+
+
+def CheckPregeneratedFiles(input_api, output_api):
+ """Checks that pregenerated files are properly updated."""
+ # TODO(chlily): Make this compatible with the util/bot environment for CI/CQ.
+ try:
+ # Check that `go` is available on the $PATH.
+ input_api.subprocess.check_call(['go', 'version'],
+ stdout=input_api.subprocess.PIPE,
+ stderr=input_api.subprocess.PIPE)
+ except input_api.subprocess.CalledProcessError as e:
+ return [
+ output_api.PresubmitPromptOrNotify(f'Could not run `go`: {e}')
+ ]
+
+ pregenerate_script_path = input_api.os_path.join(
+ input_api.change.RepositoryRoot(), 'util', 'pregenerate')
+ try:
+ out, retcode = input_api.subprocess.communicate(
+ ['go', 'run', pregenerate_script_path, '-check'],
+ stdout=input_api.subprocess.PIPE,
+ stderr=input_api.subprocess.PIPE)
+ if retcode:
+ bad = out[1].decode("utf-8").splitlines()
+ return [
+ output_api.PresubmitError(
+ ("Found out-of-date generated files. "
+ "Run `go run ./util/pregenerate` to update them."), bad)
+ ]
+ except input_api.subprocess.CalledProcessError as e:
+ return [output_api.PresubmitError(f'Could not run go script: {e}')]
+ return [] # Check passed.