Project

General

Profile

« Previous | Next » 

Revision 7965f1b4

Added by koszko over 1 year ago

improve the build system

View differences:

Makefile.in
16 16
VPATH = <<VPATH>>
17 17

  
18 18
version = <<VERSION>>
19
PYTEST = <<PYTEST>>
20 19
extension_files = background/ common/ content/ html/ licenses/ \
21 20
        copyright default_settings.json manifest.json
22 21

  
23 22
metafiles = build.sh configure Makefile.in process_html_file.sh README.txt \
24 23
        re-generate_icons.sh shell_utils.sh upload_amo.sh write_makefile.sh
25 24

  
26
# Configuration goes here
25
# Configuration gets included here by write_makefile.sh
27 26

  
28 27
# The default target: placed up here
29 28
default: $(default_target)
......
45 44
mozilla: mozilla-build.zip
46 45
chromium: chromium-build.zip
47 46

  
48
unpacked: $(default_target)-unpacked
47
unpacked: $(default_target)-unpacked Makefile
49 48
all-unpacked: mozilla-unpacked chromium-unpacked
50 49
%-unpacked: $(extension_files) icons/haketilo16.png
51 50
	$(srcdir)/build.sh $* $(srcdir) $(UPDATE_URL)
......
57 56
uninstall:
58 57
	rm -r "$(DESTDIR)/{6fe13369-88e9-440f-b837-5012fb3bedec}"
59 58

  
60
%-build.zip: %-unpacked
59
%-build.zip: %-unpacked Makefile
61 60
	cd $< && zip -q -r ../$@ *
62 61

  
63
test/certs/:
62
test/:
63
	mkdir $@
64

  
65
test/certs/: | test/
64 66
	mkdir $@
65 67

  
66 68
test/certs/%.key: | test/certs/
......
71 73
		 -subj "/CN=Haketilo Test"
72 74

  
73 75
test: test/certs/rootCA.pem test/certs/site.key $(default_target)-build.zip
74
	MOZ_HEADLESS=whatever $(PYTEST)
76
	MOZ_HEADLESS=whatever $(PYTHON) -m pytest
75 77

  
76 78
test-environment: test/certs/rootCA.pem test/certs/site.key
77 79
	python3 -m test
......
82 84

  
83 85
# helper targets
84 86
clean mostlyclean:
85
	rm -rf mozilla-unpacked chromium-unpacked haketilo-$(version)
86
	rm -f mozilla-build.zip chromium-build.zip haketilo-$(version).tar.gz \
87
	        haketilo-$(version).tar exports_init.js
87
	rm -rf mozilla-unpacked chromium-unpacked haketilo-[1-9]*
88
	rm -f mozilla-build.zip chromium-build.zip exports_init.js
88 89
	rm -rf test/certs
89 90
	rm -rf $$(find . -name geckodriver.log)
90 91
	rm -rf $$(find . -type d -name __pycache__)
configure
2 2

  
3 3
# This file is part of Haketilo
4 4
#
5
# Copyright (C) 2021, jahoti
5
# Copyright (C) 2021 Jahoti
6
# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
6 7
#
7 8
# This program is free software: you can redistribute it and/or modify
8 9
# it under the terms of the CC0 1.0 Universal License as published by
......
15 16

  
16 17
set -e
17 18

  
19
TARGET_NAME=''
18 20
BROWSERPATH=''
19
SRCDIR=''
20 21
TARGET=''
22
SRCDIR=''
21 23
BROWSER_BINARY=''
22 24
CLEAN_PROFILE=''
23 25
DRIVER=''
24
PYTEST=''
26
PYTHON=''
27

  
28
SOFT_FAILURES=n
29

  
30
ARG0="$0"
25 31

  
26 32
# Parse command line options
27 33
while [ "x$1" != x ]; do
34
    OPT="$1"
35
    case "$OPT" in
36
	chromium | chrome | google-chrome | mozilla | firefox | \
37
	    librewolf | icecat | iceweasel | abrowser | tor-browser)
38
            TARGET_NAME=$1
39
	    shift
40
	    continue
41
	    ;;
42
    esac
43

  
44
    if [ "x$(printf %s "$OPT" | cut -c -2)" = "x--" ]; then
45
	# Process a '--' option
