aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-16 18:12:21 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-16 18:12:21 +0100
commit7965f1b455144220c137bcb25c4967283a6b7ff3 (patch)
treeafca0ab5c03a935b05b9da2b43c44b81b0317272
parentcfe121e686755502bb0b40059f6c4a699338b341 (diff)
downloadbrowser-extension-7965f1b455144220c137bcb25c4967283a6b7ff3.tar.gz
browser-extension-7965f1b455144220c137bcb25c4967283a6b7ff3.zip
improve the build system
-rw-r--r--Makefile.in19
-rwxr-xr-xconfigure281
-rw-r--r--manifest.json11
-rw-r--r--test/misc_constants.py4
-rw-r--r--version1
-rw-r--r--version_chromium1
-rwxr-xr-xwrite_makefile.sh20
7 files changed, 234 insertions, 103 deletions
diff --git a/Makefile.in b/Makefile.in
index cac0c01..28ccb85 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -16,14 +16,13 @@ SHELL = /bin/sh
VPATH = <<VPATH>>
version = <<VERSION>>
-PYTEST = <<PYTEST>>
extension_files = background/ common/ content/ html/ licenses/ \
copyright default_settings.json manifest.json
metafiles = build.sh configure Makefile.in process_html_file.sh README.txt \
re-generate_icons.sh shell_utils.sh upload_amo.sh write_makefile.sh
-# Configuration goes here
+# Configuration gets included here by write_makefile.sh
# The default target: placed up here
default: $(default_target)
@@ -45,7 +44,7 @@ all: mozilla chromium
mozilla: mozilla-build.zip
chromium: chromium-build.zip
-unpacked: $(default_target)-unpacked
+unpacked: $(default_target)-unpacked Makefile
all-unpacked: mozilla-unpacked chromium-unpacked
%-unpacked: $(extension_files) icons/haketilo16.png
$(srcdir)/build.sh $* $(srcdir) $(UPDATE_URL)
@@ -57,10 +56,13 @@ install install-strip: $(default_target)-unpacked
uninstall:
rm -r "$(DESTDIR)/{6fe13369-88e9-440f-b837-5012fb3bedec}"
-%-build.zip: %-unpacked
+%-build.zip: %-unpacked Makefile
cd $< && zip -q -r ../$@ *
-test/certs/:
+test/:
+ mkdir $@
+
+test/certs/: | test/
mkdir $@
test/certs/%.key: | test/certs/
@@ -71,7 +73,7 @@ test/certs/rootCA.pem: test/certs/rootCA.key
-subj "/CN=Haketilo Test"
test: test/certs/rootCA.pem test/certs/site.key $(default_target)-build.zip
- MOZ_HEADLESS=whatever $(PYTEST)
+ MOZ_HEADLESS=whatever $(PYTHON) -m pytest
test-environment: test/certs/rootCA.pem test/certs/site.key
python3 -m test
@@ -82,9 +84,8 @@ test-environment-with-haketilo: test/certs/rootCA.pem test/certs/site.key \
# helper targets
clean mostlyclean:
- rm -rf mozilla-unpacked chromium-unpacked haketilo-$(version)
- rm -f mozilla-build.zip chromium-build.zip haketilo-$(version).tar.gz \
- haketilo-$(version).tar exports_init.js
+ rm -rf mozilla-unpacked chromium-unpacked haketilo-[1-9]*
+ rm -f mozilla-build.zip chromium-build.zip exports_init.js
rm -rf test/certs
rm -rf $$(find . -name geckodriver.log)
rm -rf $$(find . -type d -name __pycache__)
diff --git a/configure b/configure
index 80516fa..3e497b6 100755
--- a/configure
+++ b/configure
@@ -2,7 +2,8 @@
# This file is part of Haketilo
#
-# Copyright (C) 2021, jahoti
+# Copyright (C) 2021 Jahoti
+# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
@@ -15,133 +16,247 @@
set -e
+TARGET_NAME=''
BROWSERPATH=''
-SRCDIR=''
TARGET=''
+SRCDIR=''
BROWSER_BINARY=''
CLEAN_PROFILE=''
DRIVER=''
-PYTEST=''
+PYTHON=''
+
+SOFT_FAILURES=n
+
+ARG0="$0"
# Parse command line options
while [ "x$1" != x ]; do
+ OPT="$1"
+ case "$OPT" in
+ chromium | chrome | google-chrome | mozilla | firefox | \
+ librewolf | icecat | iceweasel | abrowser | tor-browser)
+ TARGET_NAME=$1
+ shift
+ continue
+ ;;
+ esac
+
+ if [ "x$(printf %s "$OPT" | cut -c -2)" = "x--" ]; then
+ # Process a '--' option
+ OPT="${OPT#--}"
+ OPT_NAME="${OPT%%=*}"
+
+ if [ "x$OPT_BASE" != "x$OPT" ]; then
+ OPT_VAL="${OPT#*=}"
+ else
+ shift
+ OPT_VAL="$1"
+ fi
+
+ case "$OPT_NAME" in
+ srcdir)
+ SRCDIR="$OPT_VAL";;
+ browser-binary)
+ BROWSER_BINARY="$OPT_VAL";;
+ clean-profile)
+ CLEAN_PROFILE="$OPT_VAL";;
+ driver)
+ DRIVER="$OPT_VAL";;
+ python)
+ PYTHON="$OPT_VAL";;
+ srcdir)
+ SRCDIR="$OPT_VAL";;
+ destdir|dstdir)
+ DESTDIR="$OPT_VAL";;
+ update-url)
+ UPDATE_URL="$OPT_VAL";;
+ host)
+ TARGET_NAME="$OPT_VAL";;
+ *)
+ printf "Unknown option '--%s'\n" "$OPT_NAME" >&2
+ exit 1
+ ;;
+ esac
+
+ shift
+ continue
+ fi
+
+ # Process a non-'--' option
+ OPT_NAME="${OPT%%=*}"
+ OPT_VAL="${OPT#*=}"
+
case "$1" in
- --srcdir=*) SRCDIR="$(printf %s "$1" | cut -c 10-)";;
- --srcdir) SRCDIR="$2"; shift;;
- --browser-binary=*) BROWSER_BINARY="$(printf %s "$1" | cut -c 18-)";;
- --browser-binary) BROWSER_BINARY="$2"; shift;;
- --clean-profile=*) CLEAN_PROFILE="$(printf %s "$1" | cut -c 17-)";;
- --clean-profile) CLEAN_PROFILE="$2"; shift;;
- --driver=*) DRIVER="$(printf %s "$1" | cut -c 10-)";;
- --driver) DRIVER="$2"; shift;;
- --pytest=*) PYTEST="$(printf %s "$1" | cut -c 10-)";;
- --pytest) PYTEST="$2"; shift;;
- --srcdir) SRCDIR="$2"; shift;;
- "DESTDIR"=*) DESTDIR="$(printf %s "$1" | cut -c 9-)";;
- "UPDATE_URL"=*) UPDATE_URL="$(printf %s "$1" | cut -c 12-)";;
- --host=*) TARGET="$(printf %s "$1" | cut -c 8-)";;
- --host) TARGET="$2"; shift;;
-
- # browsers
- chromium | chrome | google-chrome | mozilla |\
- firefox | librewolf | icecat | iceweasel | abrowser |\
- iceweasel-uxp | tor-browser) TARGET=$1;;
- *) echo Ignoring option "'$1'";;
+ BROWSER_BINARY)
+ BROWSER_BINARY="$OPT_VAL";;
+ CLEAN_PROFILE)
+ CLEAN_PROFILE="$OPT_VAL";;
+ DRIVER)
+ DRIVER="$OPT_VAL";;
+ PYTHON)
+ PYTHON="$OPT_VAL";;
+ SRCDIR)
+ SRCDIR="$OPT_VAL";;
+ DESTDIR|DSTDIR)
+ DESTDIR="$OPT_VAL";;
+ UPDATE_URL)
+ UPDATE_URL="$OPT_VAL";;
+ HOST)
+ TARGET_NAME="$OPT_VAL";;
+ *)
+ printf "Unknown variable '%s'\n" "$OPT_NAME" >&2
+ exit 1
+ ;;
esac
+
shift
done
+# Check TARGET_NAME
+if [ "x$TARGET_NAME" = x ]; then
+ printf 'Target not specified. Please use `--host=<browser-name>`.\n' >&2
+ exit 1
+fi
+
+# Check and standardize target
+case "$TARGET_NAME" in
+ mozilla | firefox | abrowser | icecat | librewolf | iceweasel | tor-browser)
+ TARGET=mozilla
+ ;;
+ ungoogled-chromium | chromium | chrome | google-chrome | brave | iridium | \
+ bromite)
+ TARGET=chromium
+ printf "Tests won't yet run on a Chromium-based browser.\n"
+ SOFT_FAILURES=y
+ ;;
+ *)
+ printf 'Invalid target: %s\n' "$TARGET_NAME" >&2
+ exit 1
+ ;;
+esac
+
# Autodetect srcdir
if [ "x$SRCDIR" = x ]; then
- SRCDIR=..
- if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
- SRCDIR=.
+ if which "$ARG0" >/dev/null 2>&1; then
+ SRCDIR="$(which "$ARG0")"
+ SRCDIR="$(dirname "$SRCDIR")"
+ SRCDIR="$(realpath "$SRCDIR" || true)"
fi
+
+ if [ "x$SRCDIR" = x ]; then
+ SRCDIR=..
+ if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
+ SRCDIR=.
+ fi
+ fi
+
+ printf 'Guessing SRCDIR: %s\n' "$SRCDIR"
fi
# Check srcdir
-if [ ! -f "$SRCDIR"/manifest.json ]; then
- echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
- exit 1
-elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
- echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
+for FILE in manifest.json write_makefile.sh version; do
+ if [ -f "$SRCDIR"/"$FILE" ]; then
+ continue
+ fi
+
+ printf "Invalid source directory '%s': missing %s\n" "$SRCDIR" $FILE >&2
exit 1
-fi
+done
-# Autodetect target
-if [ "x$TARGET" = x ]; then
- echo Detecting target automatically.
- if [ -h /etc/alternatives/x-www-browser ]; then
- BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
- TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
- tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
- else
- echo Warning: could not find target automatically. >&2
- echo Some make rules may fail. >&2
- fi
-else
- BROWSERPATH="$(realpath "$(which $TARGET)")"
-fi
+BROWSERPATH="$(realpath "$(which $TARGET_NAME)" 2>/dev/null || true)"
-# Autodetect browser binary (needed for Selenium)
+# Guess browser binary (needed for Selenium)
if [ "x$BROWSER_BINARY" = x ]; then
- if [ "x$TARGET" = xabrowser ]; then
+ if [ "x$TARGET_NAME" = xabrowser ]; then
# Trisquel's path to Abrowser
BROWSER_BINARY=/usr/lib/abrowser/abrowser
- elif [ "x$TARGET" = xlibrewolf ]; then
+ elif [ "x$TARGET_NAME" = xlibrewolf ]; then
# Debian's path to Librewolf
BROWSER_BINARY=/usr/share/librewolf/librewolf
- elif [ "x$TARGET" = xiceweasel ]; then
+ elif [ "x$TARGET_NAME" = xiceweasel ]; then
# Parabola's path to Iceweasel
BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
- elif [ "x$TARGET" = xicecat ]; then
+ elif [ "x$TARGET_NAME" = xicecat ]; then
# Parabola's path to IceCat
BROWSER_BINARY=/usr/lib/icecat/icecat
fi
-fi
-# Check and standardize target
-case "$TARGET" in
- mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
- librewolf | iceweasel | gnu | tor-browser) TARGET=mozilla;;
- chromium | chrome | google-chrome | google) TARGET=chromium;;
- "") ;;
- *) echo Invalid target "'$TARGET'" >&2; exit 2;;
-esac
+ if [ "x$BROWSER_BINARY" != x ]; then
+ printf 'Guessing BROWSER_BINARY: %s\n' "$BROWSER_BINARY"
+ elif [ "$TARGET" != "chromium" ]; then
+ printf 'Cannot guess BROWSER_BINARY for %s.\n' "$TARGET_NAME"
+ SOFT_FAILURES=y
+ fi
+fi
# Autodetect Selenium driver
if [ "x$DRIVER" = x ]; then
- if [ "x$TARGET" = mozilla ]; then
- DRIVER=geckodriver
+ if [ "x$TARGET" = xmozilla ]; then
+ DRIVER="$(which geckodriver 2>/dev/null || true)"
+ if [ -n "$DRIVER" ]; then
+ printf 'Guessing DRIVER: %s\n' "$DRIVER"
+ else
+ printf 'Cannot guess DRIVER for %s.\n' "$TARGET_NAME"
+ fi
fi
fi
# Autodetect clean profile directory for use in selenium tests
if [ "x$CLEAN_PROFILE" = x ]; then
- if [ "x$TARGET" = mozilla ]; then
+ if [ "x$TARGET" = xmozilla ]; then
CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
fi
fi
-# Autodetect pytest
-for PYTEST_GUESS in pytest pytest-3 pytest3; do
- if [ "x$PYTEST" = x ]; then
- PYTEST="$(which $PYTEST_GUESS || true)"
+# Autodetect python
+if [ "x$TARGET" = xmozilla -a "x$PYTHON" = x ]; then
+ PYTHON2_SKIPPED=n
+ for PYTHON_GUESS in python3 python-3 python; do
+ if [ "x$PYTHON" = x ]; then
+ PYTHON="$(which $PYTHON_GUESS 2>/dev/null || true)"
+ fi
+
+ if [ -n "$PYTHON" ]; then
+ if [ "$PYTHON_GUESS" = python ]; then
+ if python --version 2>&1 | grep '^Python 2' >/dev/null; then
+ PYTHON=''
+ PYTHON2_SKIPPED=y
+ fi
+ fi
+ fi
+
+ if [ -n "$PYTHON" ]; then
+ break
+ fi
+ done
+
+ if [ -n "$PYTHON" ]; then
+ printf 'Guessing PYTHON: %s\n' "$PYTHON"
+ else
+ printf 'Cannot guess PYTHON'
+ if [ "$PYTHON2_SKIPPED" = y ]; then
+ printf ' %s' \
+ '(skipped Python 2 executable in PATH; Python 3 is required)'
+ fi
+ printf '.\n'
+ SOFT_FAILURES=y
fi
-done
+fi
# Autodetect DESTDIR (no check needed)
if [ "x$DESTDIR" = x ]; then
- echo Guessing installation directory.
- if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
- DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
- if [ $TARGET = mozilla ]; then
- DESTDIR="$DESTDIR"/browser
- fi
- DESTDIR="$DESTDIR"/extensions
+ if [ "x$TARGET" = xmozilla ]; then
+ DESTDIR=/usr/share/mozilla/extensions/
+ elif test "x$TARGET_NAME" = xchromium -o \
+ "x$TARGET_NAME" = xungoogled-chromium; then
+ DESTDIR=/usr/share/chromium/extensions
+ fi
+
+ if [ -n "$DESTDIR" ]; then
+ printf 'Guessing DESTDIR: %s\n' "$DESTDIR"
else
- echo Warning: could not guess installation directory. >&2
- echo Some make rules may fail. >&2
+ printf 'Cannot guess DESTDIR.\n'
+ SOFT_FAILURES=y
fi
fi
@@ -153,11 +268,13 @@ printf '%s\n' "UPDATE_URL = $UPDATE_URL" >> record.conf
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
-printf '%s\n' "PYTEST = $PYTEST" >> record.conf
+printf '%s\n' "PYTHON = $PYTHON" >> record.conf
# Prepare and run write_makefile.sh (as config.status)
-if [ ! -e config.status ]; then
- cp "$SRCDIR"/write_makefile.sh config.status
-fi
+cp "$SRCDIR"/write_makefile.sh config.status
./config.status
+
+if [ "$SOFT_FAILURES" = "y" ]; then
+ printf 'Some make rules may fail.\n'
+fi
diff --git a/manifest.json b/manifest.json
index ac7901a..eda8c2e 100644
--- a/manifest.json
+++ b/manifest.json
@@ -28,13 +28,18 @@
#ENDIF
"name": "Haketilo",
"short_name": "Haketilo",
+ "version":
#IF CHROMIUM
// Chromium requires version to "be between 1-4 dot-separated integers each
- // between 0 and 65536".
- "version": "0.65536.1",
+ // between 0 and 65536". Firefox does not impose such rules, hence, when we
+ // make a beta release, we assign it the true version under Firefox
+ // (e.g. "1.0-beta1") and a fake version with 1-lower major and maximal
+ // allowed minor number under Chromium (e.g. 0.65536.1).
+#INCLUDE_VERBATIM version_chromium
#ELSE
- "version": "1.0-beta1",
+#INCLUDE_VERBATIM version
#ENDIF
+ ,
"author": "Wojtek Kosior & contributors",
"description": "Control your \"Web\" browsing.",
#IF MOZILLA
diff --git a/test/misc_constants.py b/test/misc_constants.py
index 51602b3..96bc9e0 100644
--- a/test/misc_constants.py
+++ b/test/misc_constants.py
@@ -37,13 +37,13 @@ awk_script_name = 'compute_scripts.awk'
unit_test_defines = ['-D', 'MOZILLA', '-D', 'MV2', '-D', 'TEST',
'-D', 'UNIT_TEST', '-D', 'DEBUG']
-conf_line_regex = re.compile(r'^([^=]+)=(.*)$')
+conf_line_regex = re.compile(r'^([^=]+) = (.*)$')
conf_settings = {}
with open(here.parent / 'record.conf', 'rt') as conf:
for line in conf.readlines():
match = conf_line_regex.match(line)
if match:
- conf_settings[match.group(1).strip()] = match.group(2).strip()
+ conf_settings[match.group(1).strip()] = match.group(2)
default_proxy_host = '127.0.0.1'
default_proxy_port = 1337
diff --git a/version b/version
new file mode 100644
index 0000000..2a326d8
--- /dev/null
+++ b/version
@@ -0,0 +1 @@
+"1.0-beta1"
diff --git a/version_chromium b/version_chromium
new file mode 100644
index 0000000..d7d86a1
--- /dev/null
+++ b/version_chromium
@@ -0,0 +1 @@
+"0.65536.1"
diff --git a/write_makefile.sh b/write_makefile.sh
index 4011fe8..c9b107b 100755
--- a/write_makefile.sh
+++ b/write_makefile.sh
@@ -13,18 +13,24 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# CC0 1.0 Universal License for more details.
+set -e
+
if [ ! -e record.conf ]; then
printf "Record of configuration 'record.conf' does not exist.\n" >&2
exit 1
-elif [ "$(head -n 1 record.conf | cut -c -9)x" != "srcdir = x" ]; then
+elif ! grep '^srcdir = ' record.conf >/dev/null 2>&1; then
printf "Record of configuration 'record.conf' is invalid.\n" >&2
- exit 2
+ exit 1
fi
-SRCDIR="$(head -n 1 record.conf | cut -c 10-)"
-. "$SRCDIR"/shell_utils.sh
-VERSION=$(get_json_key version "$(cat "$SRCDIR"/manifest.json)")
+SRCDIR="$(grep '^srcdir = ' record.conf)"
+SRCDIR="${SRCDIR#'srcdir = '}"
+
+DEFAULT_TARGET="$(grep '^default_target = ' record.conf)"
+DEFAULT_TARGET="${DEFAULT_TARGET#'default_target = '}"
+
+eval VERSION=$(cat "$SRCDIR/version")
-sed '/^# Configuration goes here$/r record.conf
+sed '/^# Configuration gets included here by write_makefile\.sh$/r record.conf
s|<<VPATH>>|'"$SRCDIR"'|
-s/<<VERSION>>/'$VERSION/ < "$SRCDIR"/Makefile.in > Makefile
+s/<<VERSION>>/'"$VERSION"/ < "$SRCDIR"/Makefile.in > Makefile