• Home
Name Date Size #Lines LOC

..--

patch_sync/03-May-2024-1,7451,451

README.mdD03-May-202416.5 KiB590435

auto_llvm_bisection.pyD03-May-20245.6 KiB187112

auto_llvm_bisection_unittest.pyD03-May-20248.3 KiB254201

bisect_clang_crashes.pyD03-May-20244.4 KiB138108

bisect_clang_crashes_unittest.pyD03-May-20243.4 KiB9270

chroot.pyD03-May-20242.5 KiB9755

chroot_unittest.pyD03-May-20242 KiB6735

copy_helpers_to_chromiumos_overlay.pyD03-May-20241.9 KiB6846

custom_script_example.pyD03-May-20242.2 KiB7327

failure_modes.pyD03-May-2024642 2411

fetch_cros_sdk_rolls.pyD03-May-20243.2 KiB11181

get_llvm_hash.pyD03-May-202411.8 KiB408279

get_llvm_hash_unittest.pyD03-May-20245.3 KiB140101

get_upstream_patch.pyD03-May-202415.9 KiB466365

git.pyD03-May-20243.5 KiB13688

git_llvm_rev.pyD03-May-202410.7 KiB383272

git_llvm_rev_test.pyD03-May-20245.3 KiB13174

git_unittest.pyD03-May-20244.6 KiB14697

llvm_bisection.pyD03-May-202413.6 KiB377249

llvm_bisection_unittest.pyD03-May-202415.3 KiB510371

llvm_patch_management.pyD03-May-20248.9 KiB277163

llvm_patch_management_unittest.pyD03-May-202411.6 KiB308169

llvm_project.pyD03-May-20241.9 KiB6543

modify_a_tryjob.pyD03-May-202410.3 KiB297187

modify_a_tryjob_unittest.pyD03-May-202414 KiB403266

nightly_revert_checker.pyD03-May-202413.7 KiB407329

nightly_revert_checker_test.pyD03-May-20246.3 KiB198160

patch_manager.pyD03-May-202427 KiB756416

patch_manager_unittest.pyD03-May-202434.6 KiB956583

revert_checker.pyD03-May-20248.7 KiB271183

subprocess_helpers.pyD03-May-20241.5 KiB5929

test_helpers.pyD03-May-20242.2 KiB9054

update_chromeos_llvm_hash.pyD03-May-202420.5 KiB630404

update_chromeos_llvm_hash_unittest.pyD03-May-202436.5 KiB885594

update_packages_and_run_tests.pyD03-May-202415.5 KiB485319

update_packages_and_run_tests_unittest.pyD03-May-202414.5 KiB450332

update_tryjob_status.pyD03-May-20248.7 KiB265162

update_tryjob_status_unittest.pyD03-May-202416.4 KiB478303

upload_lexan_crashes_to_forcey.pyD03-May-20248.9 KiB272179

upload_lexan_crashes_to_forcey_test.pyD03-May-20244.8 KiB147119

README.md