46
	OPT="${OPT#--}"
47
	OPT_NAME="${OPT%%=*}"
48

  
49
	if [ "x$OPT_BASE" != "x$OPT" ]; then
50
	    OPT_VAL="${OPT#*=}"
51
	else
52
	    shift
53
	    OPT_VAL="$1"
54
	fi
55

  
56
	case "$OPT_NAME" in
57
	    srcdir)
58
                SRCDIR="$OPT_VAL";;
59
	    browser-binary)
60
		BROWSER_BINARY="$OPT_VAL";;
61
	    clean-profile)
62
		CLEAN_PROFILE="$OPT_VAL";;
63
	    driver)
64
                DRIVER="$OPT_VAL";;
65
	    python)
66
		PYTHON="$OPT_VAL";;
67
	    srcdir)
68
                SRCDIR="$OPT_VAL";;
69
	    destdir|dstdir)
70
	        DESTDIR="$OPT_VAL";;
71
	    update-url)
72
		UPDATE_URL="$OPT_VAL";;
73
	    host)
74
		TARGET_NAME="$OPT_VAL";;
75
	    *)
76
		printf "Unknown option '--%s'\n" "$OPT_NAME" >&2
77
		exit 1
78
		;;
79
	esac
80

  
81
	shift
82
	continue
83
    fi
84

  
85
    # Process a non-'--' option
86
    OPT_NAME="${OPT%%=*}"
87
    OPT_VAL="${OPT#*=}"
88

  
28 89
    case "$1" in
29
	--srcdir=*)                 SRCDIR="$(printf %s "$1" | cut -c 10-)";;
30
	--srcdir)                                        SRCDIR="$2"; shift;;
31
	--browser-binary=*) BROWSER_BINARY="$(printf %s "$1" | cut -c 18-)";;
32
	--browser-binary)                        BROWSER_BINARY="$2"; shift;;
33
	--clean-profile=*)   CLEAN_PROFILE="$(printf %s "$1" | cut -c 17-)";;
34
	--clean-profile)                          CLEAN_PROFILE="$2"; shift;;
35
	--driver=*)                 DRIVER="$(printf %s "$1" | cut -c 10-)";;
36
	--driver)                                        DRIVER="$2"; shift;;
37
	--pytest=*)                 PYTEST="$(printf %s "$1" | cut -c 10-)";;
38
	--pytest)                                        PYTEST="$2"; shift;;
39
	--srcdir)                                        SRCDIR="$2"; shift;;
40
	"DESTDIR"=*)                DESTDIR="$(printf %s "$1" | cut -c 9-)";;
41
	"UPDATE_URL"=*)         UPDATE_URL="$(printf %s "$1" | cut -c 12-)";;
42
	--host=*)                    TARGET="$(printf %s "$1" | cut -c 8-)";;
43
	--host)                                          TARGET="$2"; shift;;
44

  
45
	# browsers
46
	chromium | chrome | google-chrome | mozilla |\
47
	firefox | librewolf | icecat | iceweasel | abrowser |\
48
	iceweasel-uxp | tor-browser)                 TARGET=$1;;
49
	*)                         echo Ignoring option "'$1'";;
90
	BROWSER_BINARY)
91
            BROWSER_BINARY="$OPT_VAL";;
92
	CLEAN_PROFILE)
93
            CLEAN_PROFILE="$OPT_VAL";;
94
	DRIVER)
95
            DRIVER="$OPT_VAL";;
96
	PYTHON)
97
            PYTHON="$OPT_VAL";;
98
	SRCDIR)
99
            SRCDIR="$OPT_VAL";;
100
	DESTDIR|DSTDIR)
101
            DESTDIR="$OPT_VAL";;
102
	UPDATE_URL)
103
            UPDATE_URL="$OPT_VAL";;
104
	HOST)
105
            TARGET_NAME="$OPT_VAL";;
106
	*)
107
	    printf "Unknown variable '%s'\n" "$OPT_NAME" >&2
108
	    exit 1
109
	    ;;
50 110
    esac
111

  
51 112
    shift
52 113
done
53 114

  
115
# Check TARGET_NAME
116
if [ "x$TARGET_NAME" = x ]; then
117
    printf 'Target not specified. Please use `--host=<browser-name>`.\n' >&2
