summaryrefslogtreecommitdiff
path: root/project/hoppla.sh
blob: a28156a98dbcc8996f05e06230e50d019fc84f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh

# the purpose of this script is to speed-up the support
# of additional variants. it is not very pretty, but
# does the job quite well. please read the script in
# its entirety before executing it.

set -eu

trap usage 1 EXIT

py_refdir=$(pwd)
py_hoppla=$(basename "$0")
py_differ=

usage()
{
	printf '%s: %s %s\n' "$py_hoppla" \
		'please read this script' \
		'and understand what it does.' >&2
	exit 1
}

if ! [ -z ${4:-} ]; then
	printf '%s: too many arguments.\n' "$py_hoppla" >&2
	exit 1
fi

if ! [ -z ${3:-} ]; then
	if [ "$3" != '--diff-only' ] && [ "$3" != '-d' ]; then
		printf '%s: %s %s\n' "$py_hoppla" \
			'invalid third argument' \
			'(must be --diff-only or -d).' >&2
		exit 1
	else
		py_differ=yes
	fi
fi

py_base_ver="$1"
py_curr_ver="$2"

PY_SOURCE_PREFIX=${PY_SOURCE_PREFIX:-}

if [ -z $PY_SOURCE_PREFIX ]; then
	PY_SOURCE_PREFIX=$py_refdir
fi

for py_ver in "$py_base_ver" "$py_curr_ver"; do
	case "$py_ver" in
		[0-9].[0-9].[0-9] )
			if ! [ -d "$PY_SOURCE_PREFIX"/Python-$py_ver ]; then
				printf '%s: %s: %s\n' "$py_hoppla" \
					"$PY_SOURCE_PREFIX"/Python-$py_ver \
					'the directory does not exist.' >&2
					exit 1
			fi
			;;
		* )
			printf '%s: %s %s\n' "$py_hoppla" \
				">>$py_ver<<" 'is not a valid python version.' >&2
			exit 1
	esac
done

for py_ver in $py_base_ver $py_curr_ver; do
	if [ -z $py_differ ]; then
		mkdir $py_refdir/$py_ver.build
		cd    $py_refdir/$py_ver.build

		printf '%s: configure.\n' $py_ver

		"$PY_SOURCE_PREFIX"/Python-$py_ver/configure \
			--enable-ipv6 > /dev/null

		printf '%s: make.\n' $py_ver

		make V=2 >pylog
	else
		cd $py_refdir/$py_ver.build
	fi

	py_dot=$(printf '%s' $py_ver | sed -e 's/\.[^.]*$//g')
	py_abi=$(printf '%s' $py_dot | sed -e 's/\.//g')

	grep -e ' -c ' pylog | grep -v -e 'build/temp.' -e '/install' \
			| sed -e 's@Python-'$py_ver/'@Python-pyver/@g' \
			      -e 's@-Wstrict-prototypes@@g' \
			      -e 's@-Werror=implicit-function-declaration@@g' \
			      -e 's@-Wno-unused-result@@g' \
			      -e 's@-Wsign-compare@@g' \
			      -e 's@-DNDEBUGe@@g' \
			      -e 's@-DPy_BUILD_CORE_BUILTIN@@g' \
			      -e 's@-DPy_BUILD_CORE@@g' \
			      -e 's@-g -fwrapv -O3 -Wall@@g' \
			      -e 's@-std=c99 -Wextra@@g' \
			      -e 's@-Wno-missing-field-initializers@@g' \
			      -e 's@-Wno-unused-result@@g' \
			      -e 's@-Wno-unused-parameter@@g' \
			      -e 's@-Wno-implicit-fallthrough@@g' \
			      -e 's@-Wno-cast-function-type@@g' \
			      -e 's@-Werror@@g' \
			      -e 's/  */ /g' \
			      -e 's/[ \t]*$//' \
		| sort > cccore.log

	grep -e ' -c ' pylog | grep -e 'build/temp.' \
			| sed -e 's@Python-'$py_ver/'@Python-pyver/@g' \
			      -e 's@'/$py_ver.build'@/pyver.build@g' \
			      -e 's@'$py_dot/'@pydot/@g' \
			      -e 's@-Wstrict-prototypes@@g' \
			      -e 's@-Werror=implicit-function-declaration@@g' \
			      -e 's@-Wno-unused-result@@g' \
			      -e 's@-Wsign-compare@@g' \
			      -e 's@-DNDEBUGe@@g' \
			      -e 's@-DBLAKE2_USE_SSE=1@@g' \
			      -e 's@-g -fwrapv -O3 -Wall@@g' \
			      -e 's@-std=c99 -Wextra@@g' \
			      -e 's@-Wno-missing-field-initializers@@g' \
			      -e 's@-Wno-unused-result@@g' \
			      -e 's@-Wno-unused-parameter@@g' \
			      -e 's@-Wno-implicit-fallthrough@@g' \
			      -e 's@-Wno-cast-function-type@@g' \
			      -e 's@-Werror@@g' \
			      -e 's/  */ /g' \
			      -e 's/[ \t]*$//' \
		| sort > ccext.log

	grep -e ' -shared ' pylog | grep -e '.cpython-' \
			| sed -e 's@Python-'$py_ver/'@Python-pyver/@g' \
			      -e 's@.cpython-'$py_abi'@.cpython-pyabi.@g' \
			      -e 's@'-$py_dot'/@-pydot/@g' \
		| sort > pyext.log

	find . -name '*.cpython-*' \
			| sed -e 's@.cpython-'$py_abi'@.cpython-pyabi.@g' \
			      -e 's@'-$py_dot'/@-pydot/@g' \
		| sort > pyext.lst

	find "$PY_SOURCE_PREFIX"/Python-$py_ver/Include -maxdepth 1 -name '*.h' \
			| sed -e 's@Python-'$py_ver/'@Python-pyver/@g' \
		| sort > pyhdr.lst
done

diffdir=$py_base_ver-vs-$py_curr_ver
logfiles="cccore.log ccext.log pyext.log pyext.lst pyhdr.lst"
genfiles="pyconfig.h Modules/config.c"

cd $py_refdir
mkdir -p $diffdir

for f in $logfiles $genfiles; do
	diffname=$(basename $f | sed -e 's/\.[^.]*$//g')

	diff -u \
			$py_refdir/$py_base_ver.build/$f \
			$py_refdir/$py_curr_ver.build/$f \
		> $diffdir/$diffname.diff || true
done

for pysrc in setup.py configure.ac; do
	diff -u "$PY_SOURCE_PREFIX"/Python-$py_base_ver/$pysrc "$PY_SOURCE_PREFIX"/Python-$py_curr_ver/$pysrc \
		> $diffdir/$pysrc.diff || true
done

trap '' 0
echo yay.

exit 0