xref: /aosp_15_r20/tools/repohooks/README.md (revision d68f33bc6fb0cc2476107c2af0573a2f5a63dfc1)
1*d68f33bcSAndroid Build Coastguard Worker# AOSP Preupload Hooks
2*d68f33bcSAndroid Build Coastguard Worker
3*d68f33bcSAndroid Build Coastguard WorkerThis repo holds hooks that get run by repo during the upload phase.  They
4*d68f33bcSAndroid Build Coastguard Workerperform various checks automatically such as running linters on your code.
5*d68f33bcSAndroid Build Coastguard Worker
6*d68f33bcSAndroid Build Coastguard WorkerNote: Currently all hooks are disabled by default.  Each repo must explicitly
7*d68f33bcSAndroid Build Coastguard Workerturn on any hook it wishes to enforce.
8*d68f33bcSAndroid Build Coastguard Worker
9*d68f33bcSAndroid Build Coastguard Worker[TOC]
10*d68f33bcSAndroid Build Coastguard Worker
11*d68f33bcSAndroid Build Coastguard Worker## Usage
12*d68f33bcSAndroid Build Coastguard Worker
13*d68f33bcSAndroid Build Coastguard WorkerNormally these execute automatically when you run `repo upload`.  If you want to
14*d68f33bcSAndroid Build Coastguard Workerrun them by hand, you can execute `pre-upload.py` directly.  By default, that
15*d68f33bcSAndroid Build Coastguard Workerwill scan the active repo and process all commits that haven't yet been merged.
16*d68f33bcSAndroid Build Coastguard WorkerSee its help for more info.
17*d68f33bcSAndroid Build Coastguard Worker
18*d68f33bcSAndroid Build Coastguard Worker### Bypassing
19*d68f33bcSAndroid Build Coastguard Worker
20*d68f33bcSAndroid Build Coastguard WorkerSometimes you might want to bypass the upload checks.  While this is **strongly
21*d68f33bcSAndroid Build Coastguard Workerdiscouraged** (often failures you add will affect others and block them too),
22*d68f33bcSAndroid Build Coastguard Workersometimes there are valid reasons for this.  You can simply use the option
23*d68f33bcSAndroid Build Coastguard Worker`--no-verify` when running `repo upload` to skip all upload checks.  This will
24*d68f33bcSAndroid Build Coastguard Workerskip **all** checks and not just specific ones.  It should be used only after
25*d68f33bcSAndroid Build Coastguard Workerhaving run & evaluated the upload output previously.
26*d68f33bcSAndroid Build Coastguard Worker
27*d68f33bcSAndroid Build Coastguard Worker# Config Files
28*d68f33bcSAndroid Build Coastguard Worker
29*d68f33bcSAndroid Build Coastguard WorkerThere are two types of config files:
30*d68f33bcSAndroid Build Coastguard Worker* Repo project-wide settings (e.g. all of AOSP).  These set up defaults for all
31*d68f33bcSAndroid Build Coastguard Worker  projects that are checked out via a single manifest.
32*d68f33bcSAndroid Build Coastguard Worker* Project-local settings (e.g. a single .git repo).  These control settings for
33*d68f33bcSAndroid Build Coastguard Worker  the local project you're working on.
34*d68f33bcSAndroid Build Coastguard Worker
35*d68f33bcSAndroid Build Coastguard WorkerThe merging of these config files control the hooks/checks that get run when
36*d68f33bcSAndroid Build Coastguard Workerrunning `repo upload`.
37*d68f33bcSAndroid Build Coastguard Worker
38*d68f33bcSAndroid Build Coastguard Worker## GLOBAL-PREUPLOAD.cfg
39*d68f33bcSAndroid Build Coastguard Worker
40*d68f33bcSAndroid Build Coastguard WorkerThese are the manifest-wide defaults and can be located in two places:
41*d68f33bcSAndroid Build Coastguard Worker* `.repo/manifests/GLOBAL-PREUPLOAD.cfg`: The manifest git repo.
42*d68f33bcSAndroid Build Coastguard Worker  Simply check this in to the manifest git repo and you're done.
43*d68f33bcSAndroid Build Coastguard Worker* `GLOBAL-PREUPLOAD.cfg`: The top level of the repo checkout.
44*d68f33bcSAndroid Build Coastguard Worker  For manifests that don't have a project checked out at the top level,
45*d68f33bcSAndroid Build Coastguard Worker  you can use repo's `<copyfile>` directive.
46*d68f33bcSAndroid Build Coastguard Worker
47*d68f33bcSAndroid Build Coastguard WorkerThese config files will be loaded first before stacking `PREUPLOAD.cfg`
48*d68f33bcSAndroid Build Coastguard Workersettings on top.
49*d68f33bcSAndroid Build Coastguard Worker
50*d68f33bcSAndroid Build Coastguard Worker## PREUPLOAD.cfg
51*d68f33bcSAndroid Build Coastguard Worker
52*d68f33bcSAndroid Build Coastguard WorkerThis file is checked in the top of a specific git repository.  Stacking them
53*d68f33bcSAndroid Build Coastguard Workerin subdirectories (to try and override parent settings) is not supported.
54*d68f33bcSAndroid Build Coastguard Worker
55*d68f33bcSAndroid Build Coastguard Worker## Example
56*d68f33bcSAndroid Build Coastguard Worker
57*d68f33bcSAndroid Build Coastguard Worker```
58*d68f33bcSAndroid Build Coastguard Worker# Per-project `repo upload` hook settings.
59*d68f33bcSAndroid Build Coastguard Worker# https://android.googlesource.com/platform/tools/repohooks
60*d68f33bcSAndroid Build Coastguard Worker
61*d68f33bcSAndroid Build Coastguard Worker[Options]
62*d68f33bcSAndroid Build Coastguard Workerignore_merged_commits = true
63*d68f33bcSAndroid Build Coastguard Worker
64*d68f33bcSAndroid Build Coastguard Worker[Hook Scripts]
65*d68f33bcSAndroid Build Coastguard Workername = script --with args ${PREUPLOAD_FILES}
66*d68f33bcSAndroid Build Coastguard Worker
67*d68f33bcSAndroid Build Coastguard Worker[Builtin Hooks]
68*d68f33bcSAndroid Build Coastguard Workercpplint = true
69*d68f33bcSAndroid Build Coastguard Worker
70*d68f33bcSAndroid Build Coastguard Worker[Builtin Hooks Options]
71*d68f33bcSAndroid Build Coastguard Workercpplint = --filter=-x ${PREUPLOAD_FILES}
72*d68f33bcSAndroid Build Coastguard Worker
73*d68f33bcSAndroid Build Coastguard Worker[Tool Paths]
74*d68f33bcSAndroid Build Coastguard Workerclang-format = /usr/bin/clang-format
75*d68f33bcSAndroid Build Coastguard Worker```
76*d68f33bcSAndroid Build Coastguard Worker
77*d68f33bcSAndroid Build Coastguard Worker## Environment
78*d68f33bcSAndroid Build Coastguard Worker
79*d68f33bcSAndroid Build Coastguard WorkerHooks are executed in the top directory of the git repository.  All paths should
80*d68f33bcSAndroid Build Coastguard Workergenerally be relative to that point.
81*d68f33bcSAndroid Build Coastguard Worker
82*d68f33bcSAndroid Build Coastguard WorkerA few environment variables are set so scripts don't need to discover things.
83*d68f33bcSAndroid Build Coastguard Worker
84*d68f33bcSAndroid Build Coastguard Worker* `REPO_PROJECT`: The name of the project.
85*d68f33bcSAndroid Build Coastguard Worker   e.g. `platform/tools/repohooks`
86*d68f33bcSAndroid Build Coastguard Worker* `REPO_PATH`: The path to the project relative to the root.
87*d68f33bcSAndroid Build Coastguard Worker   e.g. `tools/repohooks`
88*d68f33bcSAndroid Build Coastguard Worker* `REPO_REMOTE`: The name of the git remote.
89*d68f33bcSAndroid Build Coastguard Worker   e.g. `aosp`.
90*d68f33bcSAndroid Build Coastguard Worker* `REPO_LREV`: The name of the remote revision, translated to a local tracking
91*d68f33bcSAndroid Build Coastguard Worker   branch. This is typically latest commit in the remote-tracking branch.
92*d68f33bcSAndroid Build Coastguard Worker   e.g. `ec044d3e9b608ce275f02092f86810a3ba13834e`
93*d68f33bcSAndroid Build Coastguard Worker* `REPO_RREV`: The remote revision.
94*d68f33bcSAndroid Build Coastguard Worker   e.g. `master`
95*d68f33bcSAndroid Build Coastguard Worker* `PREUPLOAD_COMMIT`: The commit that is currently being checked.
96*d68f33bcSAndroid Build Coastguard Worker   e.g. `1f89dce0468448fa36f632d2fc52175cd6940a91`
97*d68f33bcSAndroid Build Coastguard Worker
98*d68f33bcSAndroid Build Coastguard Worker## Placeholders
99*d68f33bcSAndroid Build Coastguard Worker
100*d68f33bcSAndroid Build Coastguard WorkerA few keywords are recognized to pass down settings.  These are **not**
101*d68f33bcSAndroid Build Coastguard Workerenvironment variables, but are expanded inline.  Files with whitespace and
102*d68f33bcSAndroid Build Coastguard Workersuch will be expanded correctly via argument positions, so do not try to
103*d68f33bcSAndroid Build Coastguard Workerforce your own quote handling.
104*d68f33bcSAndroid Build Coastguard Worker
105*d68f33bcSAndroid Build Coastguard Worker* `${PREUPLOAD_FILES}`: List of files to operate on.
106*d68f33bcSAndroid Build Coastguard Worker* `${PREUPLOAD_FILES_PREFIXED}`: A list of files to operate on.
107*d68f33bcSAndroid Build Coastguard Worker   Any string preceding/attached to the keyword ${PREUPLOAD_FILES_PREFIXED}
108*d68f33bcSAndroid Build Coastguard Worker   will be repeated for each file automatically. If no string is preceding/attached
109*d68f33bcSAndroid Build Coastguard Worker   to the keyword, the previous argument will be repeated before each file.
110*d68f33bcSAndroid Build Coastguard Worker* `${PREUPLOAD_COMMIT}`: Commit hash.
111*d68f33bcSAndroid Build Coastguard Worker* `${PREUPLOAD_COMMIT_MESSAGE}`: Commit message.
112*d68f33bcSAndroid Build Coastguard Worker
113*d68f33bcSAndroid Build Coastguard WorkerSome variables are available to make it easier to handle OS differences.  These
114*d68f33bcSAndroid Build Coastguard Workerare automatically expanded for you:
115*d68f33bcSAndroid Build Coastguard Worker
116*d68f33bcSAndroid Build Coastguard Worker* `${REPO_PATH}`: The path to the project relative to the root.
117*d68f33bcSAndroid Build Coastguard Worker  e.g. `tools/repohooks`
118*d68f33bcSAndroid Build Coastguard Worker* `${REPO_PROJECT}`: The name of the project.
119*d68f33bcSAndroid Build Coastguard Worker  e.g. `platform/tools/repohooks`
120*d68f33bcSAndroid Build Coastguard Worker* `${REPO_ROOT}`: The absolute path of the root of the repo checkout.  If the
121*d68f33bcSAndroid Build Coastguard Worker  project is in a submanifest, this points to the root of the submanifest.
122*d68f33bcSAndroid Build Coastguard Worker* `${REPO_OUTER_ROOT}`: The absolute path of the root of the repo checkout.
123*d68f33bcSAndroid Build Coastguard Worker  This always points to the root of the overall repo checkout.
124*d68f33bcSAndroid Build Coastguard Worker* `${BUILD_OS}`: The string `darwin-x86` for macOS and the string `linux-x86`
125*d68f33bcSAndroid Build Coastguard Worker  for Linux/x86.
126*d68f33bcSAndroid Build Coastguard Worker
127*d68f33bcSAndroid Build Coastguard Worker### Examples
128*d68f33bcSAndroid Build Coastguard Worker
129*d68f33bcSAndroid Build Coastguard WorkerHere are some examples of using the placeholders.
130*d68f33bcSAndroid Build Coastguard WorkerConsider this sample config file.
131*d68f33bcSAndroid Build Coastguard Worker```
132*d68f33bcSAndroid Build Coastguard Worker[Hook Scripts]
133*d68f33bcSAndroid Build Coastguard Workerlister = ls ${PREUPLOAD_FILES}
134*d68f33bcSAndroid Build Coastguard Workerchecker prefix = check --file=${PREUPLOAD_FILES_PREFIXED}
135*d68f33bcSAndroid Build Coastguard Workerchecker flag = check --file ${PREUPLOAD_FILES_PREFIXED}
136*d68f33bcSAndroid Build Coastguard Worker```
137*d68f33bcSAndroid Build Coastguard WorkerWith a commit that changes `path1/file1` and `path2/file2`, then this will run
138*d68f33bcSAndroid Build Coastguard Workerprograms with the arguments:
139*d68f33bcSAndroid Build Coastguard Worker* ['ls', 'path1/file1', 'path2/file2']
140*d68f33bcSAndroid Build Coastguard Worker* ['check', '--file=path1/file1', '--file=path2/file2']
141*d68f33bcSAndroid Build Coastguard Worker* ['check', '--file', 'path1/file1', '--file', 'path2/file2']
142*d68f33bcSAndroid Build Coastguard Worker
143*d68f33bcSAndroid Build Coastguard Worker## [Options]
144*d68f33bcSAndroid Build Coastguard Worker
145*d68f33bcSAndroid Build Coastguard WorkerThis section allows for setting options that affect the overall behavior of the
146*d68f33bcSAndroid Build Coastguard Workerpre-upload checks.  The following options are recognized:
147*d68f33bcSAndroid Build Coastguard Worker
148*d68f33bcSAndroid Build Coastguard Worker* `ignore_merged_commits`: If set to `true`, the hooks will not run on commits
149*d68f33bcSAndroid Build Coastguard Worker  that are merged.  Hooks will still run on the merge commit itself.
150*d68f33bcSAndroid Build Coastguard Worker
151*d68f33bcSAndroid Build Coastguard Worker## [Hook Scripts]
152*d68f33bcSAndroid Build Coastguard Worker
153*d68f33bcSAndroid Build Coastguard WorkerThis section allows for completely arbitrary hooks to run on a per-repo basis.
154*d68f33bcSAndroid Build Coastguard Worker
155*d68f33bcSAndroid Build Coastguard WorkerThe key can be any name (as long as the syntax is valid), as can the program
156*d68f33bcSAndroid Build Coastguard Workerthat is executed. The key is used as the name of the hook for reporting purposes,
157*d68f33bcSAndroid Build Coastguard Workerso it should be at least somewhat descriptive.
158*d68f33bcSAndroid Build Coastguard Worker
159*d68f33bcSAndroid Build Coastguard WorkerWhitespace in the key name is OK!
160*d68f33bcSAndroid Build Coastguard Worker
161*d68f33bcSAndroid Build Coastguard WorkerThe keys must be unique as duplicates will silently clobber earlier values.
162*d68f33bcSAndroid Build Coastguard Worker
163*d68f33bcSAndroid Build Coastguard WorkerYou do not need to send stderr to stdout.  The tooling will take care of
164*d68f33bcSAndroid Build Coastguard Workermerging them together for you automatically.
165*d68f33bcSAndroid Build Coastguard Worker
166*d68f33bcSAndroid Build Coastguard Worker```
167*d68f33bcSAndroid Build Coastguard Worker[Hook Scripts]
168*d68f33bcSAndroid Build Coastguard Workermy first hook = program --gogog ${PREUPLOAD_FILES}
169*d68f33bcSAndroid Build Coastguard Workeranother hook = funtimes --i-need "some space" ${PREUPLOAD_FILES}
170*d68f33bcSAndroid Build Coastguard Workersome fish = linter --ate-a-cat ${PREUPLOAD_FILES}
171*d68f33bcSAndroid Build Coastguard Workersome cat = formatter --cat-commit ${PREUPLOAD_COMMIT}
172*d68f33bcSAndroid Build Coastguard Workersome dog = tool --no-cat-in-commit-message ${PREUPLOAD_COMMIT_MESSAGE}
173*d68f33bcSAndroid Build Coastguard Worker```
174*d68f33bcSAndroid Build Coastguard Worker
175*d68f33bcSAndroid Build Coastguard Worker## [Builtin Hooks]
176*d68f33bcSAndroid Build Coastguard Worker
177*d68f33bcSAndroid Build Coastguard WorkerThis section allows for turning on common/builtin hooks.  There are a bunch of
178*d68f33bcSAndroid Build Coastguard Workercanned hooks already included geared towards AOSP style guidelines.
179*d68f33bcSAndroid Build Coastguard Worker
180*d68f33bcSAndroid Build Coastguard Worker* `aidl_format`: Run AIDL files (.aidl) through `aidl-format`.
181*d68f33bcSAndroid Build Coastguard Worker* `aosp_license`: Check if all new-added file have valid AOSP license headers.
182*d68f33bcSAndroid Build Coastguard Worker* `android_test_mapping_format`: Validate TEST_MAPPING files in Android source
183*d68f33bcSAndroid Build Coastguard Worker  code. Refer to go/test-mapping for more details.
184*d68f33bcSAndroid Build Coastguard Worker* `bpfmt`: Run Blueprint files (.bp) through `bpfmt`.
185*d68f33bcSAndroid Build Coastguard Worker* `checkpatch`: Run commits through the Linux kernel's `checkpatch.pl` script.
186*d68f33bcSAndroid Build Coastguard Worker* `clang_format`: Run git-clang-format against the commit. The default style is
187*d68f33bcSAndroid Build Coastguard Worker  `file`.
188*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_bug_field`: Require a valid `Bug:` line.
189*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_changeid_field`: Require a valid `Change-Id:` Gerrit line.
190*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_prebuilt_apk_fields`: Require badging and build information for
191*d68f33bcSAndroid Build Coastguard Worker  prebuilt APKs.
192*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_relnote_field_format`: Check for possible misspellings of the
193*d68f33bcSAndroid Build Coastguard Worker  `Relnote:` field and that multiline release notes are properly formatted with
194*d68f33bcSAndroid Build Coastguard Worker  quotes.
195*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_relnote_for_current_txt`: Check that CLs with changes to
196*d68f33bcSAndroid Build Coastguard Worker  current.txt or public_plus_experimental_current.txt also contain a
197*d68f33bcSAndroid Build Coastguard Worker  `Relnote:` field in the commit message.
198*d68f33bcSAndroid Build Coastguard Worker* `commit_msg_test_field`: Require a `Test:` line.
199*d68f33bcSAndroid Build Coastguard Worker* `cpplint`: Run through the cpplint tool (for C++ code).
200*d68f33bcSAndroid Build Coastguard Worker* `gofmt`: Run Go code through `gofmt`.
201*d68f33bcSAndroid Build Coastguard Worker* `google_java_format`: Run Java code through
202*d68f33bcSAndroid Build Coastguard Worker  [`google-java-format`](https://github.com/google/google-java-format).
203*d68f33bcSAndroid Build Coastguard Worker  Supports an additional option --include-dirs, which if specified will limit
204*d68f33bcSAndroid Build Coastguard Worker  enforcement to only files under the specified directories.
205*d68f33bcSAndroid Build Coastguard Worker* `jsonlint`: Verify JSON code is sane.
206*d68f33bcSAndroid Build Coastguard Worker* `ktfmt`: Run Kotlin code through `ktfmt`. Supports an additional option
207*d68f33bcSAndroid Build Coastguard Worker  --include-dirs, which if specified will limit enforcement to only files under
208*d68f33bcSAndroid Build Coastguard Worker  the specified directories.
209*d68f33bcSAndroid Build Coastguard Worker* `pylint`: Alias of `pylint3`.
210*d68f33bcSAndroid Build Coastguard Worker* `pylint2`: Run Python code through `pylint` using Python 2.
211*d68f33bcSAndroid Build Coastguard Worker* `pylint3`: Run Python code through `pylint` using Python 3.
212*d68f33bcSAndroid Build Coastguard Worker* `rustfmt`: Run Rust code through `rustfmt`.
213*d68f33bcSAndroid Build Coastguard Worker* `xmllint`: Run XML code through `xmllint`.
214*d68f33bcSAndroid Build Coastguard Worker
215*d68f33bcSAndroid Build Coastguard WorkerNote: Builtin hooks tend to match specific filenames (e.g. `.json`).  If no
216*d68f33bcSAndroid Build Coastguard Workerfiles match in a specific commit, then the hook will be skipped for that commit.
217*d68f33bcSAndroid Build Coastguard Worker
218*d68f33bcSAndroid Build Coastguard Worker```
219*d68f33bcSAndroid Build Coastguard Worker[Builtin Hooks]
220*d68f33bcSAndroid Build Coastguard Worker# Turn on cpplint checking.
221*d68f33bcSAndroid Build Coastguard Workercpplint = true
222*d68f33bcSAndroid Build Coastguard Worker# Turn off gofmt checking.
223*d68f33bcSAndroid Build Coastguard Workergofmt = false
224*d68f33bcSAndroid Build Coastguard Worker```
225*d68f33bcSAndroid Build Coastguard Worker
226*d68f33bcSAndroid Build Coastguard Worker## [Builtin Hooks Options]
227*d68f33bcSAndroid Build Coastguard Worker
228*d68f33bcSAndroid Build Coastguard WorkerUsed to customize the behavior of specific `[Builtin Hooks]`.  Any arguments set
229*d68f33bcSAndroid Build Coastguard Workerhere will be passed directly to the linter in question.  This will completely
230*d68f33bcSAndroid Build Coastguard Workeroverride any existing default options, so be sure to include everything you need
231*d68f33bcSAndroid Build Coastguard Worker(especially `${PREUPLOAD_FILES}` -- see below).
232*d68f33bcSAndroid Build Coastguard Worker
233*d68f33bcSAndroid Build Coastguard WorkerQuoting is handled naturally.  i.e. use `"a b c"` to pass an argument with
234*d68f33bcSAndroid Build Coastguard Workerwhitespace.
235*d68f33bcSAndroid Build Coastguard Worker
236*d68f33bcSAndroid Build Coastguard WorkerSee [Placeholders](#Placeholders) for variables you can expand automatically.
237*d68f33bcSAndroid Build Coastguard Worker
238*d68f33bcSAndroid Build Coastguard Worker```
239*d68f33bcSAndroid Build Coastguard Worker[Builtin Hooks Options]
240*d68f33bcSAndroid Build Coastguard Worker# Pass more filter args to cpplint.
241*d68f33bcSAndroid Build Coastguard Workercpplint = --filter=-x ${PREUPLOAD_FILES}
242*d68f33bcSAndroid Build Coastguard Worker```
243*d68f33bcSAndroid Build Coastguard Worker
244*d68f33bcSAndroid Build Coastguard Worker## [Builtin Hooks Exclude Paths]
245*d68f33bcSAndroid Build Coastguard Worker
246*d68f33bcSAndroid Build Coastguard Worker*** note
247*d68f33bcSAndroid Build Coastguard WorkerThis section can only be added to the repo project-wide settings
248*d68f33bcSAndroid Build Coastguard Worker[GLOBAL-PREUPLOAD.cfg].
249*d68f33bcSAndroid Build Coastguard Worker***
250*d68f33bcSAndroid Build Coastguard Worker
251*d68f33bcSAndroid Build Coastguard WorkerUsed to explicitly exclude some projects when processing a hook. With this
252*d68f33bcSAndroid Build Coastguard Workersection, it is possible to define a hook that should apply to the majority of
253*d68f33bcSAndroid Build Coastguard Workerprojects except a few.
254*d68f33bcSAndroid Build Coastguard Worker
255*d68f33bcSAndroid Build Coastguard WorkerAn entry must completely match the project's `REPO_PATH`. The paths can use the
256*d68f33bcSAndroid Build Coastguard Worker[shell-style wildcards](https://docs.python.org/library/fnmatch.html) and
257*d68f33bcSAndroid Build Coastguard Workerquotes. For advanced cases, it is possible to use a [regular
258*d68f33bcSAndroid Build Coastguard Workerexpression](https://docs.python.org/howto/regex.html) by using the `^` prefix.
259*d68f33bcSAndroid Build Coastguard Worker
260*d68f33bcSAndroid Build Coastguard Worker```
261*d68f33bcSAndroid Build Coastguard Worker[Builtin Hooks Exclude Paths]
262*d68f33bcSAndroid Build Coastguard Worker# Run cpplint on all projects except ones under external/ and vendor/.
263*d68f33bcSAndroid Build Coastguard Worker# The "external" and "vendor" projects, if they exist, will still run cpplint.
264*d68f33bcSAndroid Build Coastguard Workercpplint = external/* vendor/*
265*d68f33bcSAndroid Build Coastguard Worker
266*d68f33bcSAndroid Build Coastguard Worker# Run rustfmt on all projects except ones under external/.  All projects under
267*d68f33bcSAndroid Build Coastguard Worker# hardware/ will be excluded except for ones starting with hardware/google (due to
268*d68f33bcSAndroid Build Coastguard Worker# the negative regex match).
269*d68f33bcSAndroid Build Coastguard Workerrustfmt = external/ ^hardware/(!?google)
270*d68f33bcSAndroid Build Coastguard Worker```
271*d68f33bcSAndroid Build Coastguard Worker
272*d68f33bcSAndroid Build Coastguard Worker## [Tool Paths]
273*d68f33bcSAndroid Build Coastguard Worker
274*d68f33bcSAndroid Build Coastguard WorkerSome builtin hooks need to call external executables to work correctly.  By
275*d68f33bcSAndroid Build Coastguard Workerdefault it will call those tools from the user's `$PATH`, but the paths of those
276*d68f33bcSAndroid Build Coastguard Workerexecutables can be overridden through `[Tool Paths]`.  This is helpful to
277*d68f33bcSAndroid Build Coastguard Workerprovide consistent behavior for developers across different OS and Linux
278*d68f33bcSAndroid Build Coastguard Workerdistros/versions.  The following tools are recognized:
279*d68f33bcSAndroid Build Coastguard Worker
280*d68f33bcSAndroid Build Coastguard Worker* `aidl-format`: used for the `aidl_format` builtin hook.
281*d68f33bcSAndroid Build Coastguard Worker* `android-test-mapping-format`: used for the `android_test_mapping_format`
282*d68f33bcSAndroid Build Coastguard Worker  builtin hook.
283*d68f33bcSAndroid Build Coastguard Worker* `bpfmt`: used for the `bpfmt` builtin hook.
284*d68f33bcSAndroid Build Coastguard Worker* `clang-format`: used for the `clang_format` builtin hook.
285*d68f33bcSAndroid Build Coastguard Worker* `cpplint`: used for the `cpplint` builtin hook.
286*d68f33bcSAndroid Build Coastguard Worker* `git-clang-format`: used for the `clang_format` builtin hook.
287*d68f33bcSAndroid Build Coastguard Worker* `gofmt`: used for the `gofmt` builtin hook.
288*d68f33bcSAndroid Build Coastguard Worker* `google-java-format`: used for the `google_java_format` builtin hook.
289*d68f33bcSAndroid Build Coastguard Worker* `google-java-format-diff`: used for the `google_java_format` builtin hook.
290*d68f33bcSAndroid Build Coastguard Worker* `ktfmt`: used for the `ktfmt` builtin hook.
291*d68f33bcSAndroid Build Coastguard Worker* `pylint`: used for the `pylint` builtin hook.
292*d68f33bcSAndroid Build Coastguard Worker* `rustfmt`: used for the `rustfmt` builtin hook.
293*d68f33bcSAndroid Build Coastguard Worker
294*d68f33bcSAndroid Build Coastguard WorkerSee [Placeholders](#Placeholders) for variables you can expand automatically.
295*d68f33bcSAndroid Build Coastguard Worker
296*d68f33bcSAndroid Build Coastguard Worker```
297*d68f33bcSAndroid Build Coastguard Worker[Tool Paths]
298*d68f33bcSAndroid Build Coastguard Worker# Pass absolute paths.
299*d68f33bcSAndroid Build Coastguard Workerclang-format = /usr/bin/clang-format
300*d68f33bcSAndroid Build Coastguard Worker# Or paths relative to the top of the git project.
301*d68f33bcSAndroid Build Coastguard Workerclang-format = prebuilts/bin/clang-format
302*d68f33bcSAndroid Build Coastguard Worker# Or paths relative to the repo root.
303*d68f33bcSAndroid Build Coastguard Workerclang-format = ${REPO_ROOT}/prebuilts/clang/host/${BUILD_OS}/clang-stable/bin/clang-format
304*d68f33bcSAndroid Build Coastguard Worker```
305*d68f33bcSAndroid Build Coastguard Worker
306*d68f33bcSAndroid Build Coastguard Worker# Hook Developers
307*d68f33bcSAndroid Build Coastguard Worker
308*d68f33bcSAndroid Build Coastguard WorkerThese are notes for people updating the `pre-upload.py` hook itself:
309*d68f33bcSAndroid Build Coastguard Worker
310*d68f33bcSAndroid Build Coastguard Worker* Don't worry about namespace collisions.  The `pre-upload.py` script is loaded
311*d68f33bcSAndroid Build Coastguard Worker  and exec-ed in its own context.  The only entry-point that matters is `main`.
312*d68f33bcSAndroid Build Coastguard Worker* New hooks can be added in `rh/hooks.py`.  Be sure to keep the list up-to-date
313*d68f33bcSAndroid Build Coastguard Worker  with the documentation in this file.
314*d68f33bcSAndroid Build Coastguard Worker
315*d68f33bcSAndroid Build Coastguard Worker## Warnings
316*d68f33bcSAndroid Build Coastguard Worker
317*d68f33bcSAndroid Build Coastguard WorkerIf the return code of a hook is 77, then it is assumed to be a warning.  The
318*d68f33bcSAndroid Build Coastguard Workeroutput will be printed to the terminal, but uploading will still be allowed
319*d68f33bcSAndroid Build Coastguard Workerwithout a bypass being required.
320*d68f33bcSAndroid Build Coastguard Worker
321*d68f33bcSAndroid Build Coastguard Worker# TODO/Limitations
322*d68f33bcSAndroid Build Coastguard Worker
323*d68f33bcSAndroid Build Coastguard Worker* Some checkers operate on the files as they exist in the filesystem.  This is
324*d68f33bcSAndroid Build Coastguard Worker  not easy to fix because the linters require not just the modified file but the
325*d68f33bcSAndroid Build Coastguard Worker  entire repo in order to perform full checks.  e.g. `pylint` needs to know what
326*d68f33bcSAndroid Build Coastguard Worker  other modules exist locally to verify their API.  We can support this case by
327*d68f33bcSAndroid Build Coastguard Worker  doing a full checkout of the repo in a temp dir, but this can slow things down
328*d68f33bcSAndroid Build Coastguard Worker  a lot.  Will need to consider a `PREUPLOAD.cfg` knob.
329*d68f33bcSAndroid Build Coastguard Worker* We need to add `pylint` tool to the AOSP manifest and use that local copy
330*d68f33bcSAndroid Build Coastguard Worker  instead of relying on the version that is in $PATH.
331*d68f33bcSAndroid Build Coastguard Worker* Should make file extension filters configurable.  All hooks currently declare
332*d68f33bcSAndroid Build Coastguard Worker  their own list of files like `.cc` and `.py` and `.xml`.
333*d68f33bcSAndroid Build Coastguard Worker* Add more checkers.
334*d68f33bcSAndroid Build Coastguard Worker  * `clang-check`: Runs static analyzers against code.
335*d68f33bcSAndroid Build Coastguard Worker  * Whitespace checking (trailing/tab mixing/etc...).
336*d68f33bcSAndroid Build Coastguard Worker  * Long line checking.
337*d68f33bcSAndroid Build Coastguard Worker  * Commit message checks (correct format/BUG/TEST/SOB tags/etc...).
338*d68f33bcSAndroid Build Coastguard Worker  * Markdown (gitiles) validator.
339*d68f33bcSAndroid Build Coastguard Worker  * Spell checker.
340