xref: /aosp_15_r20/external/bpftool/scripts/README.md (revision 858ea5e570667251cdc31d3fe7b846b591105938)
1*858ea5e5SAndroid Build Coastguard Worker# Scripts
2*858ea5e5SAndroid Build Coastguard Worker
3*858ea5e5SAndroid Build Coastguard WorkerThis directory contains scripts for maintaining bpftool's GitHub mirror.
4*858ea5e5SAndroid Build Coastguard Worker
5*858ea5e5SAndroid Build Coastguard Worker## gh-label-release-assets.sh
6*858ea5e5SAndroid Build Coastguard Worker
7*858ea5e5SAndroid Build Coastguard WorkerThis script can **add labels to GitHub release assets**. Labels are used in the
8*858ea5e5SAndroid Build Coastguard WorkerGitHub interface instead of the file name in the list of assets, but they do
9*858ea5e5SAndroid Build Coastguard Workernot alter the download URL.
10*858ea5e5SAndroid Build Coastguard Worker
11*858ea5e5SAndroid Build Coastguard WorkerThe script takes the tag reference for the release as single parameter. The
12*858ea5e5SAndroid Build Coastguard Workerrepository to use, and the names and labels to set for assets are currently
13*858ea5e5SAndroid Build Coastguard Workerdefined in the script itself.
14*858ea5e5SAndroid Build Coastguard Worker
15*858ea5e5SAndroid Build Coastguard WorkerIt requires the [GitHub command line][gh] (`gh`).
16*858ea5e5SAndroid Build Coastguard Worker
17*858ea5e5SAndroid Build Coastguard WorkerNote that only users with push access to the repository can update release
18*858ea5e5SAndroid Build Coastguard Workerassets and set labels.
19*858ea5e5SAndroid Build Coastguard Worker
20*858ea5e5SAndroid Build Coastguard Worker[gh]: https://cli.github.com/
21*858ea5e5SAndroid Build Coastguard Worker
22*858ea5e5SAndroid Build Coastguard Worker## sync-kernel.sh
23*858ea5e5SAndroid Build Coastguard Worker
24*858ea5e5SAndroid Build Coastguard Worker### Synchronize Linux and bpftool mirror
25*858ea5e5SAndroid Build Coastguard Worker
26*858ea5e5SAndroid Build Coastguard WorkerThis script synchronizes the bpftool mirror with the bpftool sources (and
27*858ea5e5SAndroid Build Coastguard Workerrelated files) from the Linux kernel repository.
28*858ea5e5SAndroid Build Coastguard Worker
29*858ea5e5SAndroid Build Coastguard WorkerSynchronization is usually performed against the `bpf-next` and `bpf` trees,
30*858ea5e5SAndroid Build Coastguard Workerbecause this is where most bpftool updates are merged.
31*858ea5e5SAndroid Build Coastguard Worker
32*858ea5e5SAndroid Build Coastguard WorkerBy default, the script does not pick the very latest commits in these trees,
33*858ea5e5SAndroid Build Coastguard Workerbut instead it uses the commits referenced in the libbpf submodule. This is
34*858ea5e5SAndroid Build Coastguard Workerbecause bpftool strongly relies on libbpf, and the libbpf GitHub mirror is used
35*858ea5e5SAndroid Build Coastguard Workerhere as a submodule dependency. This libbpf mirror is also periodically updated
36*858ea5e5SAndroid Build Coastguard Workerto the latest `bpf-next` and `bpf` tree, and records to what kernel commits it
37*858ea5e5SAndroid Build Coastguard Workerwas brought up-to-date. To ensure optimal compatibility between the bpftool
38*858ea5e5SAndroid Build Coastguard Workersources and the libbpf dependency, we want to update them to the same point of
39*858ea5e5SAndroid Build Coastguard Workerreference.
40*858ea5e5SAndroid Build Coastguard Worker
41*858ea5e5SAndroid Build Coastguard Worker### Prerequisites
42*858ea5e5SAndroid Build Coastguard Worker
43*858ea5e5SAndroid Build Coastguard WorkerThere is no particular tool required for running the script, except `git` of
44*858ea5e5SAndroid Build Coastguard Workercourse.
45*858ea5e5SAndroid Build Coastguard Worker
46*858ea5e5SAndroid Build Coastguard WorkerHowever, you need a local copy of the Linux Git repository on your system
47*858ea5e5SAndroid Build Coastguard Workerin order to successfully run the script. You can set it up as follows:
48*858ea5e5SAndroid Build Coastguard Worker
49*858ea5e5SAndroid Build Coastguard Worker```console
50*858ea5e5SAndroid Build Coastguard Worker$ git clone 'https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git' linux
51*858ea5e5SAndroid Build Coastguard Worker$ cd linux
52*858ea5e5SAndroid Build Coastguard Worker$ git remote rename origin bpf-next
53*858ea5e5SAndroid Build Coastguard Worker$ git branch --move master bpf-next
54*858ea5e5SAndroid Build Coastguard Worker$ git remote add bpf 'https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git'
55*858ea5e5SAndroid Build Coastguard Worker$ git fetch bpf
56*858ea5e5SAndroid Build Coastguard Worker$ git checkout bpf/master
57*858ea5e5SAndroid Build Coastguard Worker$ git switch --create bpf
58*858ea5e5SAndroid Build Coastguard Worker$ git branch --set-upstream-to bpf/master
59*858ea5e5SAndroid Build Coastguard Worker$ git switch bpf-next
60*858ea5e5SAndroid Build Coastguard Worker```
61*858ea5e5SAndroid Build Coastguard Worker
62*858ea5e5SAndroid Build Coastguard WorkerAt the end of the process, the repository should contain two branches
63*858ea5e5SAndroid Build Coastguard Worker`bpf-next` and `bpf`, pointing to the `master` branches of the `bpf-next` and
64*858ea5e5SAndroid Build Coastguard Worker`bpf` remote repositories, respectively. These two branches are required to
65*858ea5e5SAndroid Build Coastguard Workersynchronize the mirror correctly.
66*858ea5e5SAndroid Build Coastguard Worker
67*858ea5e5SAndroid Build Coastguard WorkerYou can later update this repository with the following commands:
68*858ea5e5SAndroid Build Coastguard Worker
69*858ea5e5SAndroid Build Coastguard Worker```console
70*858ea5e5SAndroid Build Coastguard Worker$ git switch bpf
71*858ea5e5SAndroid Build Coastguard Worker$ git pull --set-upstream bpf master
72*858ea5e5SAndroid Build Coastguard Worker$ git switch bpf-next
73*858ea5e5SAndroid Build Coastguard Worker$ git pull --set-upstream bpf-next master
74*858ea5e5SAndroid Build Coastguard Worker```
75*858ea5e5SAndroid Build Coastguard Worker
76*858ea5e5SAndroid Build Coastguard WorkerAlso make sure you have cloned the bpftool mirror recursively, to check out the
77*858ea5e5SAndroid Build Coastguard Workerlibbpf submodule. If you have not, run the following:
78*858ea5e5SAndroid Build Coastguard Worker
79*858ea5e5SAndroid Build Coastguard Worker```console
80*858ea5e5SAndroid Build Coastguard Worker$ git submodule update --init
81*858ea5e5SAndroid Build Coastguard Worker```
82*858ea5e5SAndroid Build Coastguard Worker
83*858ea5e5SAndroid Build Coastguard Worker### Usage
84*858ea5e5SAndroid Build Coastguard Worker
85*858ea5e5SAndroid Build Coastguard WorkerAs preliminary steps:
86*858ea5e5SAndroid Build Coastguard Worker
87*858ea5e5SAndroid Build Coastguard Worker- Make sure that you have a Linux Git repository installed (see above), with
88*858ea5e5SAndroid Build Coastguard Worker  two branches `bpf-next` and `bpf` up-to-date.
89*858ea5e5SAndroid Build Coastguard Worker- Make sure your mirror repository is clean.
90*858ea5e5SAndroid Build Coastguard Worker
91*858ea5e5SAndroid Build Coastguard WorkerThen run the script:
92*858ea5e5SAndroid Build Coastguard Worker
93*858ea5e5SAndroid Build Coastguard Worker```console
94*858ea5e5SAndroid Build Coastguard Worker$ ./sync-kernel.sh <bpftool-repo> <kernel-repo>
95*858ea5e5SAndroid Build Coastguard Worker```
96*858ea5e5SAndroid Build Coastguard Worker
97*858ea5e5SAndroid Build Coastguard WorkerIf working from within the bpftool repository, the path to the `<bpftool-repo>`
98*858ea5e5SAndroid Build Coastguard Workeris typically the current working directory (`.`). The second argument,
99*858ea5e5SAndroid Build Coastguard Worker`<kernel-repo>`, is the path to the Linux Git repository mentioned earlier.
100*858ea5e5SAndroid Build Coastguard Worker
101*858ea5e5SAndroid Build Coastguard WorkerSeveral environment variables can modify some internal parameters of the
102*858ea5e5SAndroid Build Coastguard Workerscript:
103*858ea5e5SAndroid Build Coastguard Worker
104*858ea5e5SAndroid Build Coastguard Worker- Set `BPF_NEXT_BASELINE `to override the `bpf-next` tree commit to use (the
105*858ea5e5SAndroid Build Coastguard Worker  commit from the `bpf-next` branch with which the bpftool repository is
106*858ea5e5SAndroid Build Coastguard Worker  currently synchronized, prior to running the script). If unset, use the hash
107*858ea5e5SAndroid Build Coastguard Worker  from `<bpftool-repo>/CHECKPOINT-COMMIT` is used.
108*858ea5e5SAndroid Build Coastguard Worker- Set `BPF_BASELINE `to override the `bpf` tree commit to use (the commit from
109*858ea5e5SAndroid Build Coastguard Worker  the `bpf` branch with which the bpftool repository is currently synchronized,
110*858ea5e5SAndroid Build Coastguard Worker  prior to running the script). If unset, use the hash from
111*858ea5e5SAndroid Build Coastguard Worker  `<bpftool-repo>/BPF-CHECKPOINT-COMMIT` is used.
112*858ea5e5SAndroid Build Coastguard Worker- Set `BPF_NEXT_TIP_COMMIT` to override the `bpf-next` tree target commit (the
113*858ea5e5SAndroid Build Coastguard Worker  commit in `bpf-next` up to which the bpftool mirror should be synchronized).
114*858ea5e5SAndroid Build Coastguard Worker  If unset, use the hash from `<bpftool-repo>/libbpf/CHECKPOINT-COMMIT`, after
115*858ea5e5SAndroid Build Coastguard Worker  the libbpf repository update that takes place at the beginning of the update
116*858ea5e5SAndroid Build Coastguard Worker  process.
117*858ea5e5SAndroid Build Coastguard Worker- Set `BPF_TIP_COMMIT` to override the `bpf` tree target commit (the commit in
118*858ea5e5SAndroid Build Coastguard Worker  `bpf` up to which the bpftool mirror should be synchronized). If unset, use
119*858ea5e5SAndroid Build Coastguard Worker  the hash from `<bpftool-repo>/libbpf/BPF-CHECKPOINT-COMMIT`, after the libbpf
120*858ea5e5SAndroid Build Coastguard Worker  repository update that takes place at the beginning of the update process.
121*858ea5e5SAndroid Build Coastguard Worker- Set `SKIP_LIBBPF_UPDATE` to `1` to avoid updating libbpf automatically.
122*858ea5e5SAndroid Build Coastguard Worker- Set `MANUAL_MODE` to `1` to manually control every cherry-picked commit.
123*858ea5e5SAndroid Build Coastguard Worker
124*858ea5e5SAndroid Build Coastguard Worker### How it works
125*858ea5e5SAndroid Build Coastguard Worker
126*858ea5e5SAndroid Build Coastguard WorkerThis script synchronizes the bpftool mirror with upstream bpftool sources from
127*858ea5e5SAndroid Build Coastguard Workerthe Linux kernel repository.
128*858ea5e5SAndroid Build Coastguard Worker
129*858ea5e5SAndroid Build Coastguard WorkerIt performs the following steps:
130*858ea5e5SAndroid Build Coastguard Worker
131*858ea5e5SAndroid Build Coastguard Worker- First, the script updates the libbpf submodule, commits the change, and (by
132*858ea5e5SAndroid Build Coastguard Worker  default) picks up libbpf's latest checkpoints to use them as target commits
133*858ea5e5SAndroid Build Coastguard Worker  for the bpftool mirror.
134*858ea5e5SAndroid Build Coastguard Worker
135*858ea5e5SAndroid Build Coastguard Worker- In the Linux repository, from the `bpf-next` branch, it creates new branches,
136*858ea5e5SAndroid Build Coastguard Worker  filters out all non-bpftool-related files, and reworks the layout to
137*858ea5e5SAndroid Build Coastguard Worker  replicate the layout from the bpftool mirror.
138*858ea5e5SAndroid Build Coastguard Worker
139*858ea5e5SAndroid Build Coastguard Worker- It generates patches for each commit touching `bpftool` or the required UAPI
140*858ea5e5SAndroid Build Coastguard Worker  files, up to the target commit, and exports these patches to a temporary
141*858ea5e5SAndroid Build Coastguard Worker  repository.
142*858ea5e5SAndroid Build Coastguard Worker
143*858ea5e5SAndroid Build Coastguard Worker- In a new branch in the bpftool mirror, the script applies (`git am`) each of
144*858ea5e5SAndroid Build Coastguard Worker  these patches to the mirror.
145*858ea5e5SAndroid Build Coastguard Worker
146*858ea5e5SAndroid Build Coastguard Worker- Then the script checks out the `bpf` branch in the Linux repository, and
147*858ea5e5SAndroid Build Coastguard Worker  repeats the same operations.
148*858ea5e5SAndroid Build Coastguard Worker
149*858ea5e5SAndroid Build Coastguard Worker- On top of the new patches applied to the mirror, the script creates a last
150*858ea5e5SAndroid Build Coastguard Worker  commit with the updated checkpoints, using a cover letter summarizing the
151*858ea5e5SAndroid Build Coastguard Worker  changes as the commit description.
152*858ea5e5SAndroid Build Coastguard Worker
153*858ea5e5SAndroid Build Coastguard Worker- The next step is verification. The script applies to the Linux repository
154*858ea5e5SAndroid Build Coastguard Worker  (`bpf-next` branch) a patch containing known differences between the Linux
155*858ea5e5SAndroid Build Coastguard Worker  repository and the bpftool mirror. Then it looks for remaining differences
156*858ea5e5SAndroid Build Coastguard Worker  between the two repositories, and warn the user if it finds any. Patches
157*858ea5e5SAndroid Build Coastguard Worker  picked up from the `bpf` tree are usually a source of differences at this
158*858ea5e5SAndroid Build Coastguard Worker  step. If the patch containing the known differences is to be updated after
159*858ea5e5SAndroid Build Coastguard Worker  the synchronization in progress, the user should do it at this time, before
160*858ea5e5SAndroid Build Coastguard Worker  the temporary files from the script are deleted.
161*858ea5e5SAndroid Build Coastguard Worker
162*858ea5e5SAndroid Build Coastguard Worker- At last, the script cleans up the temporary files and branches in the Linux
163*858ea5e5SAndroid Build Coastguard Worker  repository. Note that these temporary files and branches are not cleaned up
164*858ea5e5SAndroid Build Coastguard Worker  if the script fails during execution.
165