Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 56408 - ebuild environment should be properly saved and reused, and general cleanup
Summary: ebuild environment should be properly saved and reused, and general cleanup
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Ebuild Support (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
: 42941 110098 (view as bug list)
Depends on:
Blocks: 40993 46223 env-handling 52652 54652 125493 200044
  Show dependency tree
 
Reported: 2004-07-07 21:39 UTC by Brian Harring (RETIRED)
Modified: 2007-12-04 01:39 UTC (History)
10 users (show)

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


Attachments
portage.py.patch (pre12-setup.patch,553 bytes, patch)
2004-07-07 21:42 UTC, Brian Harring (RETIRED)
Details | Diff
ebuild.sh v1 (ebuild.sh,17.96 KB, text/plain)
2004-07-07 21:45 UTC, Brian Harring (RETIRED)
Details
ebuild-default-functions.sh (ebuild-default-functions.sh,27.30 KB, text/plain)
2004-07-07 21:47 UTC, Brian Harring (RETIRED)
Details
ebuild-functions.sh (ebuild-functions.sh,4.43 KB, text/plain)
2004-07-07 21:50 UTC, Brian Harring (RETIRED)
Details
portage.py.patch v2 (pre12-setup.patch,924 bytes, patch)
2004-07-08 10:01 UTC, Brian Harring (RETIRED)
Details | Diff
ebuild.sh v2 (ebuild.sh,15.24 KB, text/plain)
2004-07-12 13:12 UTC, Brian Harring (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:39:24 UTC
Currently, ebuild.sh is designed such that it sources the ebuild (and requisite eclass's) for every stage- this is wasteful, and prone to lots of situations/bugs that shouldn't be allowed.

Specifically, during removal-
A) portage's functions/returns need to be what the ebuild expected when it was merged- any older ebuild's merged that expected use_enable to return 1 or 0 won't function correctly under .51 where 
use_enable returns 0 always (same for use_with).

B) the eclass could've changed *radically* since the ebuild was first emerged, and there is no gurantee that the ebuild is compatible with the newer version of the eclass.  Yes, yelling at people to 
maintain the eclass such that they are fully backwards compatible is probably the first reaction, but this isn't a viable solution, let alone realistic.

General issues
A) during an actual emerge, multiple files on the fs are accessed at each stage- this introduces the possibility of a typo in /etc/profile.env or /etc/init.d/functions or /etc/rc.d/config/functions to cause a long running emerge to bail out when it hits the next phase.  This behaviour isn't desired, nor is it really right/sane- once an emerge has started, it's not safe/sane/fun to have the possibility of the env/functions available changing.

B) ebuild.sh's current method of storing ebuild defined vars drops *all* attributes- see bug #52652 for a real world example where it causes borkage.

C) ebuild.sh stomps on vars passed into it (think USE="blah" ebuild dar) via sourcing.  See bug #51095 for background, bug #51552 for the actual request and bug #51370 for a package this is causing user issues for.

D) All QA interceptors are currently disabled due to a simple typo in ebuild.sh.  This is easily fixed, but there is no point in having these functions defined (read: *used*) when ebuild.sh is not processing an ebuild in a DEPEND phase.  Added, no point in defining a half dozen functions (and having them in the env permenantly) that are exactly the same minus the function name; this should be automated and generated via an eval; the QA interceptors should also be able to be yanked from the env.

E) Do to the current layout of ebuild.sh, it's entirely possible for an ebuild/eclass to overwrite internal ebuild.sh functions.  The ebuild.sh internal functions *should* not be overwrote, and there is no point in letting them be overwrote- functions can be flagged read only too.  Note this exempts a set of functions the ebuild expects, src_unpack, src_compile, etc.  In general, ebuild.sh expects certain functions to be sane (dyn_clean, dyn_setup, hasq, etc) that the ebuild should never be touching.  So we should lock them down.  This also would apply to eclasses.
To head off the "declaring blah readonly isn't going to make things any more secure", marking internals functions as readonly isn't intended to make things more secure.  It's intended to lock down the ebuild environment so that debugging these beasts is easier, so that we can state 'well it has to be screwing up in this function- everything else is locked down'.

F) Env vars can be changed between individual ebuild phases when using the ebuild python script for debugging- this makes debugging potentially trickier.  Been using BLAH="x" ebuild cpv.ebuild phase for testing, and you do notice you forget the BLAH="x" definition for a phase- you've just changed the ebuild's environment.  The environment defined/available in setup should be taken as the initial snapshot, and propogated on through the phases.

G) the setup phase should not be wiping ${T} (this is specific to portage.py)- that's what clean is for.  Additionally, setup should be ran only once when stepping through phase's via the ebuild python.

Yeah... I think that's most of it.

Everything listed above I've addressed in my the ebuild.sh rewrite/gutting/surgery; exempting 4 lines of modification to portage.py, it's all bash env related.  It's also backwards compatible- since my version of ebuild.sh locks down it's internals, there is no way for older saved envs from installed ebuilds to hose up the current env.

Aside from that, the rewrote ebuild*.sh ought to be up to date w/ .51_pre12; it was based off of pre10, and I've merged changes in by hand (only changes being bug 53368 ebuild.sh patch inclusion).

PORTDIR_LOG has been intentionally backed out of ebuild.sh- this should be moved up into spawn, abuse the piping ability.  Recursing ebuild.sh is kinda nasty as a method to start up the logging :)
Comment 1 Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:42:45 UTC
Created attachment 34978 [details, diff]
portage.py.patch

