This commit is contained in:
Bert van der Weerd 2021-11-19 11:30:48 +01:00
parent f444640f1b
commit af0d3b0ca9
No known key found for this signature in database
GPG key ID: 4CFABB96ADE0F5B1

450
build.py
View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
pkgver = '94.0.1'
pkgver = '94.0.2'
nightly_ver = '96.0a1'
#
@ -444,7 +444,453 @@ def execute_lw_artifacts():
exec("cp -vr librewolf/* librewolf-{}/LibreWolf".format(tmp))
exec("rm -f librewolf-portable.exe")
exec("wget -q https://gitlab.com/librewolf-community/browser/windows/upload/8347381f01806245121adcca11b7f35c/librewolf-portable.exe")
# #!/usr/bin/env python3
pkgver = '94.0.2'
nightly_ver = '96.0a1'
#
# build.py - try move functionality away from that too big/horrible build script.
#
import optparse
import sys
import os
import glob
import time
start_time = time.time()
parser = optparse.OptionParser()
parser.add_option('-x', '--cross', dest='cross_compile', default=False, action="store_true")
parser.add_option('-n', '--no-execute', dest='no_execute', default=False, action="store_true")
parser.add_option('-l', '--no-librewolf', dest='no_librewolf', default=False, action="store_true")
parser.add_option('-s', '--src', dest='src', default='release')
parser.add_option('-t', '--distro', dest='distro', default='autodetect')
parser.add_option('-T', '--token', dest='token', default='')
parser.add_option('-3', '--i386', dest='i386', default=False, action="store_true")
parser.add_option('-P', '--no-settings-pane', dest='settings_pane', default=True, action="store_false")
parser.add_option('-v', '--version', dest='version', action="store", type="string")
options, remainder = parser.parse_args()
# try autodetecting options.distro
if options.distro == 'autodetect':
options.distro = 'win'
if os.path.isdir('/Applications'):
options.distro = 'osx'
elif os.path.isdir('/etc'):
options.distro = 'rpm'
if os.path.isdir('/etc/apt'):
options.distro = 'deb'
if options.version != None:
if options.src != 'release':
print('error: cant use --version and --src at the same time')
sys.exit(1)
pkgver=options.version
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(f"\n\aElapsed time: {elapsed}")
sys.exit(statuscode)
def enter_srcdir():
dir = "firefox-{}".format(pkgver)
if options.src == 'nightly':
dir = 'mozilla-unified'
elif options.src == 'tor-browser':
dir = 'tor-browser'
elif options.src == 'gecko-dev':
dir = 'gecko-dev'
print("cd {}".format(dir))
if not options.no_execute:
try:
os.chdir(dir)
except:
print("fatal error: can't change to '{}' folder.".format(dir))
script_exit(1)
def leave_srcdir():
print("cd ..")
if not options.no_execute:
os.chdir("..")
def exec(cmd):
if cmd != '':
print(cmd)
if not options.no_execute:
retval = os.system(cmd)
if retval != 0:
print("fatal error: command '{}' failed".format(cmd))
script_exit(1)
def patch(patchfile):
cmd = "patch -p1 -i {}".format(patchfile)
print("\n*** -> {}".format(cmd))
if not options.no_execute:
retval = os.system(cmd)
if retval != 0:
print("fatal error: patch '{}' failed".format(patchfile))
script_exit(1)
#
# Utilities:
#
def execute_update_submodules():
exec("git submodule update --recursive")
exec("git submodule foreach git pull origin master")
exec("git submodule foreach git merge origin master")
def execute_git_init():
if options.src != 'release':
print("fatal error: git_init only works with the release source (--src release)")
script_exit(1)
enter_srcdir()
exec("rm -rf .git")
exec("git init")
exec("git config core.safecrlf false")
exec("git config commit.gpgsign false")
exec("git add -f * .[a-z]*")
exec("git commit -am initial")
leave_srcdir()
def execute_deps_deb():
deps1 = "python python-dev python3 python3-dev python3-distutils clang pkg-config libpulse-dev gcc"
deps2 = "curl wget nodejs libpango1.0-dev nasm yasm zip m4 libgtk-3-dev libgtk2.0-dev libdbus-glib-1-dev"
deps3 = "libxt-dev python3-pip mercurial automake autoconf libtool m4"
exec("apt install -y {} {} {}".format(deps1,deps2,deps3))
def execute_deps_rpm():
deps1 = "python3 python3-distutils-extra clang pkg-config gcc curl wget nodejs nasm yasm zip m4"
deps2 = "python3-zstandard python-zstandard python-devel python3-devel gtk3-devel llvm gtk2-devel dbus-glib-devel libXt-devel pulseaudio-libs-devel"
exec("dnf -y install {} {}".format(deps1,deps2))
def execute_deps_pkg():
deps = "wget gmake m4 python3 py37-sqlite3 pkgconf llvm node nasm zip unzip yasm"
exec("pkg install {}".format(deps))
def execute_rustup():
# rust needs special love: https://www.atechtown.com/install-rust-language-on-debian-10/
exec("curl https://sh.rustup.rs -sSf | sh")
exec("cargo install cbindgen")
def execute_mach_env():
enter_srcdir()
exec("bash ./mach create-mach-environment")
leave_srcdir()
def execute_reset():
if options.src == 'release':
path = "firefox-{}/.git/index".format(pkgver)
if not os.path.isfile(path):
print("fatal error: cannot reset '--src release' sources as it's not under version control.")
script_exit(1)
enter_srcdir()
exec("git reset --hard")
leave_srcdir()
elif options.src == 'nightly':
enter_srcdir()
exec("hg up -C")
exec("hg purge")
exec("hg pull -u")
leave_srcdir()
elif options.src == 'tor-browser':
enter_srcdir()
exec("git reset --hard")
leave_srcidr()
elif options.src == 'gecko-dev':
enter_srcdir()
exec("git reset --hard")
leave_srcdir()
#
# Targets:
#
def execute_fetch():
if options.src == 'release':
exec("rm -f firefox-{}.source.tar.xz".format(pkgver))
exec("wget -q https://archive.mozilla.org/pub/firefox/releases/{}/source/firefox-{}.source.tar.xz".format(pkgver, pkgver))
elif options.src == 'nightly':
if not os.path.isdir('mozilla-unified'):
exec("rm -f bootstrap.py")
exec("rm -rf mozilla-unified")
exec("wget -q https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py")
exec("python3 bootstrap.py --no-interactive --application-choice=browser")
elif options.src == 'tor-browser':
if not os.path.isdir('tor-browser'):
exec("rm -rf tor-browser")
exec("git clone --no-checkout --recursive https://git.torproject.org/tor-browser.git")
patch("../patches/tb-mozconfig-win10.patch")
enter_srcdir()
exec("git checkout tor-browser-89.0-10.5-1-build1")
exec("git submodule update --recursive")
leave_srcdir()
elif options.src == 'gecko-dev':
if not os.path.isdir('gecko-dev'):
exec("rm -rf gecko-dev")
exec("git clone --depth=1 https://github.com/mozilla/gecko-dev.git")
def execute_extract():
if options.src == 'release':
exec("rm -rf firefox-{}".format(pkgver))
exec("tar xf firefox-{}.source.tar.xz".format(pkgver))
def execute_build():
enter_srcdir()
exec("bash ./mach build")
leave_srcdir()
def execute_package():
enter_srcdir()
exec("bash ./mach package")
leave_srcdir()
#
# LibreWolf specific:
#
def create_mozconfig(contents):
if not options.no_execute:
f = open('mozconfig', 'w')
f.write(contents)
if not options.distro == 'win':
f.write("\nac_add_options --with-app-name=librewolf")
if options.distro == 'osx' and options.cross_compile:
f.write("\nac_add_options --target=aarch64")
if options.i386:
f.write("\nac_add_options --target=i386")
f.write("\n")
f.close()
def execute_lw_do_patches():
if options.no_librewolf:
return
if not options.src in ['release','nightly','gecko-dev']:
return
enter_srcdir()
# create the right mozconfig file..
create_mozconfig(mozconfig_release)
# macos : if have compatibilty osx api headers, add that to mozconfig_release
dir = os.environ['HOME'] + '/.mozbuild/macos-sdk/MacOSX11.1.sdk'
if os.path.isdir(dir):
with open('mozconfig','a') as f:
f.write("\nac_add_options --with-macos-sdk=$HOME/.mozbuild/macos-sdk/MacOSX11.1.sdk")
f.close()
# copy branding files..
exec('echo +++ && pwd && ls ../common')
exec("cp -vr ../common/source_files/browser .")
exec("cp -v ../files/configure.sh browser/branding/librewolf")
patches = []
if options.src == 'release':
# production patches
patches = [
"../common/patches/about-dialog.patch",
"../common/patches/allow-ubo-private-mode.patch",
"../common/patches/allow_dark_preference_with_rfp.patch",
"../common/patches/context-menu.patch",
"../common/patches/megabar.patch",
"../common/patches/mozilla-vpn-ad.patch",
"../common/patches/mozilla_dirs.patch",
"../common/patches/remove_addons.patch",
"../common/patches/search-config.patch",
"../common/patches/sed-patches/allow-searchengines-non-esr.patch",
"../common/patches/sed-patches/disable-pocket.patch",
"../common/patches/sed-patches/remove-internal-plugin-certs.patch",
"../common/patches/sed-patches/stop-undesired-requests.patch",
"../common/patches/ui-patches/add-language-warning.patch",
"../common/patches/ui-patches/pref-naming.patch",
"../common/patches/ui-patches/remove-branding-urlbar.patch",
"../common/patches/ui-patches/remove-cfrprefs.patch",
"../common/patches/ui-patches/remove-organization-policy-banner.patch",
"../common/patches/ui-patches/remove-snippets-from-home.patch",
"../common/patches/ui-patches/sanitizing-description.patch",
"../common/patches/urlbarprovider-interventions.patch",
]
elif options.src == 'nightly' or options.src == 'gecko-dev':
# patches for future releases are caught with nightly
patches = [
"../common/patches/about-dialog.patch",
"../common/patches/allow-ubo-private-mode.patch",
"../common/patches/allow_dark_preference_with_rfp.patch",
"../common/patches/context-menu.patch",
"../common/patches/megabar.patch",
"../common/patches/mozilla-vpn-ad.patch",
"../common/patches/mozilla_dirs.patch",
"../common/patches/remove_addons.patch",
"../common/patches/search-config.patch",
"../common/patches/sed-patches/allow-searchengines-non-esr.patch",
"../common/patches/sed-patches/disable-pocket.patch",
"../common/patches/sed-patches/remove-internal-plugin-certs.patch",
"../common/patches/sed-patches/stop-undesired-requests.patch",
"../common/patches/ui-patches/add-language-warning.patch",
"../common/patches/ui-patches/pref-naming.patch",
"../common/patches/ui-patches/remove-branding-urlbar.patch",
"../common/patches/ui-patches/remove-cfrprefs.patch",
"../common/patches/ui-patches/remove-organization-policy-banner.patch",
"../common/patches/ui-patches/remove-snippets-from-home.patch",
"../common/patches/ui-patches/sanitizing-description.patch",
"../common/patches/urlbarprovider-interventions.patch",
]
for p in patches:
patch(p)
# local windows patches
for p in ["../patches/browser-confvars.patch", "../patches/package-manifest.patch"]:
patch(p)
# insert the settings pane source (experimental)
if options.settings_pane:
exec('rm -rf librewolf-pref-pane')
exec('git clone https://gitlab.com/ohfp/librewolf-pref-pane.git')
os.chdir('librewolf-pref-pane')
exec('git diff 1fee314adc81000294fc0cf3196a758e4b64dace > ../../patches/librewolf-pref-pane.patch')
os.chdir('..')
patch('../patches/librewolf-pref-pane.patch')
leave_srcdir()
def get_objdir():
pattern = "obj-*"
retval = glob.glob(pattern)
if options.no_execute:
return "obj-XXX"
if len(retval) != 1:
print("fatal error: in execute_lw_post_build(): cannot glob build output folder '{}'".format(pattern))
script_exit(1)
return retval[0]
def execute_lw_post_build():
if options.no_librewolf:
return
enter_srcdir()
dirname = get_objdir()
distfolder = "dist/bin"
if options.distro == 'osx':
distfolder = 'dist/LibreWolf.app/Contents/Resources'
if not options.no_execute:
os.makedirs("{}/{}/defaults/pref".format(dirname,distfolder), exist_ok=True)
os.makedirs("{}/{}/distribution".format(dirname,distfolder), exist_ok=True)
exec("cp -v ../settings/defaults/pref/local-settings.js {}/{}/defaults/pref/".format(dirname,distfolder))
exec("cp -v ../settings/distribution/policies.json {}/{}/distribution/".format(dirname,distfolder))
exec("cp -v ../settings/librewolf.cfg {}/{}/".format(dirname,distfolder))
leave_srcdir()
def execute_lw_artifacts():
if options.no_librewolf:
return
enter_srcdir()
if options.distro == 'win':
exe = ".exe"
ospkg = "win64"
dirname = "{}/dist/firefox".format(get_objdir())
elif options.distro == 'deb':
exe = ""
ospkg = "deb"
dirname = "{}/dist/librewolf".format(get_objdir())
elif options.distro == 'rpm':
exe = ""
ospkg = "rpm"
dirname = "{}/dist/librewolf".format(get_objdir())
elif options.distro == 'osx':
#exe = ""
#ospkg = "osx"
#dirname = "{}/dist/firefox".format(get_objdir())
exec("cp {}/dist/librewolf*.dmg ..".format(get_objdir()))
leave_srcdir()
return
exec("rm -rf ../firefox ../librewolf")
exec("cp -rv {} ..".format(dirname))
leave_srcdir()
librewolfdir = "librewolf"
if options.distro == 'osx':
librewolfdir = 'librewolf/Librewolf.app'
if options.distro == 'win':
exec("mv firefox librewolf")
if options.distro != 'osx':
if options.distro == 'win':
exec("mv -v {}/firefox{} {}/librewolf{}".format(librewolfdir,exe,librewolfdir,exe));
exec("rm -rf {}/default-browser-agent* {}/maintainanceservice* {}/pingsender* {}/firefox.*.xml {}/precomplete {}/removed-files {}/uninstall"
.format(librewolfdir,librewolfdir,librewolfdir,librewolfdir,librewolfdir,librewolfdir,librewolfdir,librewolfdir))
exec("cp -v common/source_files/browser/branding/librewolf/firefox.ico {}/librewolf.ico".format(librewolfdir))
if options.distro != 'win':
exec("cp -v files/register-librewolf files/start-librewolf files/start-librewolf.desktop.in librewolf")
# create zip filename
if options.src == 'release':
zipname = "librewolf-{}.en-US.{}.zip".format(pkgver,ospkg)
elif options.src == 'nightly':
zipname = "librewolf-{}.en-US.{}-nightly.zip".format(nightly_ver,ospkg)
elif options.src == 'gecko-dev':
zipname = "librewolf-{}.en-US.{}-gecko-dev.zip".format(nightly_ver,ospkg)
# 'windows portable' zip stuff..
if options.distro == 'win':
# we need tmp to tell us what portable folder to make
if options.src == 'release':
tmp = pkgver
else:
tmp = nightly_ver
exec("rm -rf librewolf-{}".format(tmp))
#exec("mkdir -p librewolf-{}/Profiles/Default librewolf-{}/LibreWolf".format(pkgver,pkgver))
os.makedirs("librewolf-{}/Profiles/Default".format(tmp), exist_ok=True)
os.makedirs("librewolf-{}/LibreWolf".format(tmp), exist_ok=True)
exec("cp -vr librewolf/* librewolf-{}/LibreWolf".format(tmp))
exec("rm -f librewolf-portable.exe")
exec("wget -q https://gitlab.com/librewolf-community/browser/windows/uploads/8347381f01806245121adcca11b7f35c/librewolf-portable.exe")
exec("mv librewolf-portable.exe librewolf-{}".format(tmp))
exec("rm -f {}".format(zipname))