Gentoo Archives: gentoo-portage-dev

From: Bertrand SIMONNET <bsimonnet@××××××××.org>
To: gentoo-portage-dev@l.g.o
Cc: Bertrand SIMONNET <bsimonnet@××××××××.org>
Subject: [gentoo-portage-dev] [PATCH 3/3] package.bashrc: per profile, per-package bashrc mechanism
Date: Tue, 30 Sep 2014 00:13:08
Message-Id: 1412035957-32071-4-git-send-email-bsimonnet@chromium.org
In Reply to: [gentoo-portage-dev] [PATCH 2/3] Add profile-formats to profile_complex by Bertrand SIMONNET
1 Profiles can define per-package bashrc files to be sourced before emerging.
2 Each line in package.bashrc must be an atom name then a list of space-delimited
3 bashrc files (stored in $profile/bashrc/).
4 ---
5 bin/ebuild.sh | 6 ++--
6 bin/phase-functions.sh | 2 +-
7 bin/save-ebuild-env.sh | 2 +-
8 man/portage.5 | 30 +++++++++++++++++-
9 .../package/ebuild/_config/special_env_vars.py | 4 +--
10 pym/portage/package/ebuild/config.py | 36 ++++++++++++++++++++++
11 pym/portage/package/ebuild/doebuild.py | 4 ++-
12 pym/portage/repository/config.py | 2 +-
13 8 files changed, 76 insertions(+), 10 deletions(-)
14
15 diff --git a/bin/ebuild.sh b/bin/ebuild.sh
16 index 14cc321..50909e1 100755
17 --- a/bin/ebuild.sh
18 +++ b/bin/ebuild.sh
19 @@ -368,10 +368,10 @@ __source_all_bashrcs() {
20 # source the existing profile.bashrcs.
21 save_IFS
22 IFS=$'\n'
23 - local path_array=($PROFILE_PATHS)
24 + local bashenv_files=($PORTAGE_BASHRC_FILES)
25 restore_IFS
26 - for x in "${path_array[@]}" ; do
27 - [ -f "$x/profile.bashrc" ] && __qa_source "$x/profile.bashrc"
28 + for x in "${bashenv_files[@]}" ; do
29 + __try_source "${x}"
30 done
31 fi
32
33 diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
34 index f39a024..5dff3bb 100644
35 --- a/bin/phase-functions.sh
36 +++ b/bin/phase-functions.sh
37 @@ -31,7 +31,7 @@ PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
38 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
39 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTAGE_XATTR_EXCLUDE \
40 PORTDIR \
41 - PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
42 + REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
43 __PORTAGE_HELPER __PORTAGE_TEST_HARDLINK_LOCKS"
44
45 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
46 diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
47 index f114c48..1a684b9 100644
48 --- a/bin/save-ebuild-env.sh
49 +++ b/bin/save-ebuild-env.sh
50 @@ -97,7 +97,7 @@ __save_ebuild_env() {
51 GOOD HILITE HOME \
52 LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
53 NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
54 - PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
55 + PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED PORTAGE_COMPRESS \
56 PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
57 PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
58 PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
59 diff --git a/man/portage.5 b/man/portage.5
60 index e399f0f..309e259 100644
61 --- a/man/portage.5
62 +++ b/man/portage.5
63 @@ -24,6 +24,7 @@ make.defaults
64 packages
65 packages.build
66 package.accept_keywords
67 +package.bashrc
68 package.keywords
69 package.mask
70 package.provided
71 @@ -358,6 +359,31 @@ a '\-'.
72 A list of packages (one per line) that make up a stage1 tarball. Really only
73 useful for stage builders.
74 .TP
75 +.BR package.bashrc
76 +Per-package bashrc mechanism. Contains a list of bashrc files to be sourced
77 +before emerging a given atom. The bashrc files must be stored in bashrc/, in
78 +the profile directory.
79 +
80 +.I Note:
81 +.nf
82 +\- The bashrc files will be sourced after profile.bashrc for the same profile.
83 +\- profile-formats in metadata/layout.conf must contain profile-bashrcs for this
84 +to be enabled.
85 +.fi
86 +
87 +.I Format:
88 +.nf
89 +\- comments begin with # (no inline comments).
90 +\- one atom per line with space-delimited list of bashrc files.
91 +.fi
92 +
93 +.I Example:
94 +.nf
95 +# By setting INSTALL_MASK in bashrc/nostandardconf.conf, we can avoid installing
96 +# the standard configuration and enable another package to install it.
97 +net-misc/dhcp nostardardconf.conf
98 +.fi
99 +.TP
100 .BR package.provided
101 A list of packages (one per line) that portage should assume have been
102 provided. Useful for porting to non-Linux systems. Basically, it's a
103 @@ -1047,11 +1073,13 @@ The default setting for repoman's --echangelog option.
104 The cache formats supported in the metadata tree. There is the old "pms" format
105 and the newer/faster "md5-dict" format. Default is to detect dirs.
106 .TP
107 -.BR profile\-formats " = [pms|portage-1|portage-2]"
108 +.BR profile\-formats " = [pms|portage-1|portage-2|profile-bashrcs]"
109 Control functionality available to profiles in this repo such as which files
110 may be dirs, or the syntax available in parent files. Use "portage-2" if you're
111 unsure. The default is "portage-1-compat" mode which is meant to be compatible
112 with old profiles, but is not allowed to be opted into directly.
113 +Setting profile-bashrcs will enable the per-profile bashrc mechanism
114 +\fBpackage.bashrc\fR.
115 .RE
116 .RE
117
118 diff --git a/pym/portage/package/ebuild/_config/special_env_vars.py b/pym/portage/package/ebuild/_config/special_env_vars.py
119 index 74fedd6..387f4ae 100644
120 --- a/pym/portage/package/ebuild/_config/special_env_vars.py
121 +++ b/pym/portage/package/ebuild/_config/special_env_vars.py
122 @@ -49,7 +49,7 @@ environ_whitelist += [
123 "FEATURES", "FILESDIR", "HOME", "MERGE_TYPE", "NOCOLOR", "PATH",
124 "PKGDIR",
125 "PKGUSE", "PKG_LOGDIR", "PKG_TMPDIR",
126 - "PORTAGE_ACTUAL_DISTDIR", "PORTAGE_ARCHLIST",
127 + "PORTAGE_ACTUAL_DISTDIR", "PORTAGE_ARCHLIST", "PORTAGE_BASHRC_FILES",
128 "PORTAGE_BASHRC", "PM_EBUILD_HOOK_DIR",
129 "PORTAGE_BINPKG_FILE", "PORTAGE_BINPKG_TAR_OPTS",
130 "PORTAGE_BINPKG_TMPFILE",
131 @@ -74,7 +74,7 @@ environ_whitelist += [
132 "PORTAGE_SIGPIPE_STATUS",
133 "PORTAGE_TMPDIR", "PORTAGE_UPDATE_ENV", "PORTAGE_USERNAME",
134 "PORTAGE_VERBOSE", "PORTAGE_WORKDIR_MODE", "PORTAGE_XATTR_EXCLUDE",
135 - "PORTDIR", "PORTDIR_OVERLAY", "PREROOTPATH", "PROFILE_PATHS",
136 + "PORTDIR", "PORTDIR_OVERLAY", "PREROOTPATH",
137 "REPLACING_VERSIONS", "REPLACED_BY_VERSION",
138 "ROOT", "ROOTPATH", "T", "TMP", "TMPDIR",
139 "USE_EXPAND", "USE_ORDER", "WORKDIR",
140 diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
141 index f639e14..183627f 100644
142 --- a/pym/portage/package/ebuild/config.py
143 +++ b/pym/portage/package/ebuild/config.py
144 @@ -316,6 +316,7 @@ class config(object):
145 self._accept_restrict = copy.deepcopy(clone._accept_restrict)
146 self._paccept_restrict = copy.deepcopy(clone._paccept_restrict)
147 self._penvdict = copy.deepcopy(clone._penvdict)
148 + self._pbashrcdict = copy.deepcopy(clone._pbashrcdict)
149 self._expand_map = copy.deepcopy(clone._expand_map)
150
151 else:
152 @@ -661,6 +662,7 @@ class config(object):
153 self._ppropertiesdict = portage.dep.ExtendedAtomDict(dict)
154 self._paccept_restrict = portage.dep.ExtendedAtomDict(dict)
155 self._penvdict = portage.dep.ExtendedAtomDict(dict)
156 + self._pbashrcdict = {}
157
158 self._repo_make_defaults = {}
159 for repo in self.repositories.repos_with_profiles():
160 @@ -742,6 +744,25 @@ class config(object):
161 for k, v in penvdict.items():
162 self._penvdict.setdefault(k.cp, {})[k] = v
163
164 + # package.bashrc
165 + for profile in profiles_complex:
166 + if not 'profile-bashrcs' in profile.profile_formats:
167 + continue
168 + self._pbashrcdict[profile] = \
169 + portage.dep.ExtendedAtomDict(dict)
170 + bashrc = grabdict_package(os.path.join(profile.location,
171 + "package.bashrc"), recursive=1, allow_wildcard=True,
172 + allow_repo=True, verify_eapi=False)
173 + if not bashrc:
174 + continue
175 +
176 + for k, v in bashrc.items():
177 + envfiles = [os.path.join(profile.location,
178 + "bashrc",
179 + envname) for envname in v]
180 + self._pbashrcdict[profile].setdefault(k.cp, {})\
181 + .setdefault(k, []).extend(envfiles)
182 +
183 #getting categories from an external file now
184 self.categories = [grabfile(os.path.join(x, "categories")) \
185 for x in locations_manager.profile_and_user_locations]
186 @@ -1501,6 +1522,21 @@ class config(object):
187 for x in penv_matches:
188 self._penv.extend(x)
189
190 + bashrc_files = []
191 +
192 + for profile in self._locations_manager.profiles_complex:
193 + bashrc_files.append(os.path.join(profile.location,
194 + 'profile.bashrc'))
195 + if profile in self._pbashrcdict:
196 + cpdict = self._pbashrcdict[profile].get(cp)
197 + if cpdict:
198 + bashrc_matches = \
199 + ordered_by_atom_specificity(cpdict, cpv_slot)
200 + for x in bashrc_matches:
201 + bashrc_files.extend(x)
202 +
203 + self.configdict["BASHRC_FILES"] = bashrc_files
204 +
205 protected_pkg_keys = set(pkg_configdict)
206 protected_pkg_keys.discard('USE')
207
208 diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
209 index 01707ae..5224775 100644
210 --- a/pym/portage/package/ebuild/doebuild.py
211 +++ b/pym/portage/package/ebuild/doebuild.py
212 @@ -335,7 +335,9 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
213 mysettings["ECLASSDIR"] = mysettings["PORTDIR"]+"/eclass"
214 mysettings["SANDBOX_LOG"] = mycpv.replace("/", "_-_")
215
216 - mysettings["PROFILE_PATHS"] = "\n".join(mysettings.profiles)
217 + mysettings["PORTAGE_BASHRC_FILES"] = \
218 + "\n".join(mysettings.configdict["BASHRC_FILES"])
219 +
220 mysettings["P"] = mysplit[0]+"-"+mysplit[1]
221 mysettings["PN"] = mysplit[0]
222 mysettings["PV"] = mysplit[1]
223 diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
224 index 5e0d055..bef643d 100644
225 --- a/pym/portage/repository/config.py
226 +++ b/pym/portage/repository/config.py
227 @@ -40,7 +40,7 @@ if sys.hexversion >= 0x3000000:
228 _invalid_path_char_re = re.compile(r'[^a-zA-Z0-9._\-+:/]')
229
230 _valid_profile_formats = frozenset(
231 - ['pms', 'portage-1', 'portage-2'])
232 + ['pms', 'portage-1', 'portage-2', 'profile-bashrcs'])
233
234 _portage1_profiles_allow_directories = frozenset(
235 ["portage-1-compat", "portage-1", 'portage-2'])
236 --
237 2.1.0.rc2.206.gedb03e5

Replies