summaryrefslogtreecommitdiff
blob: 4679070328c06bf4caa64c1fcb47ac2358879895 (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
# Copyright 2019-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# QA check: ensure that Python modules are compiled after installing
# Maintainer: Python project <python@gentoo.org>

python_pyc_check() {
	local save=$(shopt -p nullglob)
	shopt -s nullglob
	local progs=( "${EPREFIX}"/usr/lib/python-exec/*/gpep517 )
	${save}

	local invalid=()
	local mismatched_timestamp=()
	local mismatched_data=()
	local missing=()
	local stray=()

	# Avoid running the check if sufficiently new gpep517 is not installed
	# yet. It's valid to schedule (for merge order) >=gpep517-8 after
	# packages which have this check run if they don't use distutils-r1.
	has_version ">=dev-python/gpep517-8" || return

	for prog in "${progs[@]}"; do
		local impl=${prog%/*}
		impl=${impl##*/}

		[[ -d "${ED}"/usr/lib/${impl}/site-packages ]] || continue

		einfo "Verifying compiled files for ${impl}"
		local kind pyc py
		while IFS=: read -r kind pyc py extra; do
			case ${kind} in
				invalid)
					invalid+=( "${pyc}" )
					;;
				mismatched)
					case ${extra} in
						timestamp)
							mismatched_timestamp+=( "${pyc}" )
							;;
						*)
							mismatched_data+=( "${pyc}" )
							;;
					esac
					;;
				missing)
					missing+=( "${pyc}" )
					;;
				older)
					# older warnings were produced by earlier version
					# of gpep517 but the check was incorrect, so we just
					# ignore them
					;;
				stray)
					stray+=( "${pyc}" )
					;;
			esac
		done < <("${prog}" verify-pyc --destdir "${D}" --prefix "${EPREFIX}"/usr)
	done

	local found=
	if [[ ${missing[@]} ]]; then
		eqawarn
		eqawarn "QA Notice: This package installs one or more Python modules that are"
		eqawarn "not byte-compiled."
		eqawarn "The following files are missing:"
		eqawarn
		eqatag -v python-pyc.missing "${missing[@]}"
		found=1
	fi

	if [[ ${invalid[@]} ]]; then
		eqawarn
		eqawarn "QA Notice: This package installs one or more compiled Python modules"
		eqawarn "that seem to be invalid (do not have the correct header)."
		eqawarn "The following files are invalid:"
		eqawarn
		eqatag -v python-pyc.invalid "${invalid[@]}"
		found=1
	fi

	if [[ ${mismatched_data[@]} ]]; then
		eqawarn
		eqawarn "QA Notice: This package installs one or more compiled Python modules whose"
		eqawarn ".py files have different content (size or hash) than recorded:"
		eqawarn
		eqatag -v python-pyc.mismatched.data "${mismatched_data[@]}"
		found=1
	fi

	if [[ ${mismatched_timestamp[@]} ]]; then
		eqawarn
		eqawarn "QA Notice: This package installs one or more compiled Python modules whose"
		eqawarn ".py files have different timestamps than recorded:"
		eqawarn
		eqatag -v python-pyc.mismatched.timestamp "${mismatched_timestamp[@]}"
		found=1
	fi

	if [[ ${stray[@]} ]]; then
		eqawarn
		eqawarn "QA Notice: This package installs one or more compiled Python modules"
		eqawarn "that do not match installed modules (or their implementation)."
		eqawarn "The following files are stray:"
		eqawarn
		eqatag -v python-pyc.stray "${stray[@]}"
		found=1
	fi

	if [[ ${found} ]]; then
		eqawarn
		eqawarn "For more information on bytecode files and related issues, please see:"
		eqawarn "  https://projects.gentoo.org/python/guide/qawarn.html#compiled-bytecode-related-warnings"
	fi
}

python_pyc_check

: # guarantee successful exit

# vim:ft=ebuild