Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 596616 - [TRACKER] Ebuilds calling phase functions
Summary: [TRACKER] Ebuilds calling phase functions
Status: RESOLVED FIXED
Alias: None
Product: Quality Assurance
Classification: Unclassified
Component: Trackers (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Quality Assurance Team
URL: https://projects.gentoo.org/pms/6/pms...
Whiteboard:
Keywords: Tracker
Depends on: 596618 596620 596622 596624 596626 596628 596630 596634 596636 596638 596642 596644 596646 596648
Blocks:
  Show dependency tree
 
Reported: 2016-10-09 08:38 UTC by Michał Górny
Modified: 2023-09-23 15:35 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-10-09 08:38:04 UTC
As pointed out by ulm a while ago:

> Ebuilds must not call nor assume the existence of any phase functions.

In other words, it's invalid to call pkg_foo from pkg_bar. If phase functions share common code, it should be split into a separate function.
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-10-09 08:38:31 UTC
Ref: https://projects.gentoo.org/pms/6/pms.html#x1-940009.1
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-10-09 09:04:37 UTC
@ulm, those are all the violations I've been able to find. Do we want to hold this confusing rule?
Comment 3 Michael Orlitzky gentoo-dev 2016-10-09 17:38:54 UTC
Uhhhh I'll fix this if you want me to, but are you really sure that I can't assume that a pkg_pretend() function exists if I just defined it on the previous line?

  pkg_pretend() {
      # blah blah blah
  }

  pkg_setup() {
      # run again as pkg_pretend is not var safe
      pkg_pretend
  }

It seems counterproductive to cut/paste the entire pkg_pretend() function into e.g. real_pkg_pretend() and then leave a comment about how it's a workaround for some goofy PMS wording.
Comment 4 Ciaran McCreesh 2016-10-09 17:48:29 UTC
Uh, this is not about "some goofy PMS wording"...
Comment 5 Michael Orlitzky gentoo-dev 2016-10-09 18:03:02 UTC
(In reply to Ciaran McCreesh from comment #4)
> Uh, this is not about "some goofy PMS wording"...

Suppose I change it to...

  real_pkg_pretend() {
      # everything cut/pasted from pkg_pretend
  }

  pkg_pretend() {
      real_pkg_pretend
  }

  pkg_setup() {
      # run again as pkg_pretend is not var safe
      real_pkg_pretend
  }

Why am I (not?) allowed to assume that the real_pkg_pretend function exists?

The above implementation purposefully overcomplicates a common construct with no obvious benefit to me. What am I missing?
Comment 6 Ulrich Müller gentoo-dev 2016-10-12 07:29:33 UTC
(In reply to Michael Orlitzky from comment #5)
>   real_pkg_pretend() {
>       # everything cut/pasted from pkg_pretend
>   }
> 
>   pkg_pretend() {
>       real_pkg_pretend
>   }
> 
>   pkg_setup() {
>       # run again as pkg_pretend is not var safe
>       real_pkg_pretend
>   }
Comment 7 Ulrich Müller gentoo-dev 2016-10-12 07:32:08 UTC
(In reply to Michael Orlitzky from comment #5)
>   real_pkg_pretend() {
>       # everything cut/pasted from pkg_pretend
>   }
> 
>   pkg_pretend() {
>       real_pkg_pretend
>   }
> 
>   pkg_setup() {
>       # run again as pkg_pretend is not var safe
>       real_pkg_pretend
>   }

Indeed, that's how it is supposed to look like (the name of the first function could be improved, though). Trivial to fix, so I don't see what is the problem with it.
Comment 8 Austin English (RETIRED) gentoo-dev 2016-10-12 07:43:56 UTC
(In reply to Ulrich Müller from comment #7)
> (In reply to Michael Orlitzky from comment #5)
> >   real_pkg_pretend() {
> >       # everything cut/pasted from pkg_pretend
> >   }
> > 
> >   pkg_pretend() {
> >       real_pkg_pretend
> >   }
> > 
> >   pkg_setup() {
> >       # run again as pkg_pretend is not var safe
> >       real_pkg_pretend
> >   }
> 
> Indeed, that's how it is supposed to look like (the name of the first
> function could be improved, though). Trivial to fix, so I don't see what is
> the problem with it.

I think mostly that the benefit of the change is not being communicated well, so it's seen as a change for no reason.
Comment 9 Ciaran McCreesh 2016-10-12 09:17:36 UTC
(In reply to Austin English from comment #8)
> I think mostly that the benefit of the change is not being communicated
> well, so it's seen as a change for no reason.

The short version is, the package mangler is required to do special things to the phase functions to deal with environment saving, defined phases, eclasses, etc. It is not and has never been the case that the package mangler just sources the ebuild file and starts calling bash functions exactly as they're written. To avoid developers having to understand exactly what happens here (which, annoyingly, sometimes has to change when new bash releases come out), it is easiest if the phase functions are treated as being entirely special.
Comment 10 Michael Orlitzky gentoo-dev 2016-10-12 13:59:27 UTC
(In reply to Ulrich Müller from comment #7)
> 
> Indeed, that's how it is supposed to look like (the name of the first
> function could be improved, though). Trivial to fix, so I don't see what is
> the problem with it.

The problem is that the next person who looks at that code is going to think I'm an idiot and put it back the way it was. To avoid that, every such fix needs a big warning stating that the weird construct is to satisfy the PMS and should not be reverted to the "obviously correct" version.

Should calling phase functions be fatal in a future EAPI? Then we wouldn't need to put a warning next to every workaround.
Comment 11 Ulrich Müller gentoo-dev 2016-10-12 19:44:06 UTC
(In reply to Michael Orlitzky from comment #10)
> Should calling phase functions be fatal in a future EAPI? Then we wouldn't
> need to put a warning next to every workaround.

No need for an EAPI bump, as it never was legal.

@mgorny: Would it be difficult to add a repoman warning for this?
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-10-12 21:39:35 UTC
(In reply to Ulrich Müller from comment #11)
> @mgorny: Would it be difficult to add a repoman warning for this?

I don't know. I don't recall how good repoman was at parsing ebuild code. @dev-portage?
Comment 13 Zac Medico gentoo-dev 2016-10-12 23:06:50 UTC
(In reply to Michał Górny from comment #12)
> (In reply to Ulrich Müller from comment #11)
> > @mgorny: Would it be difficult to add a repoman warning for this?
> 
> I don't know. I don't recall how good repoman was at parsing ebuild code.
> @dev-portage?

Not very good, since it just uses ad-hoc regular expressions, and it will never be able to account for the call stack like a runtime check can.
Comment 14 Zac Medico gentoo-dev 2016-10-13 23:13:01 UTC
Note that repoman does have a PhaseCheck class which has the ability to recognize which phase function that a particular line occurs inside of.
Comment 15 Zac Medico gentoo-dev 2016-10-13 23:16:19 UTC
(In reply to Zac Medico from comment #14)
> Note that repoman does have a PhaseCheck class which has the ability to
> recognize which phase function that a particular line occurs inside of.

Hmm, I guess that's irrelevant though, because any calls to phase functions should be banned, regardless of the function that they occur inside.
Comment 16 Zac Medico gentoo-dev 2016-10-13 23:24:04 UTC
It looks like repoman's NoOffsetWithHelpers check is the closest thing to what you'd want to detect illegal phase function calls.
Comment 17 Larry the Git Cow gentoo-dev 2023-09-23 15:35:14 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=3fcc1f919251c10c1f1ea105f776d7e9c6f5e18e

commit 3fcc1f919251c10c1f1ea105f776d7e9c6f5e18e
Author:     Arthur Zamarin <arthurzam@gentoo.org>
AuthorDate: 2023-09-22 09:12:27 +0000
Commit:     Arthur Zamarin <arthurzam@gentoo.org>
CommitDate: 2023-09-23 15:12:43 +0000

    BannedPhaseCall: detect calls of phase functions directly
    
    Resolves: https://github.com/pkgcore/pkgcheck/issues/625
    Closes: https://bugs.gentoo.org/596616
    Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>

 src/pkgcheck/checks/codingstyle.py                         | 12 +++++++++++-
 .../BadCommandsCheck/BannedPhaseCall/expected.json         |  1 +
 .../BannedPhaseCall/BannedPhaseCall-0.ebuild               | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)