Support per-package bashrc files.
authorMichał Górny <gentoo@mgorny.alt.pl>
Thu, 22 Apr 2010 17:43:59 +0000 (17:43 +0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 29 Apr 2010 23:51:48 +0000 (16:51 -0700)
Support loading per-package bashrc files from the /etc/portage/env
directory. The invidual files should reside in a directory matching
${CATEGORY}, with names matching ${PN}, ${PN}:${SLOT}, ${P} and/or ${PF}
(which are applied in that order).

bin/ebuild.sh
bin/isolated-functions.sh
doc/config/bashrc.docbook
man/portage.5
pym/portage/const.py
pym/portage/package/ebuild/config.py
pym/portage/package/ebuild/doebuild.py

index 57ceb28486bb87e0ae3066d8bbc1f691b1cfac3d..968bf6bc518053b73834d24c86149de1be4d056b 100755 (executable)
@@ -1557,17 +1557,20 @@ source_all_bashrcs() {
        # We assume if people are changing shopts in their bashrc they do so at their
        # own peril.  This is the ONLY non-portage bit of code that can change shopts
        # without a QA violation.
-       if [ -f "${PORTAGE_BASHRC}" ]; then
-               # If $- contains x, then tracing has already enabled elsewhere for some
-               # reason.  We preserve it's state so as not to interfere.
-               if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
-                       source "${PORTAGE_BASHRC}"
-               else
-                       set -x
-                       source "${PORTAGE_BASHRC}"
-                       set +x
+       for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
+               if [ -r "${x}" ]; then
+                       # If $- contains x, then tracing has already enabled elsewhere for some
+                       # reason.  We preserve it's state so as not to interfere.
+                       if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
+                               source "${x}"
+                       else
+                               set -x
+                               source "${x}"
+                               set +x
+                       fi
                fi
-       fi
+       done
+
        [ ! -z "${OCC}" ] && export CC="${OCC}"
        [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
 }
index fa23b6675cff607228d228ee7ae7298a48485f51..6bead30b2d31c380f9fc566526db1e907c64d822 100644 (file)
@@ -553,7 +553,7 @@ save_ebuild_env() {
                        LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
                        NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
                        PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST \
-                       PORTAGE_BASHRC PORTAGE_BASHRCS_SOURCED \
+                       PORTAGE_BASHRC PM_EBUILD_HOOK_DIR PORTAGE_BASHRCS_SOURCED \
                        PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE PORTAGE_BUILDDIR \
                        PORTAGE_COLORMAP PORTAGE_CONFIGROOT PORTAGE_DEBUG \
                        PORTAGE_DEPCACHEDIR PORTAGE_GID \
index 2f06262155537c24e39fdd02f24cd2b1659734d4..f36fec5e614ba95dc25d3d82b87e9cff7b0b8b0e 100644 (file)
@@ -3,9 +3,17 @@
        <sect1 id='config-bashrc-locations'>
                <title>bashrc locations</title>
                <para>
-               If a bashrc file is located at <filename>/etc/portage/bashrc</filename>
-               then it will be sourced before an ebuild is executed.
+               If one or more bashrc files exist in the following locations, they will
+               be sourced before the ebuild is executed in the following order:
                </para>
+               
+               <orderedlist>
+                       <listitem><para><filename>/etc/portage/bashrc</filename></para></listitem>
+                       <listitem><para><filename>/etc/portage/env/${CATEGORY}/${PN}</filename></para></listitem>
+                       <listitem><para><filename>/etc/portage/env/${CATEGORY}/${PN}:${SLOT}</filename></para></listitem>
+                       <listitem><para><filename>/etc/portage/env/${CATEGORY}/${P}</filename></para></listitem>
+                       <listitem><para><filename>/etc/portage/env/${CATEGORY}/${PF}</filename></para></listitem>
+               </orderedlist>
        </sect1>
        <sect1 id='config-bashrc-ebuild-phase-hooks'>
                <title>Ebuild Phase Hooks</title>
index fb354c2201e3ad8d72ec0dd7e6b05b36a2959aad..6c78cbd54a756cf17259fbf6d9b39d40433606fe 100644 (file)
@@ -59,6 +59,9 @@ package.use
 repos.conf
 .fi
 .TP
+.BR /etc/portage/env/
+package-specific bashrc files
+.TP
 .BR /etc/portage/profile/
 site-specific overrides of \fB/etc/make.profile/\fR
 .TP
@@ -407,6 +410,8 @@ it were a single file.
 If needed, this file can be used to set up a special environment for ebuilds,
 different from the standard root environment.  The syntax is the same as for
 any other bash script.
+
+Additional package-specific bashrc files can be created in /etc/portage/env.
 .TP
 .BR categories
 A simple list of valid categories that may be used in /usr/portage, 
@@ -616,6 +621,22 @@ masters = gentoo kde
 .fi
 .RE
 .TP
+.BR /etc/portage/env/
+.RS
+In this directory additional package-specific bashrc files can be created.
+Portage will source all of them after \fB/etc/portage/bashrc\fR in the following
+order:
+.nr step 1 1
+.IP \n[step]. 3
+/etc/portage/env/${CATEGORY}/${PN}
+.IP \n+[step].
+/etc/portage/env/${CATEGORY}/${PN}:${SLOT}
+.IP \n+[step].
+/etc/portage/env/${CATEGORY}/${P}
+.IP \n+[step].
+/etc/portage/env/${CATEGORY}/${PF}
+.RE
+.TP
 .BR /usr/portage/metadata/
 .RS
 .TP
index 2c5e233f18aaf8c485bed55770b683e88f93a668..445677bd9b3fae9163e549fa919e6901cafd39cb 100644 (file)
@@ -34,6 +34,7 @@ MODULES_FILE_PATH        = USER_CONFIG_PATH + "/modules"
 CUSTOM_PROFILE_PATH      = USER_CONFIG_PATH + "/profile"
 USER_VIRTUALS_FILE       = USER_CONFIG_PATH + "/virtuals"
 EBUILD_SH_ENV_FILE       = USER_CONFIG_PATH + "/bashrc"
+EBUILD_SH_ENV_DIR        = USER_CONFIG_PATH + "/env"
 CUSTOM_MIRRORS_FILE      = USER_CONFIG_PATH + "/mirrors"
 COLOR_MAP_FILE           = USER_CONFIG_PATH + "/color.map"
 PROFILE_PATH             = "etc/make.profile"
index dc7e1a857bc9a63287f68c2d3e29a0a36d07df22..db30c2c61b47c481da006db25f05d08e44ef038c 100644 (file)
@@ -172,7 +172,7 @@ class config(object):
                "PKGDIR",
                "PKGUSE", "PKG_LOGDIR", "PKG_TMPDIR",
                "PORTAGE_ACTUAL_DISTDIR", "PORTAGE_ARCHLIST",
-               "PORTAGE_BASHRC",
+               "PORTAGE_BASHRC", "PM_EBUILD_HOOK_DIR",
                "PORTAGE_BINPKG_FILE", "PORTAGE_BINPKG_TAR_OPTS",
                "PORTAGE_BINPKG_TMPFILE",
                "PORTAGE_BIN_PATH",
index 9cf16cfea8d48971adcdee3cd4bd8ea97536181e..531cb2386d38ef56bd9cad9aedab7208493300ea 100644 (file)
@@ -32,8 +32,8 @@ from portage import auxdbkeys, bsd_chflags, dep_check, \
        eapi_is_supported, merge, os, selinux, StringIO, \
        unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \
        _shell_quote, _split_ebuild_name_glep55, _unicode_decode, _unicode_encode
-from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, \
-       INVALID_ENV_FILE, MISC_SH_BINARY
+from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_ENV_DIR, \
+       EBUILD_SH_BINARY, INVALID_ENV_FILE, MISC_SH_BINARY
 from portage.data import portage_gid, portage_uid, secpass, \
        uid, userpriv_groups
 from portage.dbapi.virtual import fakedbapi
@@ -211,6 +211,8 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings,
 
        mysettings["PORTAGE_BASHRC"] = os.path.join(
                mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE)
+       mysettings["PM_EBUILD_HOOK_DIR"] = os.path.join(
+               mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_DIR)
        mysettings["EBUILD_EXIT_STATUS_FILE"] = os.path.join(
                mysettings["PORTAGE_BUILDDIR"], ".exit_status")