xref: /aosp_15_r20/tools/external_updater/README.md (revision 3c875a214f382db1236d28570d1304ce57138f32)
1*3c875a21SAndroid Build Coastguard Worker# external_updater
2*3c875a21SAndroid Build Coastguard Worker
3*3c875a21SAndroid Build Coastguard Workerexternal updater is a tool to automatically update libraries in external/.
4*3c875a21SAndroid Build Coastguard Worker
5*3c875a21SAndroid Build Coastguard WorkerThe documentation on this page is for users of `external_updater`. If you're
6*3c875a21SAndroid Build Coastguard Workerlooking for developer docs, see [docs/dev.md](docs/dev.md).
7*3c875a21SAndroid Build Coastguard Worker
8*3c875a21SAndroid Build Coastguard Worker## Usage
9*3c875a21SAndroid Build Coastguard Worker
10*3c875a21SAndroid Build Coastguard WorkerIn each of the examples below, `$PROJECT_PATH` is the path to the project to
11*3c875a21SAndroid Build Coastguard Workeroperate on. If more than one path is given, external_updater will operate on
12*3c875a21SAndroid Build Coastguard Workereach in turn.
13*3c875a21SAndroid Build Coastguard Worker
14*3c875a21SAndroid Build Coastguard WorkerNote: Older versions of external_updater used a different path resolution
15*3c875a21SAndroid Build Coastguard Workermethod. Relative paths were resolved relative to `//external` rather than the
16*3c875a21SAndroid Build Coastguard WorkerCWD, which meant tab-completed paths would only work if the CWD was
17*3c875a21SAndroid Build Coastguard Worker`//external`, and that wildcards had to be escaped for processing by
18*3c875a21SAndroid Build Coastguard Workerexternal_updater rather than the shell (e.g.
19*3c875a21SAndroid Build Coastguard Worker`updater.sh 'check rust/crates/*'`). That behavior was removed to support CWD
20*3c875a21SAndroid Build Coastguard Workerrelative paths. If you want the old behavior back, leave a comment on
21*3c875a21SAndroid Build Coastguard Workerhttp://b/243685332 or https://r.android.com/2855445.
22*3c875a21SAndroid Build Coastguard Worker
23*3c875a21SAndroid Build Coastguard WorkerCheck updates for a library or verify METADATA is valid:
24*3c875a21SAndroid Build Coastguard Worker
25*3c875a21SAndroid Build Coastguard Worker```shell
26*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh check $PROJECT_PATH
27*3c875a21SAndroid Build Coastguard Worker```
28*3c875a21SAndroid Build Coastguard Worker
29*3c875a21SAndroid Build Coastguard WorkerUpdate a library, commit, and upload the change to Gerrit:
30*3c875a21SAndroid Build Coastguard Worker
31*3c875a21SAndroid Build Coastguard Worker```shell
32*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update $PROJECT_PATH
33*3c875a21SAndroid Build Coastguard Worker```
34*3c875a21SAndroid Build Coastguard Worker
35*3c875a21SAndroid Build Coastguard WorkerUpdate a library without committing and uploading to Gerrit:
36*3c875a21SAndroid Build Coastguard Worker
37*3c875a21SAndroid Build Coastguard Worker```shell
38*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update --no-upload $PROJECT_PATH
39*3c875a21SAndroid Build Coastguard Worker```
40*3c875a21SAndroid Build Coastguard Worker
41*3c875a21SAndroid Build Coastguard WorkerUpdate a library to a specific version:
42*3c875a21SAndroid Build Coastguard Worker
43*3c875a21SAndroid Build Coastguard Worker```shell
44*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update --custom-version $VERSION $PROJECT_PATH
45*3c875a21SAndroid Build Coastguard Worker```
46*3c875a21SAndroid Build Coastguard Worker
47*3c875a21SAndroid Build Coastguard WorkerUpdate a library on top of the local changes in the current branch, commit, and upload the change to Gerrit:
48*3c875a21SAndroid Build Coastguard Worker
49*3c875a21SAndroid Build Coastguard Worker```shell
50*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update --keep-local-changes $PROJECT_PATH
51*3c875a21SAndroid Build Coastguard Worker```
52*3c875a21SAndroid Build Coastguard Worker
53*3c875a21SAndroid Build Coastguard WorkerUpdate a library without building:
54*3c875a21SAndroid Build Coastguard Worker
55*3c875a21SAndroid Build Coastguard Worker```shell
56*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update --no-build $PROJECT_PATH
57*3c875a21SAndroid Build Coastguard Worker```
58*3c875a21SAndroid Build Coastguard Worker
59*3c875a21SAndroid Build Coastguard WorkerUpdate a library and add bug number to the commit message:
60*3c875a21SAndroid Build Coastguard Worker
61*3c875a21SAndroid Build Coastguard Worker```shell
62*3c875a21SAndroid Build Coastguard Workertools/external_updater/updater.sh update --bug $BUG_NUMBER $PROJECT_PATH
63*3c875a21SAndroid Build Coastguard Worker```
64*3c875a21SAndroid Build Coastguard Worker
65*3c875a21SAndroid Build Coastguard WorkerPROJECT_PATH can be the path to a library under external/, e.g.
66*3c875a21SAndroid Build Coastguard Workerexternal/kotlinc, or external/python/cpython3.
67*3c875a21SAndroid Build Coastguard Worker
68*3c875a21SAndroid Build Coastguard Worker## Configure
69*3c875a21SAndroid Build Coastguard Worker
70*3c875a21SAndroid Build Coastguard WorkerTo use this tool, a METADATA file must present at the root of the
71*3c875a21SAndroid Build Coastguard Workerrepository. The full definition can be found in
72*3c875a21SAndroid Build Coastguard Worker[metadata.proto](https://android.googlesource.com/platform/tools/external_updater/+/refs/heads/main/metadata.proto).
73*3c875a21SAndroid Build Coastguard WorkerOr
74*3c875a21SAndroid Build Coastguard Worker[external/toybox/METADATA](https://android.googlesource.com/platform/external/toybox/+/refs/heads/main/METADATA)
75*3c875a21SAndroid Build Coastguard Workeris a concrete example.
76*3c875a21SAndroid Build Coastguard Worker
77*3c875a21SAndroid Build Coastguard WorkerThe most important part in the file is a list of urls.
78*3c875a21SAndroid Build Coastguard Worker`external_updater` will go through all urls and uses the first
79*3c875a21SAndroid Build Coastguard Workersupported url.
80*3c875a21SAndroid Build Coastguard Worker
81*3c875a21SAndroid Build Coastguard Worker### Git upstream
82*3c875a21SAndroid Build Coastguard Worker
83*3c875a21SAndroid Build Coastguard WorkerIf type of a URL is set to GIT, the URL must be a git upstream
84*3c875a21SAndroid Build Coastguard Worker(the one you can use with `git clone`). And the version field must
85*3c875a21SAndroid Build Coastguard Workerbe either a version tag, or SHA. The tool will find the latest
86*3c875a21SAndroid Build Coastguard Workerversion tag or sha based on it.
87*3c875a21SAndroid Build Coastguard Worker
88*3c875a21SAndroid Build Coastguard WorkerWhen upgrade, the tool will simply run `git merge tag/sha`.
89*3c875a21SAndroid Build Coastguard Worker
90*3c875a21SAndroid Build Coastguard WorkerIMPORTANT: It is suggested to set up a `upstream-main` branch to
91*3c875a21SAndroid Build Coastguard Workerreplicate upstream. Because most users don't have the privilege to
92*3c875a21SAndroid Build Coastguard Workerupload changes not authored by themselves. This can be done by
93*3c875a21SAndroid Build Coastguard Workerfiling a bug to componentid:99104.
94*3c875a21SAndroid Build Coastguard Worker
95*3c875a21SAndroid Build Coastguard Worker#### SHA
96*3c875a21SAndroid Build Coastguard Worker
97*3c875a21SAndroid Build Coastguard WorkerIf the version is a SHA, the tool will always try to upgrade to the
98*3c875a21SAndroid Build Coastguard Workertop of upstream. As long as there is any new change upstream, local
99*3c875a21SAndroid Build Coastguard Workerlibrary will be treated as stale.
100*3c875a21SAndroid Build Coastguard Worker
101*3c875a21SAndroid Build Coastguard Worker#### Version tag
102*3c875a21SAndroid Build Coastguard Worker
103*3c875a21SAndroid Build Coastguard WorkerIf the version is not a SHA, the tool will try to parse the version
104*3c875a21SAndroid Build Coastguard Workerto get a numbered version. Currently the supported version format is:
105*3c875a21SAndroid Build Coastguard Worker
106*3c875a21SAndroid Build Coastguard Worker```markdown
107*3c875a21SAndroid Build Coastguard Worker<prefix><version_number><suffix>
108*3c875a21SAndroid Build Coastguard Worker```
109*3c875a21SAndroid Build Coastguard Worker
110*3c875a21SAndroid Build Coastguard Workerversion_number part can be numbers separated by `.` or `-` or `_`.
111*3c875a21SAndroid Build Coastguard Worker
112*3c875a21SAndroid Build Coastguard WorkerIf you have project where this isn't working, file a bug so we can take a look.
113*3c875a21SAndroid Build Coastguard Worker
114*3c875a21SAndroid Build Coastguard Worker#### Local changes
115*3c875a21SAndroid Build Coastguard Worker
116*3c875a21SAndroid Build Coastguard WorkerIt is suggested to verify all local changes when upgrading. This can
117*3c875a21SAndroid Build Coastguard Workerbe done easily in Gerrit, by comparing parent2 and the patchset.
118*3c875a21SAndroid Build Coastguard Worker
119*3c875a21SAndroid Build Coastguard Worker
120*3c875a21SAndroid Build Coastguard Worker### GitHub archive
121*3c875a21SAndroid Build Coastguard Worker
122*3c875a21SAndroid Build Coastguard WorkerIf the url type is ARCHIVE, and the url is from GitHub, `external_updater`
123*3c875a21SAndroid Build Coastguard Workercan upgrade a library based on GitHub releases.
124*3c875a21SAndroid Build Coastguard Worker
125*3c875a21SAndroid Build Coastguard WorkerIf you have the choice between archives and git tags, choose tags.
126*3c875a21SAndroid Build Coastguard WorkerBecause that makes it easier to manage local changes.
127*3c875a21SAndroid Build Coastguard Worker
128*3c875a21SAndroid Build Coastguard WorkerThe tool will query GitHub to get the latest release from:
129*3c875a21SAndroid Build Coastguard Worker
130*3c875a21SAndroid Build Coastguard Worker```url
131*3c875a21SAndroid Build Coastguard Workerhttps://github.com/user/proj/releases/latest
132*3c875a21SAndroid Build Coastguard Worker```
133*3c875a21SAndroid Build Coastguard Worker
134*3c875a21SAndroid Build Coastguard WorkerIf the tag of latest release is not equal to version in METADATA file, a
135*3c875a21SAndroid Build Coastguard Workernew version is found. The tool will download the tarball and overwrite the
136*3c875a21SAndroid Build Coastguard Workerlibrary with it.
137*3c875a21SAndroid Build Coastguard Worker
138*3c875a21SAndroid Build Coastguard WorkerIf there are multiple archives in one GitHub release, the one most
139*3c875a21SAndroid Build Coastguard Worker[similar](https://en.wikipedia.org/wiki/Edit_distance) to previous
140*3c875a21SAndroid Build Coastguard Worker(from METADATA) will be used.
141*3c875a21SAndroid Build Coastguard Worker
142*3c875a21SAndroid Build Coastguard WorkerAfter upgrade, files not present in the new tarball will be removed. But we
143*3c875a21SAndroid Build Coastguard Workerexplicitly keep files famous in Android tree.
144*3c875a21SAndroid Build Coastguard WorkerSee [update_package.sh](https://android.googlesource.com/platform/tools/external_updater/+/refs/heads/main/update_package.sh).
145*3c875a21SAndroid Build Coastguard Worker
146*3c875a21SAndroid Build Coastguard WorkerIf more files need to be reserved, a post_update.sh can be created to copy
147*3c875a21SAndroid Build Coastguard Workerthese files over.
148*3c875a21SAndroid Build Coastguard WorkerSee [example](https://android.googlesource.com/platform/external/kotlinc/+/refs/heads/main/post_update.sh).
149*3c875a21SAndroid Build Coastguard Worker
150*3c875a21SAndroid Build Coastguard Worker#### Local patches
151*3c875a21SAndroid Build Coastguard Worker
152*3c875a21SAndroid Build Coastguard WorkerLocal patches can be kept as patches/*.diff. They will be applied after
153*3c875a21SAndroid Build Coastguard Workerupgrade. [example](https://cs.android.com/android/platform/superproject/main/+/main:external/jsmn/patches/header.diff)
154*3c875a21SAndroid Build Coastguard Worker
155*3c875a21SAndroid Build Coastguard Worker## Email notification
156*3c875a21SAndroid Build Coastguard Worker
157*3c875a21SAndroid Build Coastguard WorkerThere is some support to automatically check updates for all external
158*3c875a21SAndroid Build Coastguard Workerlibraries every hour, send email and change. Currently this is done by
159*3c875a21SAndroid Build Coastguard Workerrunning the following script on a desktop machine.
160*3c875a21SAndroid Build Coastguard Worker
161*3c875a21SAndroid Build Coastguard Worker```shell
162*3c875a21SAndroid Build Coastguard Worker#!/bin/bash
163*3c875a21SAndroid Build Coastguard Worker
164*3c875a21SAndroid Build Coastguard Workercd /src/aosp
165*3c875a21SAndroid Build Coastguard Workerwhile true
166*3c875a21SAndroid Build Coastguard Workerdo
167*3c875a21SAndroid Build Coastguard Worker        repo abandon tmp_auto_upgrade
168*3c875a21SAndroid Build Coastguard Worker        repo forall -c git checkout .
169*3c875a21SAndroid Build Coastguard Worker        repo forall -c git clean -xdf
170*3c875a21SAndroid Build Coastguard Worker        repo sync -c
171*3c875a21SAndroid Build Coastguard Worker        source build/envsetup.sh
172*3c875a21SAndroid Build Coastguard Worker        lunch aosp_arm-eng
173*3c875a21SAndroid Build Coastguard Worker        mmma tools/external_updater
174*3c875a21SAndroid Build Coastguard Worker
175*3c875a21SAndroid Build Coastguard Worker        out/soong/host/linux-x86/bin/external_updater_notifier \
176*3c875a21SAndroid Build Coastguard Worker                --history ~/updater/history \
177*3c875a21SAndroid Build Coastguard Worker                [email protected] \
178*3c875a21SAndroid Build Coastguard Worker                --generate_change \
179*3c875a21SAndroid Build Coastguard Worker                --all
180*3c875a21SAndroid Build Coastguard Worker        date
181*3c875a21SAndroid Build Coastguard Worker        echo "Sleeping..."
182*3c875a21SAndroid Build Coastguard Worker        sleep 3600
183*3c875a21SAndroid Build Coastguard Workerdone
184*3c875a21SAndroid Build Coastguard Worker```
185