Patch to stop doebuild from wiping ${T}; this is clean's job.
Comment 2 Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:45:08 UTC
Created attachment 34979 [details]
ebuild.sh v1

ebuild.sh .  No point in submitting a diff, I've moved things around *way* too
much for the diff to be sane (although ignoring white space might make it
saner).

ebuild.sh is purely the arg processing, and env handling code.	All
non-essential functions have been moved out for the sake of keeping things neat
and clean.
Debug code is disabled, but currently left in place.
Comment 3 Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:47:28 UTC
Created attachment 34980 [details]
ebuild-default-functions.sh

ebuild.sh's internal functions; these are all marked readonly, and not saved in
the ebuild's env.
Think of it as ebuild.sh's internal/req'd functions.
Comment 4 Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:50:00 UTC
Created attachment 34981 [details]
ebuild-functions.sh

functions saved in the packages saved env.  use_with/use_enable, etc. 
Functions that may change, and *will* directly affect that ebuild down the
line.
These functions are able to change w/out issue- the functions defined in
-default-functions should maintain their return behaviours.

Basically think of this as ebuild.sh's api for ebuilds (horrid description, but
it'll do).
Comment 5 Brian Harring (RETIRED) gentoo-dev 2004-07-07 21:54:30 UTC
To give a general idea of how much abuse this code has been put through, keep in mind this is a split up ebuild.sh w/ a lot of env loving applied- basically I didn't change code unless I had to.  So large portions of the code have already been tested prior to me shifting them around.

Additionally, I brought my system up from a stage1 to full xorg-x11/flux/mozilla/etc using these patches.  The modifications have behaved rather well.

/me shuts up after that flood of patches/files/comments :)
Comment 6 Brian Harring (RETIRED) gentoo-dev 2004-07-08 10:01:32 UTC
Created attachment 35014 [details, diff]
portage.py.patch v2

Uploaded an old patch that left out the fix for setup cleansing.
Now $T is only cleansed during the clean ebuild phase.
Comment 7 Brian Harring (RETIRED) gentoo-dev 2004-07-12 13:12:18 UTC
Created attachment 35262 [details]
ebuild.sh v2

One line adjustment changing
source /etc/init.d/functions.sh
to
source /etc/init.d/functions.sh ${EBUILD_PHASE}

Otherwise, /etc/init.d/functions will make a portageq call, *horrendously*
slowing things down.
Comment 8 Paul de Vrieze (RETIRED) gentoo-dev 2004-11-09 11:45:03 UTC
A suggestion, I think we should make sure that it is still possible to change an ebuild and then just go on with the stage we were. This is very helpfull for development (could be feature protected though), saving precious time unpacking things for the umpteenth time, and preserving the compile history.

Similarly, ebuild might be coded such that in some cases changes in command line useflags are incorporated.
Comment 9 Brian Harring (RETIRED) gentoo-dev 2004-11-10 04:25:59 UTC
I see no point in allowing use flags to change midway through the build process, since it allows for the possibility of earlier phases assuming xyz to be true, and later stages assuming zyx to be true.

The changes induced in cvs to protect the env are intended to ensure the build process is exact in it's usage of the env, same for removal of packages.
Basically, these changes ensure things are correct, at the expense of a bit of flexibility for the developer who is attempting to walk through each phase continually adjusting the ebuild.

Personally, what I do is this- if I'm walking through the phases of an ebuild w/ this code, and want to make a change, I just modify the saved environment.  That is what's used, and is easy to tweak.  Test the changes w/in the saved env, then add them into the ebuild.

Worth noting for those using portage-cvs or these patches (or the ebd patchset), the detection of completed phases is no longer a collection of "does blah exist"- /var/tmp/portage/${P}/.completed_stages holds the list of phases that have finished.

As to why I *really* dislike this request, you're basically after making the env non-linear via an opt.  building/merging of the package for the user -will- be linear in env handling, as such, the dev should be testing the ebuild under that setup.  They can always modify the saved env if they're walking the phases and doing debugging...
Comment 10 Brian Harring (RETIRED) gentoo-dev 2005-02-28 00:08:08 UTC
*** Bug 42941 has been marked as a duplicate of this bug. ***
Comment 11 Brian Harring (RETIRED) gentoo-dev 2005-02-28 00:20:48 UTC
This is in portage cvs head (has been for about ~3 months).
Comment 12 Jason Stubbs (RETIRED) gentoo-dev 2005-07-14 05:47:40 UTC
Fixed on or before 2.0.51.22-r1 
Comment 13 Jason Stubbs (RETIRED) gentoo-dev 2005-07-14 06:58:28 UTC
Looking through the batch of bugs, I'm not sure that some of these are 
actually fixed in stable. Others, the requirements have possibly changed after 
the initial fix was committed. 
 
If you think this bug has been closed incorrectly, please reopen or ask that 
it be reopened. 
Comment 14 Brian Harring (RETIRED) gentoo-dev 2005-07-14 12:49:07 UTC
This bug is still an issue, although most of the dependencies have been worked
around in a fashion.
So... leave 'er closed, it's fixed in what's being worked on for next version.
Comment 15 Brian Harring (RETIRED) gentoo-dev 2005-10-21 22:53:41 UTC
Not fixed... it's not in stable.
Comment 16 Brian Harring (RETIRED) gentoo-dev 2005-10-21 22:54:41 UTC
*** Bug 110098 has been marked as a duplicate of this bug. ***