public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Bertrand SIMONNET <bsimonnet@chromium.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Bertrand SIMONNET <bsimonnet@chromium.org>
Subject: [gentoo-portage-dev] [PATCH 3/3] package.bashrc: per profile, per-package bashrc mechanism
Date: Mon, 29 Sep 2014 15:31:53 -0700	[thread overview]
Message-ID: <1412029913-13421-4-git-send-email-bsimonnet@chromium.org> (raw)
In-Reply-To: <1412029913-13421-3-git-send-email-bsimonnet@chromium.org>

Profiles can define per-package bashrc files to be sourced before emerging.
Each line in package.bashrc must be an atom name then a list of space-delimited
bashrc files (stored in $profile/bashrc/).
---
 bin/ebuild.sh                                      |  6 ++--
 bin/phase-functions.sh                             |  2 +-
 bin/save-ebuild-env.sh                             |  2 +-
 man/portage.5                                      | 30 +++++++++++++++++-
 .../package/ebuild/_config/special_env_vars.py     |  4 +--
 pym/portage/package/ebuild/config.py               | 36 ++++++++++++++++++++++
 pym/portage/package/ebuild/doebuild.py             |  4 ++-
 pym/portage/repository/config.py                   |  2 +-
 8 files changed, 76 insertions(+), 10 deletions(-)

diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 14cc321..50909e1 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -368,10 +368,10 @@ __source_all_bashrcs() {
 		# source the existing profile.bashrcs.
 		save_IFS
 		IFS=$'\n'
-		local path_array=($PROFILE_PATHS)
+		local bashenv_files=($PORTAGE_BASHRC_FILES)
 		restore_IFS
-		for x in "${path_array[@]}" ; do
-			[ -f "$x/profile.bashrc" ] && __qa_source "$x/profile.bashrc"
+		for x in "${bashenv_files[@]}" ; do
+			__try_source "${x}"
 		done
 	fi
 
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index f39a024..5dff3bb 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -31,7 +31,7 @@ PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
 	PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
 	PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTAGE_XATTR_EXCLUDE \
 	PORTDIR \
-	PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
+	REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
 	__PORTAGE_HELPER __PORTAGE_TEST_HARDLINK_LOCKS"
 
 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index f114c48..1a684b9 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -97,7 +97,7 @@ __save_ebuild_env() {
 		GOOD HILITE HOME \
 		LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
 		NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
-		PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
+		PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
 		PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
diff --git a/man/portage.5 b/man/portage.5
index e399f0f..309e259 100644
--- a/man/portage.5
+++ b/man/portage.5
@@ -24,6 +24,7 @@ make.defaults
 packages
 packages.build
 package.accept_keywords
+package.bashrc
 package.keywords
 package.mask
 package.provided
@@ -358,6 +359,31 @@ a '\-'.
 A list of packages (one per line) that make up a stage1 tarball.  Really only
 useful for stage builders.
 .TP
+.BR package.bashrc
+Per-package bashrc mechanism.  Contains a list of bashrc files to be sourced
+before emerging a given atom.  The bashrc files must be stored in bashrc/, in
+the profile directory.
+
+.I Note:
+.nf
+\- The bashrc files will be sourced after profile.bashrc for the same profile.
+\- profile-formats in metadata/layout.conf must contain profile-bashrcs for this
+to be enabled.
+.fi
+
+.I Format:
+.nf
+\- comments begin with # (no inline comments).
+\- one atom per line with space-delimited list of bashrc files.
+.fi
+
+.I Example:
+.nf
+# By setting INSTALL_MASK in bashrc/nostandardconf.conf, we can avoid installing
+# the standard configuration and enable another package to install it.
+net-misc/dhcp nostardardconf.conf
+.fi
+.TP
 .BR package.provided
 A list of packages (one per line) that portage should assume have been
 provided.  Useful for porting to non-Linux systems. Basically, it's a
@@ -1047,11 +1073,13 @@ The default setting for repoman's --echangelog option.
 The cache formats supported in the metadata tree.  There is the old "pms" format
 and the newer/faster "md5-dict" format.  Default is to detect dirs.
 .TP
-.BR profile\-formats " = [pms|portage-1|portage-2]"
+.BR profile\-formats " = [pms|portage-1|portage-2|profile-bashrcs]"
 Control functionality available to profiles in this repo such as which files
 may be dirs, or the syntax available in parent files.  Use "portage-2" if you're
 unsure.  The default is "portage-1-compat" mode which is meant to be compatible
 with old profiles, but is not allowed to be opted into directly.
+Setting profile-bashrcs will enable the per-profile bashrc mechanism
+\fBpackage.bashrc\fR.
 .RE
 .RE
 
diff --git a/pym/portage/package/ebuild/_config/special_env_vars.py b/pym/portage/package/ebuild/_config/special_env_vars.py
index 74fedd6..387f4ae 100644
--- a/pym/portage/package/ebuild/_config/special_env_vars.py
+++ b/pym/portage/package/ebuild/_config/special_env_vars.py
@@ -49,7 +49,7 @@ environ_whitelist += [
 	"FEATURES", "FILESDIR", "HOME", "MERGE_TYPE", "NOCOLOR", "PATH",
 	"PKGDIR",
 	"PKGUSE", "PKG_LOGDIR", "PKG_TMPDIR",
-	"PORTAGE_ACTUAL_DISTDIR", "PORTAGE_ARCHLIST",
+	"PORTAGE_ACTUAL_DISTDIR", "PORTAGE_ARCHLIST", "PORTAGE_BASHRC_FILES",
 	"PORTAGE_BASHRC", "PM_EBUILD_HOOK_DIR",
 	"PORTAGE_BINPKG_FILE", "PORTAGE_BINPKG_TAR_OPTS",
 	"PORTAGE_BINPKG_TMPFILE",
@@ -74,7 +74,7 @@ environ_whitelist += [
 	"PORTAGE_SIGPIPE_STATUS",
 	"PORTAGE_TMPDIR", "PORTAGE_UPDATE_ENV", "PORTAGE_USERNAME",
 	"PORTAGE_VERBOSE", "PORTAGE_WORKDIR_MODE", "PORTAGE_XATTR_EXCLUDE",
-	"PORTDIR", "PORTDIR_OVERLAY", "PREROOTPATH", "PROFILE_PATHS",
+	"PORTDIR", "PORTDIR_OVERLAY", "PREROOTPATH",
 	"REPLACING_VERSIONS", "REPLACED_BY_VERSION",
 	"ROOT", "ROOTPATH", "T", "TMP", "TMPDIR",
 	"USE_EXPAND", "USE_ORDER", "WORKDIR",
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
index f639e14..183627f 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -316,6 +316,7 @@ class config(object):
 			self._accept_restrict = copy.deepcopy(clone._accept_restrict)
 			self._paccept_restrict = copy.deepcopy(clone._paccept_restrict)
 			self._penvdict = copy.deepcopy(clone._penvdict)
+			self._pbashrcdict = copy.deepcopy(clone._pbashrcdict)
 			self._expand_map = copy.deepcopy(clone._expand_map)
 
 		else:
@@ -661,6 +662,7 @@ class config(object):
 			self._ppropertiesdict = portage.dep.ExtendedAtomDict(dict)
 			self._paccept_restrict = portage.dep.ExtendedAtomDict(dict)
 			self._penvdict = portage.dep.ExtendedAtomDict(dict)
+			self._pbashrcdict = {}
 
 			self._repo_make_defaults = {}
 			for repo in self.repositories.repos_with_profiles():
@@ -742,6 +744,25 @@ class config(object):
 				for k, v in penvdict.items():
 					self._penvdict.setdefault(k.cp, {})[k] = v
 
+				# package.bashrc
+				for profile in profiles_complex:
+					if not 'profile-bashrcs' in profile.profile_formats:
+						continue
+					self._pbashrcdict[profile] = \
+						portage.dep.ExtendedAtomDict(dict)
+					bashrc = grabdict_package(os.path.join(profile.location,
+						"package.bashrc"), recursive=1, allow_wildcard=True,
+								allow_repo=True, verify_eapi=False)
+					if not bashrc:
+						continue
+
+					for k, v in bashrc.items():
+						envfiles = [os.path.join(profile.location,
+							"bashrc",
+							envname) for envname in v]
+						self._pbashrcdict[profile].setdefault(k.cp, {})\
+							.setdefault(k, []).extend(envfiles)
+
 			#getting categories from an external file now
 			self.categories = [grabfile(os.path.join(x, "categories")) \
 				for x in locations_manager.profile_and_user_locations]
@@ -1501,6 +1522,21 @@ class config(object):
 				for x in penv_matches:
 					self._penv.extend(x)
 
+		bashrc_files = []
+
+		for profile in self._locations_manager.profiles_complex:
+			bashrc_files.append(os.path.join(profile.location,
+				'profile.bashrc'))
+			if profile in self._pbashrcdict:
+				cpdict = self._pbashrcdict[profile].get(cp)
+				if cpdict:
+					bashrc_matches = \
+						ordered_by_atom_specificity(cpdict, cpv_slot)
+					for x in bashrc_matches:
+						bashrc_files.extend(x)
+
+		self.configdict["BASHRC_FILES"] = bashrc_files
+
 		protected_pkg_keys = set(pkg_configdict)
 		protected_pkg_keys.discard('USE')
 
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
index 01707ae..5224775 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -335,7 +335,9 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
 	mysettings["ECLASSDIR"]   = mysettings["PORTDIR"]+"/eclass"
 	mysettings["SANDBOX_LOG"] = mycpv.replace("/", "_-_")
 
-	mysettings["PROFILE_PATHS"] = "\n".join(mysettings.profiles)
+	mysettings["PORTAGE_BASHRC_FILES"] = \
+		"\n".join(mysettings.configdict["BASHRC_FILES"])
+
 	mysettings["P"]  = mysplit[0]+"-"+mysplit[1]
 	mysettings["PN"] = mysplit[0]
 	mysettings["PV"] = mysplit[1]
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index 5e0d055..bef643d 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -40,7 +40,7 @@ if sys.hexversion >= 0x3000000:
 _invalid_path_char_re = re.compile(r'[^a-zA-Z0-9._\-+:/]')
 
 _valid_profile_formats = frozenset(
-	['pms', 'portage-1', 'portage-2'])
+	['pms', 'portage-1', 'portage-2', 'profile-bashrcs'])
 
 _portage1_profiles_allow_directories = frozenset(
 	["portage-1-compat", "portage-1", 'portage-2'])
-- 
2.1.0.rc2.206.gedb03e5



  reply	other threads:[~2014-09-30 21:59 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 11:18 [gentoo-portage-dev] [PATCH] per package environment: generalize the mechanism to be profile specific Bertrand Simonnet
2014-09-11 19:49 ` Zac Medico
2014-09-15 18:42   ` Bertrand Simonnet
2014-09-15 20:40     ` Zac Medico
2014-09-16 18:17       ` Bertrand Simonnet
2014-09-16 19:17         ` Zac Medico
2014-09-16 21:37           ` Bertrand Simonnet
2014-09-16 22:13             ` Zac Medico
2014-09-17  7:14               ` Alexander Berntsen
2014-09-17 18:02                 ` Zac Medico
2014-09-17 18:12                   ` Bertrand Simonnet
2014-09-17 20:36                     ` Zac Medico
2014-09-17 21:28             ` Michał Górny
2014-09-17 21:43               ` Zac Medico
2014-09-17 21:57                 ` Bertrand Simonnet
2014-09-17 23:46                   ` Bertrand Simonnet
2014-09-18  7:40                     ` Alexander Berntsen
2014-09-18  8:02                   ` Michał Górny
2014-09-18 17:54                     ` Bertrand Simonnet
2014-09-22 16:16                       ` Bertrand Simonnet
2014-09-22 18:16                         ` Zac Medico
2014-09-22 18:24                           ` Zac Medico
2014-09-22 18:43                             ` Bertrand Simonnet
2014-09-23  0:48                               ` Zac Medico
2014-09-23  0:57                                 ` Bertrand Simonnet
2014-09-24 16:05                                   ` Zac Medico
2014-09-26 16:22                                   ` Michał Górny
2014-09-26 16:28                                     ` Zac Medico
2014-09-29 22:31                                       ` Bertrand SIMONNET
2014-09-29 22:31                                         ` [gentoo-portage-dev] [PATCH 1/3] Refactor bashrc scripts sourcing Bertrand SIMONNET
2014-09-29 22:31                                           ` [gentoo-portage-dev] [PATCH 2/3] Add profile-formats to profile_complex Bertrand SIMONNET
2014-09-29 22:31                                             ` Bertrand SIMONNET [this message]
2014-09-30 22:16                                               ` [gentoo-portage-dev] Re: [PATCH 3/3] package.bashrc: per profile, per-package bashrc mechanism Bertrand Simonnet
2014-10-06 17:38                                                 ` Bertrand Simonnet
2014-10-06 18:57                                                   ` Zac Medico
2014-10-06 21:01                                                     ` Brian Dolbec
2014-10-07  0:15                                                       ` Bertrand Simonnet
2014-10-24  2:00                                                       ` Zac Medico
2014-10-24  7:25                                                         ` Alexander Berntsen
2014-10-24 20:57                                                           ` Zac Medico
2014-10-24 22:41                                                             ` Alexander Berntsen
2014-09-30  0:12                                       ` [gentoo-portage-dev] [PATCH] per package environment: generalize the mechanism to be profile specific Bertrand SIMONNET
2014-09-30  0:12                                         ` [gentoo-portage-dev] [PATCH 1/3] Refactor bashrc scripts sourcing Bertrand SIMONNET
2014-09-30  0:12                                           ` [gentoo-portage-dev] [PATCH 2/3] Add profile-formats to profile_complex Bertrand SIMONNET
2014-09-30  0:12                                             ` [gentoo-portage-dev] [PATCH 3/3] package.bashrc: per profile, per-package bashrc mechanism Bertrand SIMONNET
2014-09-30 15:19                                               ` Zac Medico
2014-09-30 16:45                                                 ` [gentoo-portage-dev] [PATCH] " Bertrand SIMONNET
2014-09-30 15:21                                         ` [gentoo-portage-dev] [PATCH] per package environment: generalize the mechanism to be profile specific Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412029913-13421-4-git-send-email-bsimonnet@chromium.org \
    --to=bsimonnet@chromium.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox