Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] distutils-r1.eclass: Add assertions for bindir correctness
Date: Thu, 09 Jun 2022 19:01:06
Message-Id: 20220609190051.2254514-1-mgorny@gentoo.org
1 The eclass code in distutils-r1_python_install makes some assumptions
2 specific to _distutils-r1_post_python_compile being called,
3 and scriptdir not being modified since. Make them more explicit by:
4
5 1) explicitly removing the files that we expect to have been created,
6
7 2) verifying that both the copied and the original scriptdir have
8 the same list of files.
9
10 Signed-off-by: Michał Górny <mgorny@g.o>
11 ---
12 eclass/distutils-r1.eclass | 24 +++++++++++++++++++++++-
13 1 file changed, 23 insertions(+), 1 deletion(-)
14
15 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
16 index f3d224a51224..0e069597b3ab 100644
17 --- a/eclass/distutils-r1.eclass
18 +++ b/eclass/distutils-r1.eclass
19 @@ -1514,11 +1514,33 @@ distutils-r1_python_install() {
20 local merge_root=
21 if [[ ${DISTUTILS_USE_PEP517} ]]; then
22 local root=${BUILD_DIR}/install
23 + local wrapped_scriptdir=${root}$(python_get_scriptdir)
24 +
25 + # we are assuming that _distutils-r1_post_python_compile
26 + # has been called and ${root} has not been altered since
27 + # let's explicitly verify these assumptions
28 +
29 + # remove files that we've created explicitly
30 + rm "${root}${scriptdir}"/{"${EPYTHON}",python3,python,pyvenv.cfg} || die
31 + # verify that scriptdir & wrapped_scriptdir both contain
32 + # the same files
33 + local ck1=$(
34 + { cd "${root}${scriptdir}" && find . -type f -print0; } |
35 + sort -z | cksum
36 + )
37 + local ck2=$(
38 + { cd "${wrapped_scriptdir}" 2>/dev/null &&
39 + find . -type f -print0; } |
40 + sort -z | cksum
41 + )
42 + if [[ ${ck1} != ${ck2} ]]; then
43 + die "File lists for ${root}${scriptdir} and ${wrapped_scriptdir} differ"
44 + fi
45 +
46 # remove the altered bindir, executables from the package
47 # are already in scriptdir
48 rm -r "${root}${scriptdir}" || die
49 if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
50 - local wrapped_scriptdir=${root}$(python_get_scriptdir)
51 if [[ -d ${wrapped_scriptdir} ]]; then
52 mv "${wrapped_scriptdir}" "${root}${scriptdir}" || die
53 fi
54 --
55 2.35.1