-
Notifications
You must be signed in to change notification settings - Fork 6
/
apply_bromite_patches.py
executable file
·96 lines (80 loc) · 3.45 KB
/
apply_bromite_patches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
'''
This script will apply patches from bromite to a chromium/src checkout
It wll also configure the output directory with the specified args
'''
import os
import argparse
import subprocess
from subprocess import PIPE
import shutil
from _load_vars import load_vars
# Parse args
args = load_vars(argparse.ArgumentParser(
description='Configure chromium directory with bromite checkout and patches'
))
chromium = args["chromium"]
bromite = args["bromite"]
root = args["root"]
build_name = args["build_name"]
build_path = args["build_path"]
depot_tools = args["depot_tools"]
env = args["env"]
bromite_build_folder = os.path.join(bromite, 'build')
# Checkout version from RELEASE (or RELEASE_COMMIT?)
print("Checkout chromium version")
release_file_name = os.path.join(bromite_build_folder, 'RELEASE_COMMIT')
with open(release_file_name, 'r', encoding='utf8') as release_file:
checkout_value = release_file.read()
print("Checking if commit already downloaded")
to_exec = f"git cat-file -t {checkout_value}"
result = subprocess.run(
to_exec, cwd=chromium,
shell=True, check=False, env=env,
stderr=PIPE, stdout=PIPE, encoding="utf8")
has_commit = "commit" in result.stdout
if has_commit:
print("Commit already downloaded")
else:
print(f"Fetching release commit {checkout_value}")
to_exec = f"git fetch --depth=1 origin {checkout_value}"
subprocess.run(to_exec, cwd=chromium, shell=True, check=True, env=env)
print(f"Checking out: {checkout_value}")
to_exec = f"git checkout {checkout_value}"
subprocess.run(to_exec, cwd=chromium, shell=True, check=True, env=env)
if not has_commit:
out_folder = os.path.join(chromium, build_path)
if os.path.exists(out_folder):
print("Looks like first time checking out, syncing build tools")
subprocess.run('gclient sync -D', cwd=chromium, shell=True, check=True, env=env)
# Copy build/bromite.gn_args to out/Default/args.gn (configurable?) (check if exists?)
destination_gn_args = os.path.join(chromium, build_path, 'args.gn')
if os.path.exists(destination_gn_args):
print("Copy bromite gn args")
source_gn_args = os.path.join(bromite_build_folder, 'bromite.gn_args')
shutil.copyfile(source_gn_args, destination_gn_args)
else:
print("Skipping args.gn since build folder was not initialized")
print("Loading excluded patches list")
PATCHES_TO_SKIP = ""
patch_skip_list_file_name = os.path.join(root, "excluded_patches.txt")
with open(patch_skip_list_file_name, 'r', encoding="utf8") as patch_skip_file:
PATCHES_TO_SKIP = patch_skip_file.read()
# Get `bromite/build/bromite_patches_list.txt` and read each line
# Skip patches identified in "excluded_patches.txt"
print("Applying patches")
patch_list_file_name = os.path.join(
bromite_build_folder, 'bromite_patches_list.txt')
with open(patch_list_file_name, 'r', encoding='utf8') as patch_list:
for patch_name_raw in patch_list:
patch_name = patch_name_raw.strip()
if patch_name in PATCHES_TO_SKIP:
print(f"Skipping: {patch_name}")
continue
raw_patch_path = os.path.join(
bromite_build_folder, 'patches', patch_name.strip())
patch_path = os.path.abspath(raw_patch_path)
# Use `git am` to apply patches one by one from `bromite/build/patches/`
subprocess.run(f"git am {patch_path}",
cwd=chromium, shell=True, check=True)
print("Done!")