118
    exit 1
119
fi
120

  
121
# Check and standardize target
122
case "$TARGET_NAME" in
123
    mozilla | firefox | abrowser | icecat | librewolf | iceweasel | tor-browser)
124
	TARGET=mozilla
125
	;;
126
    ungoogled-chromium | chromium | chrome | google-chrome | brave | iridium | \
127
	bromite)
128
	TARGET=chromium
129
	printf "Tests won't yet run on a Chromium-based browser.\n"
130
	SOFT_FAILURES=y
131
	;;
132
    *)
133
	printf 'Invalid target: %s\n' "$TARGET_NAME" >&2
134
	exit 1
135
	;;
136
esac
137

  
54 138
# Autodetect srcdir
55 139
if [ "x$SRCDIR" = x ]; then
56
    SRCDIR=..
57
    if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
58
	SRCDIR=.
140
    if which "$ARG0" >/dev/null 2>&1; then
141
	SRCDIR="$(which "$ARG0")"
142
	SRCDIR="$(dirname "$SRCDIR")"
143
	SRCDIR="$(realpath "$SRCDIR" || true)"
59 144
    fi
145

  
146
    if [ "x$SRCDIR" = x ]; then
147
	SRCDIR=..
148
	if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
149
	    SRCDIR=.
150
	fi
151
    fi
152

  
153
    printf 'Guessing SRCDIR: %s\n' "$SRCDIR"
60 154
fi
61 155

  
62 156
# Check srcdir
63
if [ ! -f "$SRCDIR"/manifest.json ]; then
64
    echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
65
    exit 1
66
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
67
    echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
157
for FILE in manifest.json write_makefile.sh version; do
158
    if [ -f "$SRCDIR"/"$FILE" ]; then
159
	continue
160
    fi
161

  
162
    printf "Invalid source directory '%s': missing %s\n" "$SRCDIR" $FILE >&2
68 163
    exit 1
69
fi
164
done
70 165

  
71
# Autodetect target
72
if [ "x$TARGET" = x ]; then
73
    echo Detecting target automatically.
74
    if [ -h /etc/alternatives/x-www-browser ]; then
75
	BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
76
	TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
77
	    tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
78
    else
79
    	echo Warning: could not find target automatically. >&2
80
    	echo Some make rules may fail. >&2
81
    fi
82
else
83
    BROWSERPATH="$(realpath "$(which $TARGET)")"
84
fi
166
BROWSERPATH="$(realpath "$(which $TARGET_NAME)" 2>/dev/null || true)"
85 167

  
86
# Autodetect browser binary (needed for Selenium)
168
# Guess browser binary (needed for Selenium)
87 169
if [ "x$BROWSER_BINARY" = x ]; then
88
    if [ "x$TARGET" = xabrowser ]; then
170
    if [ "x$TARGET_NAME" = xabrowser ]; then
89 171
	# Trisquel's path to Abrowser
90 172
	BROWSER_BINARY=/usr/lib/abrowser/abrowser
91
    elif [ "x$TARGET" = xlibrewolf ]; then
173
    elif [ "x$TARGET_NAME" = xlibrewolf ]; then
92 174
	# Debian's path to Librewolf
93 175
	BROWSER_BINARY=/usr/share/librewolf/librewolf
94
    elif [ "x$TARGET" = xiceweasel ]; then
176
    elif [ "x$TARGET_NAME" = xiceweasel ]; then
95 177
	# Parabola's path to Iceweasel
96 178
	BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
97
    elif [ "x$TARGET" = xicecat ]; then
179
    elif [ "x$TARGET_NAME" = xicecat ]; then
98 180
	# Parabola's path to IceCat
99 181
	BROWSER_BINARY=/usr/lib/icecat/icecat
100 182
    fi
101
fi
102 183

  
103
# Check and standardize target
104
case "$TARGET" in
105
    mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
106
    librewolf | iceweasel | gnu | tor-browser)   TARGET=mozilla;;
107
    chromium | chrome | google-chrome | google) TARGET=chromium;;
108
    "")                                                        ;;
109
    *)              echo Invalid target "'$TARGET'" >&2; exit 2;;
110
esac
184
    if [ "x$BROWSER_BINARY" != x ]; then
