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
|
2024-09-17 18:44:57 -05:00
|
|
|
from pathlib import Path
|
|
|
|
from tempfile import TemporaryDirectory
|
2021-11-19 12:41:54 -05:00
|
|
|
|
|
|
|
|
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:
|
2022-02-05 10:13:32 -05:00
|
|
|
dir = "librewolf-{}-{}".format(version, release)
|
2021-11-19 12:41:54 -05:00
|
|
|
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..
|
2022-04-02 04:50:47 -05:00
|
|
|
exec('cp -v ../assets/mozconfig.new mozconfig')
|
2021-11-19 12:41:54 -05:00
|
|
|
|
|
|
|
# copy branding files..
|
2022-03-30 02:27:58 -05:00
|
|
|
exec("cp -r ../themes/browser .")
|
2021-12-21 12:01:19 -05:00
|
|
|
|
|
|
|
# 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'
|
2022-01-23 13:50:03 -05:00
|
|
|
with open('../assets/patches.txt'.format(version), "r") as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
patch('../'+line)
|
2021-12-27 18:55:58 -05:00
|
|
|
|
2022-01-19 07:42:43 -05:00
|
|
|
# apply xmas.patch seperately because not all builders use this repo the same way, and
|
|
|
|
# we don't want to disturbe those workflows.
|
2022-01-19 07:19:28 -05:00
|
|
|
patch('../patches/xmas.patch')
|
2021-12-27 18:55:58 -05:00
|
|
|
|
2023-08-17 15:03:56 -05:00
|
|
|
|
2023-10-16 04:18:40 -05:00
|
|
|
# vs_pack.py issue... should be temporary
|
|
|
|
exec('cp -v ../patches/pack_vs.py build/vs/')
|
|
|
|
|
|
|
|
|
2021-12-27 18:55:58 -05:00
|
|
|
#
|
2023-08-17 15:03:56 -05:00
|
|
|
# Apply most recent `settings` repository files.
|
2021-12-27 18:55:58 -05:00
|
|
|
#
|
|
|
|
|
2023-08-17 15:03:56 -05:00
|
|
|
exec('mkdir -p lw')
|
|
|
|
enter_srcdir('lw')
|
2023-11-14 13:53:25 -05:00
|
|
|
exec('cp -v ../../settings/librewolf.cfg .')
|
|
|
|
exec('cp -v ../../settings/distribution/policies.json .')
|
|
|
|
exec('cp -v ../../settings/defaults/pref/local-settings.js .')
|
2023-08-17 15:03:56 -05:00
|
|
|
leave_srcdir();
|
|
|
|
|
2023-10-29 11:03:41 -05:00
|
|
|
|
|
|
|
|
2023-10-29 10:30:45 -05:00
|
|
|
#
|
|
|
|
# pref-pane patches
|
|
|
|
#
|
2023-10-29 11:03:41 -05:00
|
|
|
|
|
|
|
# 1) patch it in
|
2023-10-29 10:30:45 -05:00
|
|
|
patch('../patches/pref-pane/pref-pane-small.patch')
|
2023-10-29 11:03:41 -05:00
|
|
|
# 2) new files
|
|
|
|
exec('cp ../patches/pref-pane/category-librewolf.svg browser/themes/shared/preferences/category-librewolf.svg')
|
|
|
|
exec('cp ../patches/pref-pane/librewolf.css browser/themes/shared/preferences/librewolf.css')
|
|
|
|
exec('cp ../patches/pref-pane/librewolf.inc.xhtml browser/components/preferences/librewolf.inc.xhtml')
|
|
|
|
exec('cp ../patches/pref-pane/librewolf.js browser/components/preferences/librewolf.js')
|
|
|
|
|
2022-01-19 07:22:07 -05:00
|
|
|
# provide a script that fetches and bootstraps Nightly and some mozconfigs
|
2022-01-24 06:57:44 -05:00
|
|
|
exec('cp -v ../scripts/mozfetch.sh lw/')
|
2022-07-23 07:14:11 -05:00
|
|
|
exec('cp -v ../assets/mozconfig.new ../assets/mozconfig.new.without-bootstrap ../scripts/setup-wasi-linux.sh lw/')
|
2022-01-23 13:50:03 -05:00
|
|
|
|
|
|
|
# override the firefox version
|
|
|
|
for file in ["browser/config/version.txt", "browser/config/version_display.txt"]:
|
|
|
|
with open(file, "w") as f:
|
|
|
|
f.write("{}-{}".format(version,release))
|
2022-05-03 15:53:46 -05:00
|
|
|
|
2024-09-17 18:44:57 -05:00
|
|
|
print("-> Downloading locales from https://github.com/mozilla-l10n/firefox-l10n")
|
|
|
|
with TemporaryDirectory() as tmpdir:
|
2024-09-29 07:45:36 -05:00
|
|
|
exec(f"wget -qO {tmpdir}/l10n.zip 'https://codeload.github.com/mozilla-l10n/firefox-l10n/zip/refs/heads/main'")
|
2024-09-17 18:44:57 -05:00
|
|
|
exec(f"unzip -qo {tmpdir}/l10n.zip -d {tmpdir}/l10n")
|
2024-10-06 08:58:48 -05:00
|
|
|
exec(f"mv {tmpdir}/l10n/firefox-l10n-main lw/l10n")
|
2024-09-17 18:44:57 -05:00
|
|
|
|
2024-10-06 07:37:08 -05:00
|
|
|
print("-> Patching appstrings.properties")
|
|
|
|
# Why is "Firefox" hardcoded there???
|
2024-10-06 08:58:48 -05:00
|
|
|
exec("find . -path '*/appstrings.properties' -exec sed -i s/Firefox/LibreWolf/ {} \;")
|
2024-10-06 07:37:08 -05:00
|
|
|
|
2024-09-17 18:44:57 -05:00
|
|
|
print("-> Applying LibreWolf locales")
|
|
|
|
l10n_dir = Path("..", "l10n")
|
|
|
|
for source_path in l10n_dir.rglob("*"):
|
|
|
|
if source_path.is_dir() or source_path.name.endswith(".md"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
rel_path = source_path.relative_to(l10n_dir)
|
2024-10-06 08:58:48 -05:00
|
|
|
if rel_path.parts[0] == "en-US":
|
|
|
|
target_path = Path(
|
|
|
|
rel_path.parts[1],
|
|
|
|
"locales", "en-US",
|
|
|
|
*rel_path.parts[1:]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
target_path = Path(
|
|
|
|
"lw", "l10n",
|
2024-10-06 10:49:12 -05:00
|
|
|
*rel_path.parts[0:2],
|
|
|
|
*rel_path.parts[1:]
|
2024-10-06 08:58:48 -05:00
|
|
|
)
|
2024-09-17 18:44:57 -05:00
|
|
|
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
write_mode = "w"
|
|
|
|
if ".inc" in target_path.name:
|
|
|
|
target_path = target_path.with_name(target_path.name.replace(".inc", ""))
|
|
|
|
write_mode = "a"
|
|
|
|
|
2024-09-19 10:42:01 -05:00
|
|
|
print(f"{source_path} {'>' if write_mode == 'w' else '>>'} {target_path}")
|
2024-09-17 18:44:57 -05:00
|
|
|
|
|
|
|
with open(target_path, write_mode) as target_file:
|
|
|
|
with open(source_path, "r") as source_file:
|
|
|
|
target_file.write(("\n\n" if write_mode == "a" else "") + source_file.read())
|
|
|
|
|
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
|
|
|
#
|
|
|
|
|
2022-01-23 13:50:03 -05:00
|
|
|
if len(args) != 2:
|
|
|
|
sys.stderr.write('error: please specify version and release of librewolf source')
|
2021-11-19 12:41:54 -05:00
|
|
|
sys.exit(1)
|
|
|
|
version = args[0]
|
2022-01-23 13:50:03 -05:00
|
|
|
release = args[1]
|
2024-09-10 09:52:58 -05:00
|
|
|
srcdir = "librewolf-{}-{}".format(version, release)
|
|
|
|
if not os.path.exists(srcdir + '/configure.py'):
|
2021-11-19 12:41:54 -05:00
|
|
|
sys.stderr.write('error: folder doesn\'t look like a Firefox folder.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
librewolf_patches()
|
|
|
|
|
|
|
|
sys.exit(0) # ensure 0 exit code
|