Add presubmit to prevent modifying the chrome stdlib
This presubmit fails for changes to the src/trace_processor/perfetto_sql/stdlib/chrome or test/data/chrome directories. This because the source of truth lives in Chromium so any changes should be made there instead.
It allows CLs from the Copybara service, which specifies the COPYBARA_IMPORT flag in the CL description.
Manual rolls can still be done with the CHROME_STDLIB_MANUAL_ROLL flag.
Bug: b/324211825
Change-Id: I8f2d44b4f65e2e79327fa91dd4bdd014ce6ccb17
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index ba705eb..b889b79 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -84,6 +84,7 @@
results += RunAndReportIfLong(CheckSqlMetrics, input, output)
results += RunAndReportIfLong(CheckTestData, input, output)
results += RunAndReportIfLong(CheckAmalgamatedPythonTools, input, output)
+ results += RunAndReportIfLong(CheckChromeStdlib, input, output)
return results
@@ -382,6 +383,37 @@
return []
+def CheckChromeStdlib(input_api, output_api):
+ stdlib_paths = ("src/trace_processor/perfetto_sql/stdlib/chrome/",
+ "test/data/chrome/",
+ "test/trace_processor/diff_tests/stdlib/chrome/")
+
+ def chrome_stdlib_file_filter(x):
+ return input_api.FilterSourceFile(x, files_to_check=stdlib_paths)
+
+ # Only check chrome stdlib files
+ if not any(input_api.AffectedFiles(file_filter=chrome_stdlib_file_filter)):
+ return []
+
+ # Always allow Copybara service to make changes to chrome stdlib
+ if input_api.change.COPYBARA_IMPORT:
+ return []
+
+ if input_api.change.CHROME_STDLIB_MANUAL_ROLL:
+ return []
+
+ message = (
+ 'Files under {0} and {1} '
+ 'are rolled from the Chromium repository by a '
+ 'Copybara service.\nYou should not modify these in '
+ 'the Perfetto repository, please make your changes '
+ 'in Chromium instead.\n'
+ 'If you want to do a manual roll, you must specify '
+ 'CHROME_STDLIB_MANUAL_ROLL=<reason> in the CL description.').format(
+ *stdlib_paths)
+ return [output_api.PresubmitError(message)]
+
+
def CheckAmalgamatedPythonTools(input_api, output_api):
# The script invocation doesn't work on Windows.
if input_api.is_windows: