Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 250240 - /etc/portage/bashrc is sourced multiple times
Summary: /etc/portage/bashrc is sourced multiple times
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-08 01:05 UTC by Lars Strojny
Modified: 2019-07-19 15:31 UTC (History)
3 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 Lars Strojny 2008-12-08 01:05:16 UTC
I'm using /etc/portage/bashrc to apply package specific FEATURES and CFLAGS for debugging purposes. To make this easier I always einfo out what specific env files are being used for the current build.

My bashrc looks like that:
for conf in ${CATEGORY} ${PN} ${PN}-${PV} ${PN}-${PV}-${PR}; do
	if [[ "${conf}" == "${CATEGORY}" ]] ; then
		env=/etc/portage/env/${CATEGORY}.env
	else
		env=/etc/portage/env/${CATEGORY}/${conf}.env
	fi
	if [[ -f  ${env} ]]; then
		einfo "Reading specific environment from ${env}"
		. ${env}
	fi
done

For debugging purposes I've replaced the bashrc with a simple one liner:

einfo "/etc/portage/bashrc sourced"

The example output from "emerge portage" follows. As you can see, /etc/portage/bashrc is sourced a lot, which is not really necessary.

lstrojny@lstrojny /etc/portage $ sudo emerge portage
Calculating dependencies... done!

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) sys-apps/portage-2.2_rc17
 * portage-2.2_rc17.patch.bz2 RMD160 SHA1 SHA256 size ;-) ...                                                                                                               [ ok ]
 * portage-2.2_rc15.tar.bz2 RMD160 SHA1 SHA256 size ;-) ...                                                                                                                 [ ok ]
>>> Creating Manifest for /usr/portage/sys-apps/portage
  digest.assumed                 8
   portage-2.1.1-r2::portage-2.1.1-r2.patch.bz2
   portage-2.1.1-r2::portage-2.1.1.tar.bz2
   portage-2.1.1-r2::portage-man-pl-2.1-r1.patch.bz2
   portage-2.1.1-r2::portage-man-pl-2.1.tar.bz2
   portage-2.1.4.5::portage-2.1.4.5.patch.bz2
   portage-2.1.4.5::portage-2.1.4.tar.bz2
   portage-2.1.4.5::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc1::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc2::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc3::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc16::portage-2.2_rc16.patch.bz2
   portage-2.2_rc16::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc17::portage-man-pl-2.1.2.tar.bz2
 * checking ebuild checksums ;-) ...                                                                                                                                        [ ok ]
 * checking auxfile checksums ;-) ...                                                                                                                                       [ ok ]
 * checking miscfile checksums ;-) ...                                                                                                                                      [ ok ]
 * /etc/portage/bashrc sourced
You should enable -g (or higher) for debugging!
 * /etc/portage/bashrc sourced
>>> Creating Manifest for /usr/portage/sys-apps/portage
  digest.assumed                 8
   portage-2.1.1-r2::portage-2.1.1-r2.patch.bz2
   portage-2.1.1-r2::portage-2.1.1.tar.bz2
   portage-2.1.1-r2::portage-man-pl-2.1-r1.patch.bz2
   portage-2.1.1-r2::portage-man-pl-2.1.tar.bz2
   portage-2.1.4.5::portage-2.1.4.5.patch.bz2
   portage-2.1.4.5::portage-2.1.4.tar.bz2
   portage-2.1.4.5::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc1::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc2::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc3::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc16::portage-2.2_rc16.patch.bz2
   portage-2.2_rc16::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc17::portage-man-pl-2.1.2.tar.bz2
 * /etc/portage/bashrc sourced
>>> Unpacking source...
>>> Unpacking portage-2.2_rc17.patch.bz2 to /var/tmp/portage/sys-apps/portage-2.2_rc17/work
>>> Unpacking portage-2.2_rc15.tar.bz2 to /var/tmp/portage/sys-apps/portage-2.2_rc17/work
 * Applying portage-2.2_rc17.patch ...                                                                                                                                       [ ok ]
 * Setting portage.VERSION to 2.2_rc17 ...
>>> Source unpacked.
>>> Creating Manifest for /usr/portage/sys-apps/portage
  digest.assumed                 8
   portage-2.1.1-r2::portage-2.1.1-r2.patch.bz2
   portage-2.1.1-r2::portage-2.1.1.tar.bz2
   portage-2.1.1-r2::portage-man-pl-2.1-r1.patch.bz2
   portage-2.1.1-r2::portage-man-pl-2.1.tar.bz2
   portage-2.1.4.5::portage-2.1.4.5.patch.bz2
   portage-2.1.4.5::portage-2.1.4.tar.bz2
   portage-2.1.4.5::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc1::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc2::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc3::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc16::portage-2.2_rc16.patch.bz2
   portage-2.2_rc16::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc17::portage-man-pl-2.1.2.tar.bz2
 * /etc/portage/bashrc sourced
>>> Compiling source in /var/tmp/portage/sys-apps/portage-2.2_rc17/work/portage-2.2_rc15 ...
>>> Source compiled.
>>> Creating Manifest for /usr/portage/sys-apps/portage
  digest.assumed                 8
   portage-2.1.1-r2::portage-2.1.1-r2.patch.bz2
   portage-2.1.1-r2::portage-2.1.1.tar.bz2
   portage-2.1.1-r2::portage-man-pl-2.1-r1.patch.bz2
   portage-2.1.1-r2::portage-man-pl-2.1.tar.bz2
   portage-2.1.4.5::portage-2.1.4.5.patch.bz2
   portage-2.1.4.5::portage-2.1.4.tar.bz2
   portage-2.1.4.5::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc1::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc2::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc3::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc16::portage-2.2_rc16.patch.bz2
   portage-2.2_rc16::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc17::portage-man-pl-2.1.2.tar.bz2
 * /etc/portage/bashrc sourced
>>> Test phase [not enabled]: sys-apps/portage-2.2_rc17
>>> Creating Manifest for /usr/portage/sys-apps/portage
  digest.assumed                 8
   portage-2.1.1-r2::portage-2.1.1-r2.patch.bz2
   portage-2.1.1-r2::portage-2.1.1.tar.bz2
   portage-2.1.1-r2::portage-man-pl-2.1-r1.patch.bz2
   portage-2.1.1-r2::portage-man-pl-2.1.tar.bz2
   portage-2.1.4.5::portage-2.1.4.5.patch.bz2
   portage-2.1.4.5::portage-2.1.4.tar.bz2
   portage-2.1.4.5::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc1::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc2::portage-man-pl-2.1.2.tar.bz2
   portage-2.1.6_rc3::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc16::portage-2.2_rc16.patch.bz2
   portage-2.2_rc16::portage-man-pl-2.1.2.tar.bz2
   portage-2.2_rc17::portage-man-pl-2.1.2.tar.bz2
 * /etc/portage/bashrc sourced

>>> Install portage-2.2_rc17 into /var/tmp/portage/sys-apps/portage-2.2_rc17/image/ category sys-apps
patching file make.conf
>>> Completed installing portage-2.2_rc17 into /var/tmp/portage/sys-apps/portage-2.2_rc17/image/

 * /etc/portage/bashrc sourced
strip: x86_64-pc-linux-gnu-strip --strip-unneeded -R .comment
ecompressdir: bzip2 -9 /usr/share/man

>>> Installing sys-apps/portage-2.2_rc17
 * /etc/portage/bashrc sourced
 * /etc/portage/bashrc sourced
 * /etc/portage/bashrc sourced
 * /etc/portage/bashrc sourced
 * Cleaning orphaned Python bytecode from /usr/lib64/portage/pym ..
 * /etc/portage/bashrc sourced
 * /etc/portage/bashrc sourced
 * Byte compiling python modules for python-2.5 .. ...                                                                                                                       [ ok ]
 * 
 * For help with using portage please consult the Gentoo Handbook
 * at http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3
 * 
 * If you're upgrading from a pre-2.2 version of portage you might
 * want to remerge world (emerge -e world) to take full advantage
 * of some of the new features in 2.2.
 * This is not required however for portage to function properly.
 * 
 * /etc/portage/bashrc sourced
 * /etc/portage/bashrc sourced
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.
Comment 1 Wormo (RETIRED) gentoo-dev 2008-12-08 02:18:41 UTC
I believe this multiple sourcing is a side-effect of the current implementation of pre- and post-hooks for each ebuild phase. 

Assigning to portage devs in case someone wants to consider this feature request, or wants to explain why it is the way it is.
Comment 2 Zac Medico gentoo-dev 2008-12-08 02:40:33 UTC
It's pretty common for bashrc users to rely on it being sources for every ebuild phase. Rather than put code directly in global scope, you should put it inside a pre_ or post_ phase hook function, or else make it conditional on the $EBUILD_PHASE variable.

For example:

  pre_pkg_setup() {
    # your code here
  }

or

  if [ "$EBUILD_PHASE" = setup ] ; then
    # your code here
  fi
Comment 3 Petross404(Petros S) 2019-07-19 10:18:37 UTC
(In reply to Zac Medico from comment #2)
> It's pretty common for bashrc users to rely on it being sources for every
> ebuild phase. Rather than put code directly in global scope, you should put
> it inside a pre_ or post_ phase hook function, or else make it conditional
> on the $EBUILD_PHASE variable.
> 
> For example:
> 
>   pre_pkg_setup() {
>     # your code here
>   }
> 
> or
> 
>   if [ "$EBUILD_PHASE" = setup ] ; then
>     # your code here
>   fi

Out of curiosity, shouldn't this be like this? :
if [[ "${EBUILD_PHASE}" == "setup" ]] ; then
     # your code here
fi

I am not trying to outsmart anyone here, it's an honest question. I think [[ should be preferred?
Comment 4 Mike Gilbert gentoo-dev 2019-07-19 15:30:29 UTC
(In reply to Petross404(Petros S) from comment #3)

Either syntax should work. [[ ]] is generally preferred in ebuilds.