GN: avoid absolute paths and add PRESUBMIT
Absolute GN paths create problems when perfetto is embedded
in other projects (especially V8).
Sometimes they sneak in, mostly from new contributors.
This adds a PRESUBMIT that warns about it.
I fixed existing places and ran gn format on everything.
Change-Id: Ic3dd7747e3a6b5d4b59b8e46465d9c1f4146bcd4
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index b889b79..5d92c14 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -85,6 +85,7 @@
results += RunAndReportIfLong(CheckTestData, input, output)
results += RunAndReportIfLong(CheckAmalgamatedPythonTools, input, output)
results += RunAndReportIfLong(CheckChromeStdlib, input, output)
+ results += RunAndReportIfLong(CheckAbsolutePathsInGn, input, output)
return results
@@ -434,3 +435,29 @@
' to update them.')
]
return []
+
+
+def CheckAbsolutePathsInGn(input_api, output_api):
+
+ def file_filter(x):
+ return input_api.FilterSourceFile(
+ x,
+ files_to_check=[r'.*\.gni?$'],
+ files_to_skip=['^.gn$', '^gn/.*', '^buildtools/.*'])
+
+ error_lines = []
+ for f in input_api.AffectedSourceFiles(file_filter):
+ for line_number, line in f.ChangedContents():
+ if input_api.re.search(r'(^\s*[#])|([#]\s*nogncheck)', line):
+ continue # Skip comments and '# nogncheck' lines
+ if input_api.re.search(r'"//[^"]', line):
+ error_lines.append(' %s:%s: %s' %
+ (f.LocalPath(), line_number, line.strip()))
+
+ if len(error_lines) == 0:
+ return []
+ return [
+ output_api.PresubmitError(
+ 'Use relative paths in GN rather than absolute:\n' +
+ '\n'.join(error_lines))
+ ]