185
	printf 'Guessing BROWSER_BINARY: %s\n' "$BROWSER_BINARY"
186
    elif [ "$TARGET" != "chromium" ]; then
187
	printf 'Cannot guess BROWSER_BINARY for %s.\n' "$TARGET_NAME"
188
	SOFT_FAILURES=y
189
    fi
190
fi
111 191

  
112 192
# Autodetect Selenium driver
113 193
if [ "x$DRIVER" = x ]; then
114
    if [ "x$TARGET" = mozilla ]; then
115
	DRIVER=geckodriver
194
    if [ "x$TARGET" = xmozilla ]; then
195
	DRIVER="$(which geckodriver 2>/dev/null || true)"
196
	if [ -n "$DRIVER" ]; then
197
	    printf 'Guessing DRIVER: %s\n' "$DRIVER"
198
	else
199
	    printf 'Cannot guess DRIVER for %s.\n' "$TARGET_NAME"
200
	fi
116 201
    fi
117 202
fi
118 203

  
119 204
# Autodetect clean profile directory for use in selenium tests
120 205
if [ "x$CLEAN_PROFILE" = x ]; then
121
    if [ "x$TARGET" = mozilla ]; then
206
    if [ "x$TARGET" = xmozilla ]; then
122 207
	CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
123 208
    fi
124 209
fi
125 210

  
126
# Autodetect pytest
127
for PYTEST_GUESS in pytest pytest-3 pytest3; do
128
    if [ "x$PYTEST" = x ]; then
129
	PYTEST="$(which $PYTEST_GUESS || true)"
211
# Autodetect python
212
if [ "x$TARGET" = xmozilla -a "x$PYTHON" = x ]; then
213
    PYTHON2_SKIPPED=n
214
    for PYTHON_GUESS in python3 python-3 python; do
215
	if [ "x$PYTHON" = x ]; then
216
	    PYTHON="$(which $PYTHON_GUESS 2>/dev/null || true)"
217
	fi
218

  
219
	if [ -n "$PYTHON" ]; then
220
	    if [ "$PYTHON_GUESS" = python ]; then
221
		if python --version 2>&1 | grep '^Python 2' >/dev/null; then
222
		    PYTHON=''
223
		    PYTHON2_SKIPPED=y
224
		fi
225
	    fi
226
	fi
227

  
228
	if [ -n "$PYTHON" ]; then
229
	    break
230
	fi
231
    done
232

  
233
    if [ -n "$PYTHON" ]; then
234
	printf 'Guessing PYTHON: %s\n' "$PYTHON"
235
    else
236
	printf 'Cannot guess PYTHON'
237
	if [ "$PYTHON2_SKIPPED" = y ]; then
238
	    printf ' %s' \
239
		   '(skipped Python 2 executable in PATH; Python 3 is required)'
240
	fi
241
	printf '.\n'
242
	SOFT_FAILURES=y
130 243
    fi
131
done
244
fi
132 245

  
133 246
# Autodetect DESTDIR (no check needed)
134 247
if [ "x$DESTDIR" = x ]; then
135
    echo Guessing installation directory.
136
    if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
137
	DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
138
	if [ $TARGET = mozilla ]; then
139
	    DESTDIR="$DESTDIR"/browser
140
	fi
141
	DESTDIR="$DESTDIR"/extensions
248
    if [ "x$TARGET" = xmozilla ]; then
249
	DESTDIR=/usr/share/mozilla/extensions/
250
    elif test "x$TARGET_NAME" = xchromium -o \
251
	      "x$TARGET_NAME" = xungoogled-chromium; then
252
	DESTDIR=/usr/share/chromium/extensions
253
    fi
254

  
255
    if [ -n "$DESTDIR" ]; then
256
	printf 'Guessing DESTDIR: %s\n' "$DESTDIR"
142 257
    else
143
    	echo Warning: could not guess installation directory. >&2
144
    	echo Some make rules may fail. >&2
258
	printf 'Cannot guess DESTDIR.\n'
259
	SOFT_FAILURES=y
145 260
    fi
