Gentoo Archives: gentoo-dev

From: James Le Cuirot <chewi@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 06/12] python-utils-r1.eclass: Don't die in python_fix_shebang if all fixed
Date: Sun, 06 Jan 2019 14:53:12
Message-Id: 20190106145248.11085256@symphony.aura-online.co.uk
In Reply to: Re: [gentoo-dev] [PATCH 06/12] python-utils-r1.eclass: Don't die in python_fix_shebang if all fixed by "Michał Górny"
1 On Sat, 05 Jan 2019 22:42:27 +0100
2 Michał Górny <mgorny@g.o> wrote:
3
4 > On Sat, 2019-01-05 at 21:38 +0000, James Le Cuirot wrote:
5 > > On Fri, 04 Jan 2019 19:26:34 +0100
6 > > Michał Górny <mgorny@g.o> wrote:
7 > >
8 > > > On Fri, 2019-01-04 at 13:10 -0500, Mike Gilbert wrote:
9 > > > > On Fri, Jan 4, 2019 at 10:55 AM Michał Górny <mgorny@g.o> wrote:
10 > > > > >
11 > > > > > On Thu, 2019-01-03 at 21:39 +0000, James Le Cuirot wrote:
12 > > > > > > Shebangs may need fixing on prefix systems or when cross-building but
13 > > > > > > not at other times.
14 > > > > > >
15 > > > > > > Signed-off-by: James Le Cuirot <chewi@g.o>
16 > > > > > > ---
17 > > > > > > eclass/python-utils-r1.eclass | 8 ++------
18 > > > > > > 1 file changed, 2 insertions(+), 6 deletions(-)
19 > > > > > >
20 > > > > > > diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
21 > > > > > > index 19cfaf2798ab..91e457f3cf14 100644
22 > > > > > > --- a/eclass/python-utils-r1.eclass
23 > > > > > > +++ b/eclass/python-utils-r1.eclass
24 > > > > > > @@ -1328,16 +1328,12 @@ python_fix_shebang() {
25 > > > > > > fi
26 > > > > > > done < <(find -H "${path}" -type f -print0 || die)
27 > > > > > >
28 > > > > > > - if [[ ! ${any_fixed} ]]; then
29 > > > > > > + if [[ ! ${any_fixed} && ! ${any_correct} ]]; then
30 > > > > > > local cmd=eerror
31 > > > > > > [[ ${EAPI:-0} == [012345] ]] && cmd=eqawarn
32 > > > > > >
33 > > > > > > "${cmd}" "QA warning: ${FUNCNAME}, ${path#${D%/}} did not match any fixable files."
34 > > > > > > - if [[ ${any_correct} ]]; then
35 > > > > > > - "${cmd}" "All files have ${EPYTHON} shebang already."
36 > > > > > > - else
37 > > > > > > - "${cmd}" "There are no Python files in specified directory."
38 > > > > > > - fi
39 > > > > > > + "${cmd}" "There are no Python files in specified directory."
40 > > > > > >
41 > > > > > > [[ ${cmd} == eerror ]] && die "${FUNCNAME} did not match any fixable files (QA warning fatal in EAPI ${EAPI})"
42 > > > > > > fi
43 > > > > >
44 > > > > > Sounds like you're introducing breakage, then abusing a function to fix
45 > > > > > your breakage, then killing a useful diagnostic because you've just
46 > > > > > broken it.
47 > > > >
48 > > > > I'm unable to make sense of what you are trying to say here. Is there
49 > > > > something wrong with this patch, or are you making a general comment
50 > > > > on the patch series?
51 > > > >
52 > > >
53 > > > Original usage: rewrite 'python' to 'pythonX.Y', etc. on static files.
54 > > > Throws an error if you try to use for files that have correct shebang
55 > > > already.
56 > > >
57 > > > Now:
58 > > >
59 > > > 1. Due to PYTHON override, generated files frequently have wrong
60 > > > shebangs.
61 > > >
62 > > > 2. python_fix_shebang is modified to fix this -- orthogonal
63 > > > behavior is introduced.
64 > > >
65 > > > 3. Now diagnostic on files with correct shebang is gone because it
66 > > > conflicts with the orthogonal behavior added here.
67 > >
68 > > The diagnostic is a problem even without my changes.
69 > >
70 > > It's quite likely upstream could hardcode a shebang like
71 > > #!/usr/bin/python2.7, which does not need to be modified on normal
72 > > systems but does on prefixed systems.
73 >
74 > Fixing prefix was never the goal.
75
76 And fixing prefix is a bad thing? The prefix team does seem interested
77 in this work. There is a good deal of overlap here and in making sure I
78 wasn't making prefix worse, I had to stop and consider how this would
79 help them too.
80
81 > > What about hardcoding #!/usr/bin/python3.6? This would need correcting
82 > > against 3.7 but would fall foul of the diagnostic when using 3.6.
83 >
84 > No, it would fail as mismatched shebang. By design.
85
86 Okay, I only thought of this case while writing the mail, having
87 forgotten the precise logic since working on it. It doesn't take
88 anything away from the point above though.
89
90 > python_fix_shebang is meant to fix common cases of generic shebangs
91 > in a safe way, not serve as a generic shebang replacement tool.
92
93 Allow me to suggest some options for a compromise. We can't just make
94 the diagnostic conditional on cross/prefix cases as it is the other
95 cases where it would blow up. This leaves us with:
96
97 (a) In cross/prefix cases only, call python_fix_shebang on all files
98 that look like they have a Python-like shebang in pkg_postinst.
99 Unfortunately the Python eclasses don't currently export a pkg_postinst
100 phase function so existing ebuilds using other eclasses may need
101 fixing. These files could be efficiently found with help from awk using
102 something along the lines of this:
103
104 find "${D}" -type f -exec awk '/^#!.*python/ {print FILENAME} {nextfile}' {} +
105
106 (b) Same as (a) but I'll invoke this from cross-boss using bashrc
107 instead of relying on the eclasses. Prefix would need to do its own thing.
108
109 (c) Create a second variant of python_fix_shebang (name TBD) that would
110 only do something in cross/prefix cases. This would be called against
111 the files that only fail in these cases. It would have to be gradually
112 added to ebuilds as problems are found but that was also the case in my
113 original proposal.
114
115 --
116 James Le Cuirot (chewi)
117 Gentoo Linux Developer