0
Fork 0
mirror of https://codeberg.org/librewolf/source.git synced 2024-12-22 21:53:31 -05:00
LibreWolf/scripts/librewolf-patches.py

165 lines
4.4 KiB
Python
Raw Normal View History

2021-11-19 12:41:54 -05:00
#!/usr/bin/env python3
2021-12-27 18:55:58 -05:00
#
# The script that patches the firefox source into the librewolf source.
#
2021-11-19 12:41:54 -05:00
import os
import sys
import optparse
import time
import glob
2021-12-27 18:55:58 -05:00
#
# general functions, skip these, they are not that interesting
#
2021-11-19 12:41:54 -05:00
2021-12-27 18:55:58 -05:00
start_time = time.time()
2021-11-19 12:41:54 -05:00
parser = optparse.OptionParser()
parser.add_option('-n', '--no-execute', dest='no_execute', default=False, action="store_true")
parser.add_option('-P', '--no-settings-pane', dest='settings_pane', default=True, action="store_false")
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))
2021-11-20 05:17:38 -05:00
print("\n\aElapsed time: {elapsed}")
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
sys.exit(statuscode)
def exec(cmd, exit_on_fail = True, do_print = True):
if cmd != '':
if do_print:
print(cmd)
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
if not options.no_execute:
retval = os.system(cmd)
if retval != 0 and exit_on_fail:
print("fatal error: command '{}' failed".format(cmd))
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
script_exit(1)
return retval
return None
def patch(patchfile):
cmd = "patch -p1 -i {}".format(patchfile)
print("\n*** -> {}".format(cmd))
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
if not options.no_execute:
retval = os.system(cmd)
if retval != 0:
print("fatal error: patch '{}' failed".format(patchfile))
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
script_exit(1)
def enter_srcdir(_dir = None):
if _dir == None:
dir = "librewolf-{}".format(version)
else:
dir = _dir
print("cd {}".format(dir))
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
if not options.no_execute:
try:
os.chdir(dir)
except:
print("fatal error: can't change to '{}' folder.".format(dir))
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
script_exit(1)
def leave_srcdir():
print("cd ..")
2021-11-20 05:17:38 -05:00
sys.stdout.flush()
2021-11-19 12:41:54 -05:00
if not options.no_execute:
os.chdir("..")
2021-12-27 18:55:58 -05:00
#
# This is the only interesting function in this script
#
2021-11-19 12:41:54 -05:00
def librewolf_patches():
enter_srcdir()
2021-12-27 18:55:58 -05:00
2021-11-19 12:41:54 -05:00
# create the right mozconfig file..
2021-11-19 14:46:23 -05:00
exec('cp -v ../assets/mozconfig .')
2021-11-19 12:41:54 -05:00
# copy branding files..
exec("cp -vr ../themes/browser .")
# copy the right search-config.json file
exec('cp -v ../assets/search-config.json services/settings/dumps/main/search-config.json')
2021-11-19 12:41:54 -05:00
# read lines of .txt file into 'patches'
2021-11-19 14:46:23 -05:00
f = open('../assets/patches.txt'.format(version), "r")
2021-11-19 12:41:54 -05:00
lines = f.readlines()
f.close()
patches = []
for line in lines:
patches.append('../'+line)
2021-11-19 12:41:54 -05:00
for p in patches:
patch(p)
2021-12-27 18:55:58 -05:00
# apply xmas.patch seperately
patch('../patches/xmas.patch')
2021-12-27 18:55:58 -05:00
#
# Create the 'lw' folder, it contains the librewolf.cfg and policies.json files.
#
exec('mkdir -p lw')
2021-11-19 12:41:54 -05:00
# insert the settings pane source (experimental)
2021-12-27 18:55:58 -05:00
exec('rm -rf librewolf-pref-pane')
2022-01-08 13:35:56 -05:00
exec('git clone https://gitlab.com/librewolf-community/browser/librewolf-pref-pane.git')
2021-12-27 18:55:58 -05:00
os.chdir('librewolf-pref-pane')
exec('git diff 1fee314adc81000294fc0cf3196a758e4b64dace > ../lw/librewolf-pref-pane.patch')
os.chdir('..')
exec('rm -rf librewolf-pref-pane')
patch('lw/librewolf-pref-pane.patch')
exec('rm -f lw/librewolf-pref-pane.patch')
2021-11-19 12:41:54 -05:00
2021-12-27 18:55:58 -05:00
##! This is the moment in time we grab the Settings repo HEAD revision
exec('git clone https://gitlab.com/librewolf-community/settings.git')
exec("cp -v settings/defaults/pref/local-settings.js lw/")
exec("cp -v settings/distribution/policies.json lw/")
exec("cp -v settings/librewolf.cfg lw/")
exec('rm -rf settings')
# provide a script that fetches and bootstraps Nightly
exec('cp -v ../scripts/mozfetch.sh lw')
2022-01-03 08:27:39 -05:00
exec('cp -v ../assets/mozconfig.new ../assets/mozconfig.new.without-wasi ../scripts/setup-wasi-linux.sh lw')
2021-12-27 18:55:58 -05:00
leave_srcdir()
2021-11-19 12:41:54 -05:00
#
2021-12-27 18:55:58 -05:00
# Main functionality in this script.. which is to call librewolf_patches()
2021-11-19 12:41:54 -05:00
#
if len(args) != 1:
sys.stderr.write('error: please specify version of librewolf source')
sys.exit(1)
version = args[0]
if not os.path.exists('librewolf-{}'.format(version) + '/configure.py'):
sys.stderr.write('error: folder doesn\'t look like a Firefox folder.')
sys.exit(1)
librewolf_patches()
sys.exit(0) # ensure 0 exit code