-
Notifications
You must be signed in to change notification settings - Fork 4
/
apply-patches.py
executable file
·171 lines (132 loc) · 5.57 KB
/
apply-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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
#
# The script that patches the firefox source into the librewolf source.
# fork of librewolf's script librewolf-patches.py
#
import sys
import os
import optparse
import time
from os.path import isfile, join
#
# general functions, skip these, they are not that interesting
#
start_time = time.time()
parser = optparse.OptionParser()
parser.add_option('-n', '--no-execute', dest='no_execute', default=False, action="store_true")
options, args = parser.parse_args()
def script_exit(statuscode):
if (time.time() - start_time) > 60:
# print elapsed time
elapsed = time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time))
print("\n\aElapsed time: {elapsed}")
sys.stdout.flush()
sys.exit(statuscode)
def exec(cmd, exit_on_fail = True, do_print = True):
if cmd != '':
if do_print:
print(cmd)
sys.stdout.flush()
if not options.no_execute:
retval = os.system(cmd)
if retval != 0 and exit_on_fail:
print(f"fatal error: command '{cmd}' failed")
sys.stdout.flush()
script_exit(1)
return retval
return None
def patch(patchfile: str):
cmd = f"patch -Np1 -i {patchfile}"
print(f"\n*** -> {cmd}")
sys.stdout.flush()
if not options.no_execute:
retval = os.system(cmd)
if retval != 0:
print(f"fatal error: patch '{patchfile}' failed")
sys.stdout.flush()
script_exit(1)
def enter_srcdir(directory: str):
print(f"cd {directory}")
sys.stdout.flush()
if not options.no_execute:
try:
os.chdir(directory)
except Exception:
print(f"fatal error: can't change to '{directory}' folder.")
sys.stdout.flush()
script_exit(1)
def leave_srcdir():
print("cd ..")
sys.stdout.flush()
if not options.no_execute:
os.chdir("..")
def gentoo_patches(firefox_folder: str, common_srcdir: str):
enter_srcdir(firefox_folder)
gentoo_path = join(common_srcdir, 'patches/gentoo')
patch_files = [f for f in os.listdir(gentoo_path) if isfile(join(gentoo_path, f))]
blacklist_patches = []
blacklist_filepath = join(common_srcdir, 'gentoo-patch-blacklist.txt')
if isfile(blacklist_filepath):
with open(blacklist_filepath, 'r') as f:
blacklist_patches = f.read().splitlines()
for patch_file in patch_files:
if any(denied_patch in patch_file for denied_patch in blacklist_patches):
continue
patch_filename = join(gentoo_path, patch_file)
patch(patch_filename)
leave_srcdir()
def librewolf_patches(firefox_folder: str, common_srcdir: str, settings_srcdir: str):
enter_srcdir(firefox_folder)
# copy branding files..
exec('cp -r {0} .'.format(join(common_srcdir, 'source_files/browser')))
# copy the right search-config.json file
exec('cp -v {0} services/settings/dumps/main/search-config.json'.format(join(common_srcdir, 'source_files/search-config.json')))
# read lines of .txt file into 'patches'
with open(join(common_srcdir, 'patches/librewolf-patchset.txt'), 'r') as f:
for line in f.read().splitlines():
patch(join(common_srcdir, line))
# apply xmas.patch seperately because not all builders use this repo the same way, and
# we don't want to disturbe those workflows.
# patch(join(common_srcdir, 'patches/librewolf/xmas.patch'))
#
# Apply most recent `settings` repository files.
#
exec('mkdir -p lw')
enter_srcdir('lw')
exec('cp -v {0} .'.format(join(settings_srcdir, 'cachyos.cfg')))
exec('cp -v {0} .'.format(join(settings_srcdir, 'distribution/policies.json')))
exec('cp -v {0} .'.format(join(settings_srcdir, 'defaults/pref/local-settings.js')))
leave_srcdir()
#
# pref-pane patches
#
# 1) patch it in
patch(join(common_srcdir, 'patches/pref-pane/pref-pane-small.patch'))
# 2) new files
exec('cp {0} browser/themes/shared/preferences/category-cachy-browser.svg'.format(join(common_srcdir, 'patches/pref-pane/category-cachy-browser.svg')))
exec('cp {0} browser/themes/shared/preferences/cachy-browser.css'.format(join(common_srcdir, 'patches/pref-pane/cachy-browser.css')))
exec('cp {0} browser/components/preferences/cachy-browser.inc.xhtml'.format(join(common_srcdir, 'patches/pref-pane/cachy-browser.inc.xhtml')))
exec('cp {0} browser/components/preferences/cachy-browser.js'.format(join(common_srcdir, 'patches/pref-pane/cachy-browser.js')))
# 3) append our locale string values to preferences.ftl
exec('cat browser/locales/en-US/browser/preferences/preferences.ftl {0} > preferences.ftl'.format(join(common_srcdir, 'patches/pref-pane/preferences.ftl')))
exec('mv preferences.ftl browser/locales/en-US/browser/preferences/preferences.ftl')
# generate locales
#exec("bash ../scripts/generate-locales.sh")
leave_srcdir()
#
# Main functionality in this script..
#
if len(args) != 3:
sys.stderr.write(f'Invalid usage! {sys.argv[0]} <firefox folder> <cachy-browser-common folder> <cachy-browser-settings folder>\n')
sys.exit(1)
firefox_folder = args[0]
cachy_common_folder = args[1]
cachy_settings_folder = args[2]
if not os.path.exists(join(firefox_folder, 'configure.py')):
sys.stderr.write('error: folder doesn\'t look like a Firefox folder.\n')
sys.exit(1)
print('---- Gentoo patches')
gentoo_patches(firefox_folder, cachy_common_folder)
print('---- Librewolf patches')
librewolf_patches(firefox_folder, cachy_common_folder, cachy_settings_folder)
sys.exit(0) # ensure 0 exit code