Bug 1815516 - extend expiration of test variant conditioned-profile. r=suhaib
[gecko.git] / gfx / angle / vendor_from_git.py
blob95ea39286633a5da4d0cd3059b85d641d55b467d
1 #! /usr/bin/env python3
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 assert __name__ != "__main__"
8 """
9 Any time we vendor[1] from an external git repo, we want to keep a record of the csets
10 we're pulling from.
12 This script leaves a record of the merge-base reference tip and cherry-picks that we pull
13 into Gecko. (such as gfx/angle/cherry_picks.txt)
14 """
16 from pathlib import *
17 import subprocess
18 import sys
20 # --
23 def print_now(*args):
24 print(*args)
25 sys.stdout.flush()
28 def run_checked(*args, **kwargs):
29 print(" ", args)
30 sys.stdout.flush()
31 return subprocess.run(args, check=True, **kwargs)
34 # --
37 def record_cherry_picks(dir_in_gecko, merge_base_origin):
38 # merge_base_origin is not always 'origin'!
39 base_merge_base_from = Path(dir_in_gecko, "MERGE_BASE").read_text().split("\n")[0]
40 merge_base_from = merge_base_origin + "/" + base_merge_base_from
42 assert "/" in merge_base_from, "Please specify a reference tip from a remote."
43 log_path = Path(dir_in_gecko, "cherry_picks.txt")
44 print_now("Logging cherry picks to {}.".format(log_path))
46 merge_base = (
47 run_checked(
48 "git", "merge-base", "HEAD", merge_base_from, stdout=subprocess.PIPE
50 .stdout.decode()
51 .strip()
53 merge_base_readable = (
54 run_checked(
55 "git",
56 "show",
57 "-s",
58 "--format=commit %H %cd",
59 merge_base,
60 stdout=subprocess.PIPE,
62 .stdout.decode()
63 .strip()
66 mb_info = run_checked(
67 "git", "log", "{}~1..{}".format(merge_base, merge_base), stdout=subprocess.PIPE
68 ).stdout
69 cherries = run_checked(
70 "git", "log", merge_base + "..", stdout=subprocess.PIPE
71 ).stdout
73 with open(log_path, "wb") as f:
74 f.write(cherries)
75 f.write(b"\nAbove: cherries picked")
76 f.write(b"\n" + (b"=" * 80))
77 f.write(b"\nBelow: merge base from: " + merge_base_from.encode())
78 f.write(b"\n\n")
79 f.write(mb_info)
81 # The below supports only a single commit-alert task. If/when we add another task, this
82 # will need to be improved.
83 print_now("Updating moz.yaml")
84 moz_yaml_file = Path(dir_in_gecko, "moz.yaml")
85 with open(moz_yaml_file, "r") as f:
86 moz_yaml_contents = f.readlines()
87 with open(moz_yaml_file, "wb") as f:
88 for line in moz_yaml_contents:
90 def prefix():
91 return line[0 : line.index(": ") + 2].encode()
93 if "branch: " in line:
94 f.write(prefix() + base_merge_base_from.encode() + b"\n")
95 elif "release: " in line:
96 f.write(prefix() + merge_base_readable.encode() + b"\n")
97 elif "revision: " in line:
98 f.write(prefix() + merge_base.encode() + b"\n")
99 else:
100 f.write(line.encode())