1# LLVM Tools
2
3## Overview
4
5These scripts helps automate tasks such as updating the LLVM next hash,
6determing whether a new patch applies correctly, and patch management.
7
8In addition, there are scripts that automate the process of retrieving the
9git hash of LLVM from either google3, top of trunk, or for a specific SVN
10version.
11
12**NOTE: All scripts must must be run outside the chroot**
13
14**NOTE: sudo must be permissive (i.e. **`cros_sdk`** should NOT prompt for a
15password)**
16
17## `update_packages_and_run_tests.py`
18
19### Usage
20
21This script is used for updating a package's LLVM hash (sys-devel/llvm,
22sys-libs/compiler-rt, sys-libs/libcxx, sys-libs/libcxxabi, and
23sys-libs/llvm-libunwind) and then run tests after updating the git hash.
24There are three ways to test the change, including starting tryjobs,
25recipe builders or using cq+1.
26
27An example when this script should be run is when certain boards would like
28to be tested with the updated `LLVM_NEXT_HASH`.
29
30For example:
31
32```
33$ ./update_packages_and_run_tests.py \
34  --is_llvm_next \
35  --llvm_version tot \
36  tryjobs \
37  --options nochromesdk latest-toolchain \
38  --builders kevin-release-tryjob nocturne-release-tryjob
39```
40
41The above example would update the packages' `LLVM_NEXT_HASH` to the top of
42trunk's git hash and would submit tryjobs for kevin and nocturne boards, passing
43in 'nochromesdk' and 'latest-toolchain' for each tryjob.
44
45For help with the command line arguments of the script, run:
46
47```
48$ ./update_packages_and_run_tests.py --help
49```
50
51Similarly as the previous example, but for updating `LLVM_HASH` to
52google3 and test with cq+1:
53
54```
55$ ./update_packages_and_run_tests.py \
56  --llvm_version google3 \
57  cq
58```
59
60Similarly as the previous example, but for updating `LLVM_NEXT_HASH` to
61the git hash of revision 367622 and test with recipe builders:
62
63```
64$ ./update_packages_and_run_tests.py \
65  --is_llvm_next \
66  --llvm_version 367622 \
67  recipe \
68  --options -nocanary \
69  --builders chromeos/toolchain/kevin-llvm chromeos/toolchain/nocturne-llvm
70```
71
72## `update_chromeos_llvm_hash.py`
73
74### Usage
75
76This script is used for updating a package's/packages' LLVM hashes and
77creating a change list of those changes which will uploaded for review. For
78example, some changes that would be included in the change list are
79the updated ebuilds, changes made to the patches of the updated packages such
80as being removed or an updated patch metadata file. These changes are determined
81by the `--failure_mode` option.
82
83An example where this script would be used is when multiple packages need to
84have their `LLVM_NEXT_HASH` updated.
85
86For example:
87
88```
89$ ./update_chromeos_llvm_hash.py \
90  --update_packages sys-devel/llvm sys-libs/compiler-rt \
91  --is_llvm_next \
92  --llvm_version google3 \
93  --failure_mode disable_patches
94```
95
96The example above would update sys-devel/llvm and sys-libs/compiler-rt's
97`LLVM_NEXT_HASH` to the latest google3's git hash of LLVM. And the change list
98may include patches that were disabled for either sys-devel/llvm or
99sys-libs/compiler-rt.
100
101For help with the command line arguments of the script, run:
102
103```
104$ ./update_chromeos_llvm_hash.py --help
105```
106
107For example, to update `LLVM_HASH` to top of trunk of LLVM:
108
109```
110$ ./update_chromeos_llvm_hash.py \
111  --update_packages sys-devel/llvm sys-libs/compiler-rt \
112  --llvm_version tot \
113  --failure_mode disable_patches
114```
115
116For example, to create a roll CL to the git hash of revision 367622:
117
118```
119$ ./update_chromeos_llvm_hash.py \
120  --update_packages sys-devel/llvm sys-libs/compiler-rt \
121  sys-libs/libcxx sys-libs/libcxxabi sys-libs/llvm-libunwind \
122  'dev-util/lldb-server' \
123  --llvm_version 367622 \
124  --failure_mode disable_patches
125```
126
127## `llvm_patch_management.py`
128
129### Usage
130
131This script is used to test whether a newly added patch in a package's patch
132metadata file would apply successfully. The script is also used to make sure
133the patches of a package applied successfully, failed, etc., depending on the
134failure mode specified.
135
136An example of using this script is when multiple packages would like to be
137tested when a new patch was added to their patch metadata file.
138
139For example:
140
141```
142$ ./llvm_patch_management.py \
143  --packages sys-devel/llvm sys-libs/compiler-rt \
144  --failure_mode continue
145```
146
147The above example tests sys-devel/llvm and sys-libs/compiler-rt patch metadata
148file with the failure mode `continue`.
149
150For help with the command line arguments of the script, run:
151
152```
153$ ./llvm_patch_management.py --help
154```
155
156## `patch_manager.py`
157
158### Usage
159
160This script is used when when all the command line arguments are known such as
161testing a specific metadata file or a specific source tree.
162
163For help with the command line arguments of the script, run:
164
165```
166$ ./patch_manager.py --help
167```
168
169For example, to see all the failed (if any) patches:
170
171```
172$ ./patch_manager.py \
173  --svn_version 367622 \
174  --patch_metadata_file /abs/path/to/patch/file \
175  --filesdir_path /abs/path/to/$FILESDIR \
176  --src_path /abs/path/to/src/tree \
177  --failure_mode continue
178```
179
180For example, to disable all patches that failed to apply:
181
182```
183$ ./patch_manager.py \
184  --svn_version 367622 \
185  --patch_metadata_file /abs/path/to/patch/file \
186  --filesdir_path /abs/path/to/$FILESDIR \
187  --src_path /abs/path/to/src/tree \
188  --failure_mode disable_patches
189```
190
191For example, to remove all patches that no longer apply:
192
193```
194$ ./patch_manager.py \
195  --svn_version 367622 \
196  --patch_metadata_file /abs/path/to/patch/file \
197  --filesdir_path /abs/path/to/$FILESDIR \
198  --src_path /abs/path/to/src/tree \
199  --failure_mode remove_patches
200```
201
202For example, to bisect a failing patch and stop at the first bisected patch:
203
204```
205$ ./patch_manager.py \
206  --svn_version 367622 \
207  --patch_metadata_file /abs/path/to/patch/file \
208  --filesdir_path /abs/path/to/$FILESDIR \
209  --src_path /abs/path/to/src/tree \
210  --failure_mode bisect_patches \
211  --good_svn_version 365631
212```
213
214For example, to bisect a failing patch and then continue bisecting the rest of
215the failed patches:
216
217```
218$ ./patch_manager.py \
219  --svn_version 367622 \
220  --patch_metadata_file /abs/path/to/patch/file \
221  --filesdir_path /abs/path/to/$FILESDIR \
222  --src_path /abs/path/to/src/tree \
223  --failure_mode bisect_patches \
224  --good_svn_version 365631 \
225  --continue_bisection True
226```
227
228## LLVM Bisection
229
230### `llvm_bisection.py`
231
232#### Usage
233
234This script is used to bisect a bad revision of LLVM. After the script finishes,
235the user requires to run the script again to continue the bisection. Intially,
236the script creates a JSON file that does not exist which then continues
237bisection (after invoking the script again) based off of the JSON file.
238
239For example, assuming the revision 369420 is the bad revision:
240
241```
242$ ./llvm_bisection.py \
243  --parallel 3 \
244  --start_rev 369410 \
245  --end_rev 369420 \
246  --last_tested /abs/path/to/tryjob/file/ \
247  --extra_change_lists 513590 \
248  --builder eve-release-tryjob \
249  --options latest-toolchain
250```
251
252The above example bisects the bad revision (369420), starting from the good
253revision 369410 and launching 3 tryjobs in between if possible (`--parallel`).
254Here, the `--last_tested` path is a path to a JSON file that does not exist. The
255tryjobs are tested on the eve board. `--extra_change_lists` and `--options`
256indicate what parameters to pass into launching a tryjob.
257
258For help with the command line arguments of the script, run:
259
260```
261$ ./llvm_bisection.py --help
262```
263
264### `auto_llvm_bisection.py`
265
266#### Usage
267
268This script automates the LLVM bisection process by using `cros buildresult` to
269update the status of each tryjob.
270
271An example when this script would be used to do LLVM bisection overnight
272because tryjobs take very long to finish.
273
274For example, assuming the good revision is 369410 and the bad revision is
275369420, then:
276
277```
278$ ./auto_llvm_bisection.py --start_rev 369410 --end_rev 369420 \
279  --last_tested /abs/path/to/last_tested_file.json \
280  --extra_change_lists 513590 1394249 \
281  --options latest-toolchain nochromesdk \
282  --chroot_path /path/to/chromeos/chroot \
283  --builder eve-release-tryjob
284```
285
286The example above bisects LLVM between revision 369410 and 369420. If the file
287exists, the script resumes bisection. Otherwise, the script creates the file
288provided by `--last_tested`. `--extra_change_lists` and `--options` are used for
289each tryjob when being submitted. Lastly, the tryjobs are launched for the board
290provided by `--builder` (in this example, for the eve board).
291
292For help with the command line arguments of the script, run:
293
294```
295$ ./auto_llvm_bisection.py --help
296```
297
298### `update_tryjob_status.py`
299
300#### Usage
301
302This script updates a tryjob's 'status' value when bisecting LLVM. This script
303can use the file that was created by `llvm_bisection.py`.
304
305An example when this script would be used is when the result of tryjob that was
306launched was 'fail' (due to flaky infra) but it should really have been
307'success'.
308
309For example, to update a tryjob's 'status' to 'good':
310
311```
312$ ./update_tryjob_status.py \
313  --set_status good \
314  --revision 369412 \
315  --status_file /abs/path/to/tryjob/file
316```
317
318The above example uses the file in `--status_file` to update a tryjob in that
319file that tested the revision 369412 and sets its 'status' value to 'good'.
320
321For help with the command line arguments of the script, run:
322
323```
324$ ./update_tryjob_status.py --help
325```
326
327For example, to update a tryjob's 'status' to 'bad':
328
329```
330$ ./update_tryjob_status.py \
331  --set_status bad \
332  --revision 369412 \
333  --status_file /abs/path/to/tryjob/file
334```
335
336For example, to update a tryjob's 'status' to 'pending':
337
338```
339$ ./update_tryjob_status.py \
340  --set_status pending \
341  --revision 369412 \
342  --status_file /abs/path/to/tryjob/file
343```
344
345For example, to update a tryjob's 'status' to 'skip':
346
347```
348$ ./update_tryjob_status.py \
349  --set_status skip \
350  --revision 369412 \
351  --status_file /abs/path/to/tryjob/file
352```
353
354For example, to update a tryjob's 'status' based off a custom script exit code:
355
356```
357$ ./update_tryjob_status.py \
358  --set_status custom_script \
359  --revision 369412 \
360  --status_file /abs/path/to/tryjob/file \
361  --custom_script /abs/path/to/script.py
362```
363
364### `modify_a_tryjob.py`
365
366#### Usage
367
368This script modifies a tryjob directly given an already created tryjob file when
369bisecting LLVM. The file created by `llvm_bisection.py` can be used in this
370script.
371
372An example when this script would be used is when a tryjob needs to be manually
373added.
374
375For example:
376
377```
378$ ./modify_a_tryjob.py \
379  --modify_a_tryjob add \
380  --revision 369416 \
381  --extra_change_lists 513590 \
382  --options latest-toolchain \
383  --builder eve-release-tryjob \
384  --status_file /abs/path/to/tryjob/file
385```
386
387The above example creates a tryjob that tests revision 369416 on the eve board,
388passing in the extra arguments (`--extra_change_lists` and `--options`). The
389tryjob is then inserted into the file passed in via `--status_file`.
390
391For help with the command line arguments of the script, run:
392
393```
394$ ./modify_a_tryjob.py --help
395```
396
397For example, to remove a tryjob that tested revision 369412:
398
399```
400$ ./modify_a_tryjob.py \
401  --modify_a_tryjob remove \
402  --revision 369412 \
403  --status_file /abs/path/to/tryjob/file
404```
405
406For example, to relaunch a tryjob that tested revision 369418:
407
408```
409$ ./modify_a_tryjob.py \
410  --modify_a_tryjob relaunch \
411  --revision 369418 \
412  --status_file /abs/path/to/tryjob/file
413```
414
415## Other Helpful Scripts
416
417### `get_llvm_hash.py`
418
419#### Usage
420
421The script has a class that deals with retrieving either the top of trunk git
422hash of LLVM, the git hash of google3, or a specific git hash of a SVN version.
423It also has other functions when dealing with a git hash of LLVM.
424
425In addition, it has a function to retrieve the latest google3 LLVM version.
426
427For example, to retrieve the top of trunk git hash of LLVM:
428
429```
430from get_llvm_hash import LLVMHash
431
432LLVMHash().GetTopOfTrunkGitHash()
433```
434
435For example, to retrieve the git hash of google3:
436
437```
438from get_llvm_hash import LLVMHash
439
440LLVMHash().GetGoogle3LLVMHash()
441```
442
443For example, to retrieve the git hash of a specific SVN version:
444
445```
446from get_llvm_hash import LLVMHash
447
448LLVMHash().GetLLVMHash(<svn_version>)
449```
450
451For example, to retrieve the latest google3 LLVM version:
452
453```
454from get_llvm_hash import GetGoogle3LLVMVersion
455
456GetGoogle3LLVMVersion(stable=True)
457```
458
459### `git_llvm_rev.py`
460
461This script is meant to synthesize LLVM revision numbers, and translate between
462these synthesized numbers and git SHAs. Usage should be straightforward:
463
464```
465~> ./git_llvm_rev.py --llvm_dir llvm-project-copy/ --rev r380000
4666f635f90929da9545dd696071a829a1a42f84b30
467~> ./git_llvm_rev.py --llvm_dir llvm-project-copy/ --sha 6f635f90929da9545dd696071a829a1a42f84b30
468r380000
469~> ./git_llvm_rev.py --llvm_dir llvm-project-copy/ --sha origin/some-branch
470r387778
471```
472
473**Tip**: if you put a symlink called `git-llvm-rev` to this script somewhere on
474your `$PATH`, you can also use it as `git llvm-rev`.
475
476### `get_upstream_patch.py`
477
478#### Usage
479
480This script updates the proper ChromeOS packages with LLVM patches of your choosing, and
481copies the patches into patch folders of the packages. This tool supports both git hash
482of commits as well as differential reviews.
483
484Usage:
485
486```
487./get_upstream_patch.py --chroot_path /abs/path/to/chroot --start_sha llvm
488--sha 174c3eb69f19ff2d6a3eeae31d04afe77e62c021 --sha 174c3eb69f19ff2d6a3eeae31d04afe77e62c021
489--differential D123456
490```
491
492It tries to autodetect a lot of things (e.g., packages changed by each sha,
493their ebuild paths, the "start"/"end" revisions to set, etc.) By default the
494script creates a local patch. Use --create_cl option to create a CL instead. For
495more information, please see the `--help`
496
497### `revert_checker.py`
498
499**This script is copied from upstream LLVM. Please prefer to make upstream edits,
500rather than modifying this script. It's kept in a CrOS repo so we don't need an
501LLVM tree to `import` this from scripts here.**
502
503This script reports reverts which happen 'across' a certain LLVM commit.
504
505To clarify the meaning of 'across' with an example, if we had the following
506commit history (where `a -> b` notes that `b` is a direct child of `a`):
507
508123abc -> 223abc -> 323abc -> 423abc -> 523abc
509
510And where 423abc is a revert of 223abc, this revert is considered to be 'across'
511323abc. More generally, a revert A of a parent commit B is considered to be
512'across' a commit C if C is a parent of A and B is a parent of C.
513
514Usage example:
515
516```
517./revert_checker.py -C llvm-project-copy 123abc 223abc 323abc
518```
519
520In the above example, the tool will scan all commits between 123abc and 223abc,
521and all commits between 123abc and 323abc for reverts of commits which are
522parents of 123abc.
523
524### `nightly_revert_checker.py`
525
526This is an automated wrapper around `revert_checker.py`. It checks to see if any
527new reverts happened across toolchains that we're trying to ship since it was
528last run. If so, it either automatically cherry-picks the reverts, or sends
529emails to appropriate groups.
530
531Usage example for cherry-picking:
532```
533PYTHONPATH=../ ./nightly_revert_checker.py \
534  cherry-pick
535  --state_file state.json \
536  --llvm_dir llvm-project-copy \
537  --chromeos_dir ../../../../
538  --reviewers=chromium-os-mage@google.com
539```
540
541Usage example for email:
542```
543PYTHONPATH=../ ./nightly_revert_checker.py \
544  email
545  --state_file state.json \
546  --llvm_dir llvm-project-copy \
547  --chromeos_dir ../../../../
548```
549
550### `bisect_clang_crashes.py`
551
552This script downloads clang crash diagnoses from
553gs://chromeos-toolchain-artifacts/clang-crash-diagnoses and sends them to 4c for
554bisection.
555
556Usage example:
557
558```
559$ ./bisect_clang_crashes.py --4c 4c-cli --state_file ./output/state.json
560```
561
562The above command downloads the artifacts of clang crash diagnoses and send them
563to 4c server for bisection. The summary of submitted jobs will be saved in
564output/state.json under the current path. The output directory will be created
565automatically if it does not exist yet. To get more information of the submitted
566jobs, please refer to go/4c-cli.
567
568### `upload_lexan_crashes_to_forcey.py`
569
570This script downloads clang crash diagnoses from Lexan's bucket and sends them
571to 4c for bisection.
572
573Usage example:
574
575```
576$ ./upload_lexan_crashes_to_forcey.py --4c 4c-cli \
577    --state_file ./output/state.json
578```
579
580The above command downloads the artifacts of clang crash diagnoses and send them
581to 4c server for bisection. The summary of submitted jobs will be saved in
582output/state.json under the current path. The output directory will be created
583automatically if it does not exist yet. To get more information of the submitted
584jobs, please refer to go/4c-cli.
585
586Note that it's recommended to 'seed' the state file with a most recent upload
587date. This can be done by running this tool *once* with a `--last_date` flag.
588This flag has the script override whatever's in the state file (if anything) and
589start submitting all crashes uploaded starting at the given day.
590