146 261
fi
147 262

  
......
153 268
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
154 269
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
155 270
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
156
printf '%s\n' "PYTEST = $PYTEST" >> record.conf
271
printf '%s\n' "PYTHON = $PYTHON" >> record.conf
157 272

  
158 273
# Prepare and run write_makefile.sh (as config.status)
159
if [ ! -e config.status ]; then
160
    cp "$SRCDIR"/write_makefile.sh config.status
161
fi
274
cp "$SRCDIR"/write_makefile.sh config.status
162 275

  
163 276
./config.status
277

  
278
if [ "$SOFT_FAILURES" = "y" ]; then
279
    printf 'Some make rules may fail.\n'
280
fi
manifest.json
28 28
#ENDIF
29 29
    "name": "Haketilo",
30 30
    "short_name": "Haketilo",
31
    "version":
31 32
#IF CHROMIUM
32 33
    // Chromium requires version to "be between 1-4 dot-separated integers each
33
    // between 0 and 65536".
34
    "version": "0.65536.1",
34
    // between 0 and 65536". Firefox does not impose such rules, hence, when we
35
    // make a beta release, we assign it the true version under Firefox
36
    // (e.g. "1.0-beta1") and a fake version with 1-lower major and maximal
37
    // allowed minor number under Chromium (e.g. 0.65536.1).
38
#INCLUDE_VERBATIM version_chromium
35 39
#ELSE
36
    "version": "1.0-beta1",
40
#INCLUDE_VERBATIM version
37 41
#ENDIF
42
    ,
38 43
    "author": "Wojtek Kosior & contributors",
39 44
    "description": "Control your \"Web\" browsing.",
40 45
#IF MOZILLA
test/misc_constants.py
37 37
unit_test_defines = ['-D', 'MOZILLA', '-D', 'MV2', '-D', 'TEST',
38 38
                     '-D', 'UNIT_TEST', '-D', 'DEBUG']
39 39

  
40
conf_line_regex = re.compile(r'^([^=]+)=(.*)$')
40
conf_line_regex = re.compile(r'^([^=]+) = (.*)$')
41 41
conf_settings = {}
42 42
with open(here.parent / 'record.conf', 'rt') as conf:
43 43
    for line in conf.readlines():
44 44
        match = conf_line_regex.match(line)
45 45
        if match:
46
            conf_settings[match.group(1).strip()] = match.group(2).strip()
46
            conf_settings[match.group(1).strip()] = match.group(2)
47 47

  
48 48
default_proxy_host = '127.0.0.1'
49 49
default_proxy_port = 1337
version
1
"1.0-beta1"
version_chromium
1
"0.65536.1"
write_makefile.sh
13 13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
# CC0 1.0 Universal License for more details.
15 15

  
16
set -e
17

  
16 18
if [ ! -e record.conf ]; then
17 19
    printf "Record of configuration 'record.conf' does not exist.\n" >&2
18 20
    exit 1
19
elif [ "$(head -n 1 record.conf | cut -c -9)x" != "srcdir = x" ]; then
21
elif ! grep '^srcdir = ' record.conf >/dev/null 2>&1; then
20 22
    printf "Record of configuration 'record.conf' is invalid.\n" >&2
21
    exit 2
23
    exit 1
22 24
fi
23 25

  
24
SRCDIR="$(head -n 1 record.conf | cut -c 10-)"
25
. "$SRCDIR"/shell_utils.sh
26
VERSION=$(get_json_key version "$(cat "$SRCDIR"/manifest.json)")
26
SRCDIR="$(grep '^srcdir = ' record.conf)"
27
SRCDIR="${SRCDIR#'srcdir = '}"
28

  
29
DEFAULT_TARGET="$(grep '^default_target = ' record.conf)"
30
DEFAULT_TARGET="${DEFAULT_TARGET#'default_target = '}"
31

  
32
eval VERSION=$(cat "$SRCDIR/version")
27 33

  
28
sed '/^# Configuration goes here$/r record.conf
34
sed '/^# Configuration gets included here by write_makefile\.sh$/r record.conf
29 35
s|<<VPATH>>|'"$SRCDIR"'|
30
s/<<VERSION>>/'$VERSION/ < "$SRCDIR"/Makefile.in > Makefile
36
s/<<VERSION>>/'"$VERSION"/ < "$SRCDIR"/Makefile.in > Makefile

Also available in: Unified diff