1 |
Author: grobian |
2 |
Date: 2010-02-27 18:53:28 +0000 (Sat, 27 Feb 2010) |
3 |
New Revision: 15479 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/portage/__init__.py |
7 |
main/branches/prefix/pym/portage/package/ebuild/doebuild.py |
8 |
main/branches/prefix/pym/portage/package/ebuild/prepare_build_dirs.py |
9 |
Log: |
10 |
resolve all merge conflicts |
11 |
|
12 |
Modified: main/branches/prefix/pym/portage/__init__.py |
13 |
=================================================================== |
14 |
--- main/branches/prefix/pym/portage/__init__.py 2010-02-27 18:30:51 UTC (rev 15478) |
15 |
+++ main/branches/prefix/pym/portage/__init__.py 2010-02-27 18:53:28 UTC (rev 15479) |
16 |
@@ -1017,188 +1017,6 @@ |
17 |
|
18 |
return (version,None) |
19 |
|
20 |
-<<<<<<< .working |
21 |
- |
22 |
- |
23 |
- |
24 |
-def _can_test_pty_eof(): |
25 |
- """ |
26 |
- The _test_pty_eof() function seems to hang on most |
27 |
- kernels other than Linux. |
28 |
- This was reported for the following kernels which used to work fine |
29 |
- without this EOF test: Darwin, AIX, FreeBSD. They seem to hang on |
30 |
- the slave_file.close() call. Note that Python's implementation of |
31 |
- openpty on Solaris already caused random hangs without this EOF test |
32 |
- and hence is globally disabled. |
33 |
- @rtype: bool |
34 |
- @returns: True if _test_pty_eof() won't hang, False otherwise. |
35 |
- """ |
36 |
- return platform.system() in ("Linux",) |
37 |
- |
38 |
-def _test_pty_eof(): |
39 |
- """ |
40 |
- Returns True if this issues is fixed for the currently |
41 |
- running version of python: http://bugs.python.org/issue5380 |
42 |
- Raises an EnvironmentError from openpty() if it fails. |
43 |
- """ |
44 |
- |
45 |
- use_fork = False |
46 |
- |
47 |
- import array, fcntl, pty, select, termios |
48 |
- test_string = 2 * "blah blah blah\n" |
49 |
- test_string = _unicode_decode(test_string, |
50 |
- encoding='utf_8', errors='strict') |
51 |
- |
52 |
- # may raise EnvironmentError |
53 |
- master_fd, slave_fd = pty.openpty() |
54 |
- |
55 |
- # Non-blocking mode is required for Darwin kernel. |
56 |
- fcntl.fcntl(master_fd, fcntl.F_SETFL, |
57 |
- fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK) |
58 |
- |
59 |
- # Disable post-processing of output since otherwise weird |
60 |
- # things like \n -> \r\n transformations may occur. |
61 |
- mode = termios.tcgetattr(slave_fd) |
62 |
- mode[1] &= ~termios.OPOST |
63 |
- termios.tcsetattr(slave_fd, termios.TCSANOW, mode) |
64 |
- |
65 |
- # Simulate a subprocess writing some data to the |
66 |
- # slave end of the pipe, and then exiting. |
67 |
- pid = None |
68 |
- if use_fork: |
69 |
- pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, |
70 |
- encoding='utf_8', errors='strict'), env=os.environ, |
71 |
- fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, |
72 |
- returnpid=True) |
73 |
- if isinstance(pids, int): |
74 |
- os.close(master_fd) |
75 |
- os.close(slave_fd) |
76 |
- raise EnvironmentError('spawn failed') |
77 |
- pid = pids[0] |
78 |
- else: |
79 |
- os.write(slave_fd, _unicode_encode(test_string, |
80 |
- encoding='utf_8', errors='strict')) |
81 |
- os.close(slave_fd) |
82 |
- |
83 |
- # If using a fork, we must wait for the child here, |
84 |
- # in order to avoid a race condition that would |
85 |
- # lead to inconsistent results. |
86 |
- if pid is not None: |
87 |
- os.waitpid(pid, 0) |
88 |
- |
89 |
- master_file = os.fdopen(master_fd, 'rb') |
90 |
- eof = False |
91 |
- data = [] |
92 |
- iwtd = [master_file] |
93 |
- owtd = [] |
94 |
- ewtd = [] |
95 |
- |
96 |
- while not eof: |
97 |
- |
98 |
- events = select.select(iwtd, owtd, ewtd) |
99 |
- if not events[0]: |
100 |
- eof = True |
101 |
- break |
102 |
- |
103 |
- buf = array.array('B') |
104 |
- try: |
105 |
- buf.fromfile(master_file, 1024) |
106 |
- except EOFError: |
107 |
- eof = True |
108 |
- except IOError: |
109 |
- # This is where data loss occurs. |
110 |
- eof = True |
111 |
- |
112 |
- if not buf: |
113 |
- eof = True |
114 |
- else: |
115 |
- data.append(_unicode_decode(buf.tostring(), |
116 |
- encoding='utf_8', errors='strict')) |
117 |
- |
118 |
- master_file.close() |
119 |
- |
120 |
- return test_string == ''.join(data) |
121 |
- |
122 |
-# If _test_pty_eof() can't be used for runtime detection of |
123 |
-# http://bugs.python.org/issue5380, openpty can't safely be used |
124 |
-# unless we can guarantee that the current version of python has |
125 |
-# been fixed (affects all current versions of python3). When |
126 |
-# this issue is fixed in python3, we can add another sys.hexversion |
127 |
-# conditional to enable openpty support in the fixed versions. |
128 |
-if sys.hexversion >= 0x3000000 and not _can_test_pty_eof(): |
129 |
- _disable_openpty = True |
130 |
-else: |
131 |
- # Disable the use of openpty on Solaris as it seems Python's openpty |
132 |
- # implementation doesn't play nice on Solaris with Portage's |
133 |
- # behaviour causing hangs/deadlocks. |
134 |
- # Additional note for the future: on Interix, pipes do NOT work, so |
135 |
- # _disable_openpty on Interix must *never* be True |
136 |
- _disable_openpty = platform.system() in ("SunOS",) |
137 |
-_tested_pty = False |
138 |
- |
139 |
-if not _can_test_pty_eof(): |
140 |
- # Skip _test_pty_eof() on systems where it hangs. |
141 |
- _tested_pty = True |
142 |
- |
143 |
-def _create_pty_or_pipe(copy_term_size=None): |
144 |
- """ |
145 |
- Try to create a pty and if then fails then create a normal |
146 |
- pipe instead. |
147 |
- |
148 |
- @param copy_term_size: If a tty file descriptor is given |
149 |
- then the term size will be copied to the pty. |
150 |
- @type copy_term_size: int |
151 |
- @rtype: tuple |
152 |
- @returns: A tuple of (is_pty, master_fd, slave_fd) where |
153 |
- is_pty is True if a pty was successfully allocated, and |
154 |
- False if a normal pipe was allocated. |
155 |
- """ |
156 |
- |
157 |
- got_pty = False |
158 |
- |
159 |
- global _disable_openpty, _tested_pty |
160 |
- if not (_tested_pty or _disable_openpty): |
161 |
- try: |
162 |
- if not _test_pty_eof(): |
163 |
- _disable_openpty = True |
164 |
- except EnvironmentError as e: |
165 |
- _disable_openpty = True |
166 |
- writemsg("openpty failed: '%s'\n" % str(e), |
167 |
- noiselevel=-1) |
168 |
- del e |
169 |
- _tested_pty = True |
170 |
- |
171 |
- if _disable_openpty: |
172 |
- master_fd, slave_fd = os.pipe() |
173 |
- else: |
174 |
- from pty import openpty |
175 |
- try: |
176 |
- master_fd, slave_fd = openpty() |
177 |
- got_pty = True |
178 |
- except EnvironmentError as e: |
179 |
- _disable_openpty = True |
180 |
- writemsg("openpty failed: '%s'\n" % str(e), |
181 |
- noiselevel=-1) |
182 |
- del e |
183 |
- master_fd, slave_fd = os.pipe() |
184 |
- |
185 |
- if got_pty: |
186 |
- # Disable post-processing of output since otherwise weird |
187 |
- # things like \n -> \r\n transformations may occur. |
188 |
- import termios |
189 |
- mode = termios.tcgetattr(slave_fd) |
190 |
- mode[1] &= ~termios.OPOST |
191 |
- termios.tcsetattr(slave_fd, termios.TCSANOW, mode) |
192 |
- |
193 |
- if got_pty and \ |
194 |
- copy_term_size is not None and \ |
195 |
- os.isatty(copy_term_size): |
196 |
- from portage.output import get_term_size, set_term_size |
197 |
- rows, columns = get_term_size() |
198 |
- set_term_size(rows, columns, slave_fd) |
199 |
- |
200 |
- return (got_pty, master_fd, slave_fd) |
201 |
- |
202 |
# XXX This would be to replace getstatusoutput completely. |
203 |
# XXX Issue: cannot block execution. Deadlock condition. |
204 |
def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakeroot=0, **keywords): |
205 |
@@ -1810,1335 +1628,6 @@ |
206 |
return (None, None) |
207 |
return (m.group(1), m.group(3)) |
208 |
|
209 |
-<<<<<<< .working |
210 |
-def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, mydbapi): |
211 |
- |
212 |
- ebuild_path = os.path.abspath(myebuild) |
213 |
- pkg_dir = os.path.dirname(ebuild_path) |
214 |
- |
215 |
- if "CATEGORY" in mysettings.configdict["pkg"]: |
216 |
- cat = mysettings.configdict["pkg"]["CATEGORY"] |
217 |
- else: |
218 |
- cat = os.path.basename(normalize_path(os.path.join(pkg_dir, ".."))) |
219 |
- |
220 |
- eapi = None |
221 |
- if 'parse-eapi-glep-55' in mysettings.features: |
222 |
- mypv, eapi = portage._split_ebuild_name_glep55( |
223 |
- os.path.basename(myebuild)) |
224 |
- else: |
225 |
- mypv = os.path.basename(ebuild_path)[:-7] |
226 |
- |
227 |
- mycpv = cat+"/"+mypv |
228 |
- mysplit = versions._pkgsplit(mypv) |
229 |
- if mysplit is None: |
230 |
- raise portage.exception.IncorrectParameter( |
231 |
- _("Invalid ebuild path: '%s'") % myebuild) |
232 |
- |
233 |
- # Make a backup of PORTAGE_TMPDIR prior to calling config.reset() |
234 |
- # so that the caller can override it. |
235 |
- tmpdir = mysettings["PORTAGE_TMPDIR"] |
236 |
- |
237 |
- if mydo == 'depend': |
238 |
- if mycpv != mysettings.mycpv: |
239 |
- # Don't pass in mydbapi here since the resulting aux_get |
240 |
- # call would lead to infinite 'depend' phase recursion. |
241 |
- mysettings.setcpv(mycpv) |
242 |
- else: |
243 |
- # If IUSE isn't in configdict['pkg'], it means that setcpv() |
244 |
- # hasn't been called with the mydb argument, so we have to |
245 |
- # call it here (portage code always calls setcpv properly, |
246 |
- # but api consumers might not). |
247 |
- if mycpv != mysettings.mycpv or \ |
248 |
- 'IUSE' not in mysettings.configdict['pkg']: |
249 |
- # Reload env.d variables and reset any previous settings. |
250 |
- mysettings.reload() |
251 |
- mysettings.reset() |
252 |
- mysettings.setcpv(mycpv, mydb=mydbapi) |
253 |
- |
254 |
- # config.reset() might have reverted a change made by the caller, |
255 |
- # so restore it to it's original value. |
256 |
- mysettings["PORTAGE_TMPDIR"] = tmpdir |
257 |
- |
258 |
- mysettings.pop("EBUILD_PHASE", None) # remove from backupenv |
259 |
- mysettings["EBUILD_PHASE"] = mydo |
260 |
- |
261 |
- mysettings["PORTAGE_MASTER_PID"] = str(os.getpid()) |
262 |
- |
263 |
- # We are disabling user-specific bashrc files. |
264 |
- mysettings["BASH_ENV"] = INVALID_ENV_FILE |
265 |
- |
266 |
- if debug: # Otherwise it overrides emerge's settings. |
267 |
- # We have no other way to set debug... debug can't be passed in |
268 |
- # due to how it's coded... Don't overwrite this so we can use it. |
269 |
- mysettings["PORTAGE_DEBUG"] = "1" |
270 |
- |
271 |
- mysettings["EPREFIX"] = EPREFIX.rstrip(os.path.sep) |
272 |
- mysettings["EBUILD"] = ebuild_path |
273 |
- mysettings["O"] = pkg_dir |
274 |
- mysettings.configdict["pkg"]["CATEGORY"] = cat |
275 |
- mysettings["FILESDIR"] = os.path.join(pkg_dir, "files") |
276 |
- mysettings["PF"] = mypv |
277 |
- |
278 |
- if hasattr(mydbapi, '_repo_info'): |
279 |
- mytree = os.path.dirname(os.path.dirname(pkg_dir)) |
280 |
- repo_info = mydbapi._repo_info[mytree] |
281 |
- mysettings['PORTDIR'] = repo_info.portdir |
282 |
- mysettings['PORTDIR_OVERLAY'] = repo_info.portdir_overlay |
283 |
- |
284 |
- mysettings["PORTDIR"] = os.path.realpath(mysettings["PORTDIR"]) |
285 |
- mysettings["DISTDIR"] = os.path.realpath(mysettings["DISTDIR"]) |
286 |
- mysettings["RPMDIR"] = os.path.realpath(mysettings["RPMDIR"]) |
287 |
- |
288 |
- mysettings["ECLASSDIR"] = mysettings["PORTDIR"]+"/eclass" |
289 |
- mysettings["SANDBOX_LOG"] = mycpv.replace("/", "_-_") |
290 |
- |
291 |
- mysettings["PROFILE_PATHS"] = "\n".join(mysettings.profiles) |
292 |
- mysettings["P"] = mysplit[0]+"-"+mysplit[1] |
293 |
- mysettings["PN"] = mysplit[0] |
294 |
- mysettings["PV"] = mysplit[1] |
295 |
- mysettings["PR"] = mysplit[2] |
296 |
- |
297 |
- if portage.util.noiselimit < 0: |
298 |
- mysettings["PORTAGE_QUIET"] = "1" |
299 |
- |
300 |
- if mydo == 'depend' and \ |
301 |
- 'EAPI' not in mysettings.configdict['pkg']: |
302 |
- |
303 |
- if eapi is not None: |
304 |
- # From parse-eapi-glep-55 above. |
305 |
- pass |
306 |
- elif 'parse-eapi-ebuild-head' in mysettings.features: |
307 |
- eapi = _parse_eapi_ebuild_head( |
308 |
- codecs.open(_unicode_encode(ebuild_path, |
309 |
- encoding=_encodings['fs'], errors='strict'), |
310 |
- mode='r', encoding=_encodings['content'], errors='replace')) |
311 |
- |
312 |
- if eapi is not None: |
313 |
- if not eapi_is_supported(eapi): |
314 |
- raise portage.exception.UnsupportedAPIException(mycpv, eapi) |
315 |
- mysettings.configdict['pkg']['EAPI'] = eapi |
316 |
- |
317 |
- if mydo != "depend": |
318 |
- # Metadata vars such as EAPI and RESTRICT are |
319 |
- # set by the above config.setcpv() call. |
320 |
- eapi = mysettings["EAPI"] |
321 |
- if not eapi_is_supported(eapi): |
322 |
- # can't do anything with this. |
323 |
- raise portage.exception.UnsupportedAPIException(mycpv, eapi) |
324 |
- |
325 |
- if mysplit[2] == "r0": |
326 |
- mysettings["PVR"]=mysplit[1] |
327 |
- else: |
328 |
- mysettings["PVR"]=mysplit[1]+"-"+mysplit[2] |
329 |
- |
330 |
- if "PATH" in mysettings: |
331 |
- mysplit=mysettings["PATH"].split(":") |
332 |
- else: |
333 |
- mysplit=[] |
334 |
- # Note: PORTAGE_BIN_PATH may differ from the global constant |
335 |
- # when portage is reinstalling itself. |
336 |
- portage_bin_path = mysettings["PORTAGE_BIN_PATH"] |
337 |
- if portage_bin_path not in mysplit: |
338 |
- mysettings["PATH"] = portage_bin_path + ":" + mysettings["PATH"] |
339 |
- |
340 |
- # Sandbox needs cannonical paths. |
341 |
- mysettings["PORTAGE_TMPDIR"] = os.path.realpath( |
342 |
- mysettings["PORTAGE_TMPDIR"]) |
343 |
- mysettings["BUILD_PREFIX"] = os.path.join(mysettings["PORTAGE_TMPDIR"], "portage") |
344 |
- mysettings["PKG_TMPDIR"] = os.path.join(mysettings["PORTAGE_TMPDIR"], "binpkgs") |
345 |
- |
346 |
- # Package {pre,post}inst and {pre,post}rm may overlap, so they must have separate |
347 |
- # locations in order to prevent interference. |
348 |
- if mydo in ("unmerge", "prerm", "postrm", "cleanrm"): |
349 |
- mysettings["PORTAGE_BUILDDIR"] = os.path.join( |
350 |
- mysettings["PKG_TMPDIR"], |
351 |
- mysettings["CATEGORY"], mysettings["PF"]) |
352 |
- else: |
353 |
- mysettings["PORTAGE_BUILDDIR"] = os.path.join( |
354 |
- mysettings["BUILD_PREFIX"], |
355 |
- mysettings["CATEGORY"], mysettings["PF"]) |
356 |
- |
357 |
- mysettings["HOME"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "homedir") |
358 |
- mysettings["WORKDIR"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "work") |
359 |
- mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep |
360 |
- mysettings["ED"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image" + mysettings["EPREFIX"]) + os.sep |
361 |
- mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp") |
362 |
- |
363 |
- mysettings["PORTAGE_BASHRC"] = os.path.join( |
364 |
- mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE) |
365 |
- mysettings["EBUILD_EXIT_STATUS_FILE"] = os.path.join( |
366 |
- mysettings["PORTAGE_BUILDDIR"], ".exit_status") |
367 |
- |
368 |
- #set up KV variable -- DEP SPEEDUP :: Don't waste time. Keep var persistent. |
369 |
- if eapi not in ('0', '1', '2', '3', '3_pre2'): |
370 |
- # Discard KV for EAPIs that don't support it. Cache KV is restored |
371 |
- # from the backupenv whenever config.reset() is called. |
372 |
- mysettings.pop('KV', None) |
373 |
- elif mydo != 'depend' and 'KV' not in mysettings and \ |
374 |
- mydo in ('compile', 'config', 'configure', 'info', |
375 |
- 'install', 'nofetch', 'postinst', 'postrm', 'preinst', |
376 |
- 'prepare', 'prerm', 'setup', 'test', 'unpack'): |
377 |
- mykv,err1=ExtractKernelVersion(os.path.join(myroot, EPREFIX_LSTRIP, "usr/src/linux")) |
378 |
- if mykv: |
379 |
- # Regular source tree |
380 |
- mysettings["KV"]=mykv |
381 |
- else: |
382 |
- mysettings["KV"]="" |
383 |
- mysettings.backup_changes("KV") |
384 |
- |
385 |
- # Allow color.map to control colors associated with einfo, ewarn, etc... |
386 |
- mycolors = [] |
387 |
- for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET"): |
388 |
- mycolors.append("%s=$'%s'" % \ |
389 |
- (c, portage.output.style_to_ansi_code(c))) |
390 |
- mysettings["PORTAGE_COLORMAP"] = "\n".join(mycolors) |
391 |
- |
392 |
-def prepare_build_dirs(myroot, mysettings, cleanup): |
393 |
- |
394 |
- clean_dirs = [mysettings["HOME"]] |
395 |
- |
396 |
- # We enable cleanup when we want to make sure old cruft (such as the old |
397 |
- # environment) doesn't interfere with the current phase. |
398 |
- if cleanup: |
399 |
- clean_dirs.append(mysettings["T"]) |
400 |
- |
401 |
- for clean_dir in clean_dirs: |
402 |
- try: |
403 |
- shutil.rmtree(clean_dir) |
404 |
- except OSError as oe: |
405 |
- if errno.ENOENT == oe.errno: |
406 |
- pass |
407 |
- elif errno.EPERM == oe.errno: |
408 |
- writemsg("%s\n" % oe, noiselevel=-1) |
409 |
- writemsg(_("Operation Not Permitted: rmtree('%s')\n") % \ |
410 |
- clean_dir, noiselevel=-1) |
411 |
- return 1 |
412 |
- else: |
413 |
- raise |
414 |
- |
415 |
- def makedirs(dir_path): |
416 |
- try: |
417 |
- os.makedirs(dir_path) |
418 |
- except OSError as oe: |
419 |
- if errno.EEXIST == oe.errno: |
420 |
- pass |
421 |
- elif errno.EPERM == oe.errno: |
422 |
- writemsg("%s\n" % oe, noiselevel=-1) |
423 |
- writemsg(_("Operation Not Permitted: makedirs('%s')\n") % \ |
424 |
- dir_path, noiselevel=-1) |
425 |
- return False |
426 |
- else: |
427 |
- raise |
428 |
- return True |
429 |
- |
430 |
- mysettings["PKG_LOGDIR"] = os.path.join(mysettings["T"], "logging") |
431 |
- |
432 |
- mydirs = [os.path.dirname(mysettings["PORTAGE_BUILDDIR"])] |
433 |
- mydirs.append(os.path.dirname(mydirs[-1])) |
434 |
- |
435 |
- try: |
436 |
- for mydir in mydirs: |
437 |
- portage.util.ensure_dirs(mydir) |
438 |
- portage.util.apply_secpass_permissions(mydir, |
439 |
- gid=portage_gid, uid=portage_uid, mode=0o70, mask=0) |
440 |
- for dir_key in ("PORTAGE_BUILDDIR", "HOME", "PKG_LOGDIR", "T"): |
441 |
- """These directories don't necessarily need to be group writable. |
442 |
- However, the setup phase is commonly run as a privileged user prior |
443 |
- to the other phases being run by an unprivileged user. Currently, |
444 |
- we use the portage group to ensure that the unprivleged user still |
445 |
- has write access to these directories in any case.""" |
446 |
- portage.util.ensure_dirs(mysettings[dir_key], mode=0o775) |
447 |
- portage.util.apply_secpass_permissions(mysettings[dir_key], |
448 |
- uid=portage_uid, gid=portage_gid) |
449 |
- except portage.exception.PermissionDenied as e: |
450 |
- writemsg(_("Permission Denied: %s\n") % str(e), noiselevel=-1) |
451 |
- return 1 |
452 |
- except portage.exception.OperationNotPermitted as e: |
453 |
- writemsg(_("Operation Not Permitted: %s\n") % str(e), noiselevel=-1) |
454 |
- return 1 |
455 |
- except portage.exception.FileNotFound as e: |
456 |
- writemsg(_("File Not Found: '%s'\n") % str(e), noiselevel=-1) |
457 |
- return 1 |
458 |
- |
459 |
- # Reset state for things like noauto and keepwork in FEATURES. |
460 |
- for x in ('.die_hooks',): |
461 |
- try: |
462 |
- os.unlink(os.path.join(mysettings['PORTAGE_BUILDDIR'], x)) |
463 |
- except OSError: |
464 |
- pass |
465 |
- |
466 |
- _prepare_workdir(mysettings) |
467 |
- if mysettings.get('EBUILD_PHASE') != 'fetch': |
468 |
- # Avoid spurious permissions adjustments when fetching with |
469 |
- # a temporary PORTAGE_TMPDIR setting (for fetchonly). |
470 |
- _prepare_features_dirs(mysettings) |
471 |
- |
472 |
-def _adjust_perms_msg(settings, msg): |
473 |
- |
474 |
- def write(msg): |
475 |
- writemsg(msg, noiselevel=-1) |
476 |
- |
477 |
- background = settings.get("PORTAGE_BACKGROUND") == "1" |
478 |
- log_path = settings.get("PORTAGE_LOG_FILE") |
479 |
- log_file = None |
480 |
- |
481 |
- if background and log_path is not None: |
482 |
- try: |
483 |
- log_file = codecs.open(_unicode_encode(log_path, |
484 |
- encoding=_encodings['fs'], errors='strict'), |
485 |
- mode='a', encoding=_encodings['content'], errors='replace') |
486 |
- except IOError: |
487 |
- def write(msg): |
488 |
- pass |
489 |
- else: |
490 |
- def write(msg): |
491 |
- log_file.write(_unicode_decode(msg)) |
492 |
- log_file.flush() |
493 |
- |
494 |
- try: |
495 |
- write(msg) |
496 |
- finally: |
497 |
- if log_file is not None: |
498 |
- log_file.close() |
499 |
- |
500 |
-def _prepare_features_dirs(mysettings): |
501 |
- |
502 |
- features_dirs = { |
503 |
- "ccache":{ |
504 |
- "path_dir": EPREFIX+"/usr/lib/ccache/bin", |
505 |
- "basedir_var":"CCACHE_DIR", |
506 |
- "default_dir":os.path.join(mysettings["PORTAGE_TMPDIR"], "ccache"), |
507 |
- "always_recurse":False}, |
508 |
- "distcc":{ |
509 |
- "path_dir": EPREFIX+"/usr/lib/distcc/bin", |
510 |
- "basedir_var":"DISTCC_DIR", |
511 |
- "default_dir":os.path.join(mysettings["BUILD_PREFIX"], ".distcc"), |
512 |
- "subdirs":("lock", "state"), |
513 |
- "always_recurse":True} |
514 |
- } |
515 |
- dirmode = 0o2070 |
516 |
- filemode = 0o60 |
517 |
- modemask = 0o2 |
518 |
- restrict = mysettings.get("PORTAGE_RESTRICT","").split() |
519 |
- from portage.data import secpass |
520 |
- droppriv = secpass >= 2 and \ |
521 |
- "userpriv" in mysettings.features and \ |
522 |
- "userpriv" not in restrict |
523 |
- for myfeature, kwargs in features_dirs.items(): |
524 |
- if myfeature in mysettings.features: |
525 |
- failure = False |
526 |
- basedir = mysettings.get(kwargs["basedir_var"]) |
527 |
- if basedir is None or not basedir.strip(): |
528 |
- basedir = kwargs["default_dir"] |
529 |
- mysettings[kwargs["basedir_var"]] = basedir |
530 |
- try: |
531 |
- path_dir = kwargs["path_dir"] |
532 |
- if not os.path.isdir(path_dir): |
533 |
- raise portage.exception.DirectoryNotFound(path_dir) |
534 |
- |
535 |
- mydirs = [mysettings[kwargs["basedir_var"]]] |
536 |
- if "subdirs" in kwargs: |
537 |
- for subdir in kwargs["subdirs"]: |
538 |
- mydirs.append(os.path.join(basedir, subdir)) |
539 |
- for mydir in mydirs: |
540 |
- modified = portage.util.ensure_dirs(mydir) |
541 |
- # Generally, we only want to apply permissions for |
542 |
- # initial creation. Otherwise, we don't know exactly what |
543 |
- # permissions the user wants, so should leave them as-is. |
544 |
- droppriv_fix = False |
545 |
- if droppriv: |
546 |
- st = os.stat(mydir) |
547 |
- if st.st_gid != portage_gid or \ |
548 |
- not dirmode == (stat.S_IMODE(st.st_mode) & dirmode): |
549 |
- droppriv_fix = True |
550 |
- if not droppriv_fix: |
551 |
- # Check permissions of files in the directory. |
552 |
- for filename in os.listdir(mydir): |
553 |
- try: |
554 |
- subdir_st = os.lstat( |
555 |
- os.path.join(mydir, filename)) |
556 |
- except OSError: |
557 |
- continue |
558 |
- if subdir_st.st_gid != portage_gid or \ |
559 |
- ((stat.S_ISDIR(subdir_st.st_mode) and \ |
560 |
- not dirmode == (stat.S_IMODE(subdir_st.st_mode) & dirmode))): |
561 |
- droppriv_fix = True |
562 |
- break |
563 |
- |
564 |
- if droppriv_fix: |
565 |
- _adjust_perms_msg(mysettings, |
566 |
- colorize("WARN", " * ") + \ |
567 |
- _("Adjusting permissions " |
568 |
- "for FEATURES=userpriv: '%s'\n") % mydir) |
569 |
- elif modified: |
570 |
- _adjust_perms_msg(mysettings, |
571 |
- colorize("WARN", " * ") + \ |
572 |
- _("Adjusting permissions " |
573 |
- "for FEATURES=%s: '%s'\n") % (myfeature, mydir)) |
574 |
- |
575 |
- if modified or kwargs["always_recurse"] or droppriv_fix: |
576 |
- def onerror(e): |
577 |
- raise # The feature is disabled if a single error |
578 |
- # occurs during permissions adjustment. |
579 |
- if not apply_recursive_permissions(mydir, |
580 |
- gid=portage_gid, dirmode=dirmode, dirmask=modemask, |
581 |
- filemode=filemode, filemask=modemask, onerror=onerror): |
582 |
- raise portage.exception.OperationNotPermitted( |
583 |
- _("Failed to apply recursive permissions for the portage group.")) |
584 |
- |
585 |
- except portage.exception.DirectoryNotFound as e: |
586 |
- failure = True |
587 |
- writemsg(_("\n!!! Directory does not exist: '%s'\n") % \ |
588 |
- (e,), noiselevel=-1) |
589 |
- writemsg(_("!!! Disabled FEATURES='%s'\n") % myfeature, |
590 |
- noiselevel=-1) |
591 |
- |
592 |
- except portage.exception.PortageException as e: |
593 |
- failure = True |
594 |
- writemsg("\n!!! %s\n" % str(e), noiselevel=-1) |
595 |
- writemsg(_("!!! Failed resetting perms on %s='%s'\n") % \ |
596 |
- (kwargs["basedir_var"], basedir), noiselevel=-1) |
597 |
- writemsg(_("!!! Disabled FEATURES='%s'\n") % myfeature, |
598 |
- noiselevel=-1) |
599 |
- |
600 |
- if failure: |
601 |
- mysettings.features.remove(myfeature) |
602 |
- mysettings['FEATURES'] = ' '.join(sorted(mysettings.features)) |
603 |
- time.sleep(5) |
604 |
- |
605 |
-def _prepare_workdir(mysettings): |
606 |
- workdir_mode = 0o700 |
607 |
- try: |
608 |
- mode = mysettings["PORTAGE_WORKDIR_MODE"] |
609 |
- if mode.isdigit(): |
610 |
- parsed_mode = int(mode, 8) |
611 |
- elif mode == "": |
612 |
- raise KeyError() |
613 |
- else: |
614 |
- raise ValueError() |
615 |
- if parsed_mode & 0o7777 != parsed_mode: |
616 |
- raise ValueError("Invalid file mode: %s" % mode) |
617 |
- else: |
618 |
- workdir_mode = parsed_mode |
619 |
- except KeyError as e: |
620 |
- writemsg(_("!!! PORTAGE_WORKDIR_MODE is unset, using %s.\n") % oct(workdir_mode)) |
621 |
- except ValueError as e: |
622 |
- if len(str(e)) > 0: |
623 |
- writemsg("%s\n" % e) |
624 |
- writemsg(_("!!! Unable to parse PORTAGE_WORKDIR_MODE='%s', using %s.\n") % \ |
625 |
- (mysettings["PORTAGE_WORKDIR_MODE"], oct(workdir_mode))) |
626 |
- mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode).replace('o', '') |
627 |
- try: |
628 |
- apply_secpass_permissions(mysettings["WORKDIR"], |
629 |
- uid=portage_uid, gid=portage_gid, mode=workdir_mode) |
630 |
- except portage.exception.FileNotFound: |
631 |
- pass # ebuild.sh will create it |
632 |
- |
633 |
- if mysettings.get("PORT_LOGDIR", "") == "": |
634 |
- while "PORT_LOGDIR" in mysettings: |
635 |
- del mysettings["PORT_LOGDIR"] |
636 |
- if "PORT_LOGDIR" in mysettings: |
637 |
- try: |
638 |
- modified = portage.util.ensure_dirs(mysettings["PORT_LOGDIR"]) |
639 |
- if modified: |
640 |
- apply_secpass_permissions(mysettings["PORT_LOGDIR"], |
641 |
- uid=portage_uid, gid=portage_gid, mode=0o2770) |
642 |
- except portage.exception.PortageException as e: |
643 |
- writemsg("!!! %s\n" % str(e), noiselevel=-1) |
644 |
- writemsg(_("!!! Permission issues with PORT_LOGDIR='%s'\n") % \ |
645 |
- mysettings["PORT_LOGDIR"], noiselevel=-1) |
646 |
- writemsg(_("!!! Disabling logging.\n"), noiselevel=-1) |
647 |
- while "PORT_LOGDIR" in mysettings: |
648 |
- del mysettings["PORT_LOGDIR"] |
649 |
- if "PORT_LOGDIR" in mysettings and \ |
650 |
- os.access(mysettings["PORT_LOGDIR"], os.W_OK): |
651 |
- logid_path = os.path.join(mysettings["PORTAGE_BUILDDIR"], ".logid") |
652 |
- if not os.path.exists(logid_path): |
653 |
- open(_unicode_encode(logid_path), 'w') |
654 |
- logid_time = _unicode_decode(time.strftime("%Y%m%d-%H%M%S", |
655 |
- time.gmtime(os.stat(logid_path).st_mtime)), |
656 |
- encoding=_encodings['content'], errors='replace') |
657 |
- |
658 |
- if "split-log" in mysettings.features: |
659 |
- mysettings["PORTAGE_LOG_FILE"] = os.path.join( |
660 |
- mysettings["PORT_LOGDIR"], "build", "%s/%s:%s.log" % \ |
661 |
- (mysettings["CATEGORY"], mysettings["PF"], logid_time)) |
662 |
- else: |
663 |
- mysettings["PORTAGE_LOG_FILE"] = os.path.join( |
664 |
- mysettings["PORT_LOGDIR"], "%s:%s:%s.log" % \ |
665 |
- (mysettings["CATEGORY"], mysettings["PF"], logid_time)) |
666 |
- |
667 |
- util.ensure_dirs(os.path.dirname(mysettings["PORTAGE_LOG_FILE"])) |
668 |
- |
669 |
- else: |
670 |
- # NOTE: When sesandbox is enabled, the local SELinux security policies |
671 |
- # may not allow output to be piped out of the sesandbox domain. The |
672 |
- # current policy will allow it to work when a pty is available, but |
673 |
- # not through a normal pipe. See bug #162404. |
674 |
- mysettings["PORTAGE_LOG_FILE"] = os.path.join( |
675 |
- mysettings["T"], "build.log") |
676 |
- |
677 |
-def _doebuild_exit_status_check(mydo, settings): |
678 |
- """ |
679 |
- Returns an error string if the shell appeared |
680 |
- to exit unsuccessfully, None otherwise. |
681 |
- """ |
682 |
- exit_status_file = settings.get("EBUILD_EXIT_STATUS_FILE") |
683 |
- if not exit_status_file or \ |
684 |
- os.path.exists(exit_status_file): |
685 |
- return None |
686 |
- msg = _("The ebuild phase '%s' has exited " |
687 |
- "unexpectedly. This type of behavior " |
688 |
- "is known to be triggered " |
689 |
- "by things such as failed variable " |
690 |
- "assignments (bug #190128) or bad substitution " |
691 |
- "errors (bug #200313). Normally, before exiting, bash should " |
692 |
- "have displayed an error message above. If bash did not " |
693 |
- "produce an error message above, it's possible " |
694 |
- "that the ebuild has called `exit` when it " |
695 |
- "should have called `die` instead. This behavior may also " |
696 |
- "be triggered by a corrupt bash binary or a hardware " |
697 |
- "problem such as memory or cpu malfunction. If the problem is not " |
698 |
- "reproducible or it appears to occur randomly, then it is likely " |
699 |
- "to be triggered by a hardware problem. " |
700 |
- "If you suspect a hardware problem then you should " |
701 |
- "try some basic hardware diagnostics such as memtest. " |
702 |
- "Please do not report this as a bug unless it is consistently " |
703 |
- "reproducible and you are sure that your bash binary and hardware " |
704 |
- "are functioning properly.") % mydo |
705 |
- return msg |
706 |
- |
707 |
-def _doebuild_exit_status_check_and_log(settings, mydo, retval): |
708 |
- msg = _doebuild_exit_status_check(mydo, settings) |
709 |
- if msg: |
710 |
- if retval == os.EX_OK: |
711 |
- retval = 1 |
712 |
- from textwrap import wrap |
713 |
- from portage.elog.messages import eerror |
714 |
- for l in wrap(msg, 72): |
715 |
- eerror(l, phase=mydo, key=settings.mycpv) |
716 |
- return retval |
717 |
- |
718 |
-def _doebuild_exit_status_unlink(exit_status_file): |
719 |
- """ |
720 |
- Double check to make sure it really doesn't exist |
721 |
- and raise an OSError if it still does (it shouldn't). |
722 |
- OSError if necessary. |
723 |
- """ |
724 |
- if not exit_status_file: |
725 |
- return |
726 |
- try: |
727 |
- os.unlink(exit_status_file) |
728 |
- except OSError: |
729 |
- pass |
730 |
- if os.path.exists(exit_status_file): |
731 |
- os.unlink(exit_status_file) |
732 |
- |
733 |
-_doebuild_manifest_exempt_depend = 0 |
734 |
-_doebuild_manifest_cache = None |
735 |
-_doebuild_broken_ebuilds = set() |
736 |
-_doebuild_broken_manifests = set() |
737 |
- |
738 |
-def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, |
739 |
- fetchonly=0, cleanup=0, dbkey=None, use_cache=1, fetchall=0, tree=None, |
740 |
- mydbapi=None, vartree=None, prev_mtimes=None, |
741 |
- fd_pipes=None, returnpid=False): |
742 |
- |
743 |
- """ |
744 |
- Wrapper function that invokes specific ebuild phases through the spawning |
745 |
- of ebuild.sh |
746 |
- |
747 |
- @param myebuild: name of the ebuild to invoke the phase on (CPV) |
748 |
- @type myebuild: String |
749 |
- @param mydo: Phase to run |
750 |
- @type mydo: String |
751 |
- @param myroot: $ROOT (usually '/', see man make.conf) |
752 |
- @type myroot: String |
753 |
- @param mysettings: Portage Configuration |
754 |
- @type mysettings: instance of portage.config |
755 |
- @param debug: Turns on various debug information (eg, debug for spawn) |
756 |
- @type debug: Boolean |
757 |
- @param listonly: Used to wrap fetch(); passed such that fetch only lists files required. |
758 |
- @type listonly: Boolean |
759 |
- @param fetchonly: Used to wrap fetch(); passed such that files are only fetched (no other actions) |
760 |
- @type fetchonly: Boolean |
761 |
- @param cleanup: Passed to prepare_build_dirs (TODO: what does it do?) |
762 |
- @type cleanup: Boolean |
763 |
- @param dbkey: A dict (usually keys and values from the depend phase, such as KEYWORDS, USE, etc..) |
764 |
- @type dbkey: Dict or String |
765 |
- @param use_cache: Enables the cache |
766 |
- @type use_cache: Boolean |
767 |
- @param fetchall: Used to wrap fetch(), fetches all URIs (even ones invalid due to USE conditionals) |
768 |
- @type fetchall: Boolean |
769 |
- @param tree: Which tree to use ('vartree','porttree','bintree', etc..), defaults to 'porttree' |
770 |
- @type tree: String |
771 |
- @param mydbapi: a dbapi instance to pass to various functions; this should be a portdbapi instance. |
772 |
- @type mydbapi: portdbapi instance |
773 |
- @param vartree: A instance of vartree; used for aux_get calls, defaults to db[myroot]['vartree'] |
774 |
- @type vartree: vartree instance |
775 |
- @param prev_mtimes: A dict of { filename:mtime } keys used by merge() to do config_protection |
776 |
- @type prev_mtimes: dictionary |
777 |
- @param fd_pipes: A dict of mapping for pipes, { '0': stdin, '1': stdout } |
778 |
- for example. |
779 |
- @type fd_pipes: Dictionary |
780 |
- @param returnpid: Return a list of process IDs for a successful spawn, or |
781 |
- an integer value if spawn is unsuccessful. NOTE: This requires the |
782 |
- caller clean up all returned PIDs. |
783 |
- @type returnpid: Boolean |
784 |
- @rtype: Boolean |
785 |
- @returns: |
786 |
- 1. 0 for success |
787 |
- 2. 1 for error |
788 |
- |
789 |
- Most errors have an accompanying error message. |
790 |
- |
791 |
- listonly and fetchonly are only really necessary for operations involving 'fetch' |
792 |
- prev_mtimes are only necessary for merge operations. |
793 |
- Other variables may not be strictly required, many have defaults that are set inside of doebuild. |
794 |
- |
795 |
- """ |
796 |
- |
797 |
- if not tree: |
798 |
- writemsg("Warning: tree not specified to doebuild\n") |
799 |
- tree = "porttree" |
800 |
- global db |
801 |
- |
802 |
- # chunked out deps for each phase, so that ebuild binary can use it |
803 |
- # to collapse targets down. |
804 |
- actionmap_deps={ |
805 |
- "setup": [], |
806 |
- "unpack": ["setup"], |
807 |
- "prepare": ["unpack"], |
808 |
- "configure": ["prepare"], |
809 |
- "compile":["configure"], |
810 |
- "test": ["compile"], |
811 |
- "install":["test"], |
812 |
- "rpm": ["install"], |
813 |
- "package":["install"], |
814 |
- } |
815 |
- |
816 |
- if mydbapi is None: |
817 |
- mydbapi = db[myroot][tree].dbapi |
818 |
- |
819 |
- if vartree is None and mydo in ("merge", "qmerge", "unmerge"): |
820 |
- vartree = db[myroot]["vartree"] |
821 |
- |
822 |
- features = mysettings.features |
823 |
- noauto = "noauto" in features |
824 |
- from portage.data import secpass |
825 |
- |
826 |
- clean_phases = ("clean", "cleanrm") |
827 |
- validcommands = ["help","clean","prerm","postrm","cleanrm","preinst","postinst", |
828 |
- "config", "info", "setup", "depend", "pretend", |
829 |
- "fetch", "fetchall", "digest", |
830 |
- "unpack", "prepare", "configure", "compile", "test", |
831 |
- "install", "rpm", "qmerge", "merge", |
832 |
- "package","unmerge", "manifest"] |
833 |
- |
834 |
- if mydo not in validcommands: |
835 |
- validcommands.sort() |
836 |
- writemsg("!!! doebuild: '%s' is not one of the following valid commands:" % mydo, |
837 |
- noiselevel=-1) |
838 |
- for vcount in range(len(validcommands)): |
839 |
- if vcount%6 == 0: |
840 |
- writemsg("\n!!! ", noiselevel=-1) |
841 |
- writemsg(validcommands[vcount].ljust(11), noiselevel=-1) |
842 |
- writemsg("\n", noiselevel=-1) |
843 |
- return 1 |
844 |
- |
845 |
- if mydo == "fetchall": |
846 |
- fetchall = 1 |
847 |
- mydo = "fetch" |
848 |
- |
849 |
- parallel_fetchonly = mydo in ("fetch", "fetchall") and \ |
850 |
- "PORTAGE_PARALLEL_FETCHONLY" in mysettings |
851 |
- |
852 |
- if mydo not in clean_phases and not os.path.exists(myebuild): |
853 |
- writemsg("!!! doebuild: %s not found for %s\n" % (myebuild, mydo), |
854 |
- noiselevel=-1) |
855 |
- return 1 |
856 |
- |
857 |
- global _doebuild_manifest_exempt_depend |
858 |
- |
859 |
- if "strict" in features and \ |
860 |
- "digest" not in features and \ |
861 |
- tree == "porttree" and \ |
862 |
- mydo not in ("digest", "manifest", "help") and \ |
863 |
- not _doebuild_manifest_exempt_depend: |
864 |
- # Always verify the ebuild checksums before executing it. |
865 |
- global _doebuild_manifest_cache, _doebuild_broken_ebuilds, \ |
866 |
- _doebuild_broken_ebuilds |
867 |
- |
868 |
- if myebuild in _doebuild_broken_ebuilds: |
869 |
- return 1 |
870 |
- |
871 |
- pkgdir = os.path.dirname(myebuild) |
872 |
- manifest_path = os.path.join(pkgdir, "Manifest") |
873 |
- |
874 |
- # Avoid checking the same Manifest several times in a row during a |
875 |
- # regen with an empty cache. |
876 |
- if _doebuild_manifest_cache is None or \ |
877 |
- _doebuild_manifest_cache.getFullname() != manifest_path: |
878 |
- _doebuild_manifest_cache = None |
879 |
- if not os.path.exists(manifest_path): |
880 |
- out = portage.output.EOutput() |
881 |
- out.eerror(_("Manifest not found for '%s'") % (myebuild,)) |
882 |
- _doebuild_broken_ebuilds.add(myebuild) |
883 |
- return 1 |
884 |
- mf = Manifest(pkgdir, mysettings["DISTDIR"]) |
885 |
- |
886 |
- else: |
887 |
- mf = _doebuild_manifest_cache |
888 |
- |
889 |
- try: |
890 |
- mf.checkFileHashes("EBUILD", os.path.basename(myebuild)) |
891 |
- except KeyError: |
892 |
- out = portage.output.EOutput() |
893 |
- out.eerror(_("Missing digest for '%s'") % (myebuild,)) |
894 |
- _doebuild_broken_ebuilds.add(myebuild) |
895 |
- return 1 |
896 |
- except portage.exception.FileNotFound: |
897 |
- out = portage.output.EOutput() |
898 |
- out.eerror(_("A file listed in the Manifest " |
899 |
- "could not be found: '%s'") % (myebuild,)) |
900 |
- _doebuild_broken_ebuilds.add(myebuild) |
901 |
- return 1 |
902 |
- except portage.exception.DigestException as e: |
903 |
- out = portage.output.EOutput() |
904 |
- out.eerror(_("Digest verification failed:")) |
905 |
- out.eerror("%s" % e.value[0]) |
906 |
- out.eerror(_("Reason: %s") % e.value[1]) |
907 |
- out.eerror(_("Got: %s") % e.value[2]) |
908 |
- out.eerror(_("Expected: %s") % e.value[3]) |
909 |
- _doebuild_broken_ebuilds.add(myebuild) |
910 |
- return 1 |
911 |
- |
912 |
- if mf.getFullname() in _doebuild_broken_manifests: |
913 |
- return 1 |
914 |
- |
915 |
- if mf is not _doebuild_manifest_cache: |
916 |
- |
917 |
- # Make sure that all of the ebuilds are |
918 |
- # actually listed in the Manifest. |
919 |
- glep55 = 'parse-eapi-glep-55' in mysettings.features |
920 |
- for f in os.listdir(pkgdir): |
921 |
- pf = None |
922 |
- if glep55: |
923 |
- pf, eapi = _split_ebuild_name_glep55(f) |
924 |
- elif f[-7:] == '.ebuild': |
925 |
- pf = f[:-7] |
926 |
- if pf is not None and not mf.hasFile("EBUILD", f): |
927 |
- f = os.path.join(pkgdir, f) |
928 |
- if f not in _doebuild_broken_ebuilds: |
929 |
- out = portage.output.EOutput() |
930 |
- out.eerror(_("A file is not listed in the " |
931 |
- "Manifest: '%s'") % (f,)) |
932 |
- _doebuild_broken_manifests.add(manifest_path) |
933 |
- return 1 |
934 |
- |
935 |
- # Only cache it if the above stray files test succeeds. |
936 |
- _doebuild_manifest_cache = mf |
937 |
- |
938 |
- def exit_status_check(retval): |
939 |
- msg = _doebuild_exit_status_check(mydo, mysettings) |
940 |
- if msg: |
941 |
- if retval == os.EX_OK: |
942 |
- retval = 1 |
943 |
- from textwrap import wrap |
944 |
- from portage.elog.messages import eerror |
945 |
- for l in wrap(msg, 72): |
946 |
- eerror(l, phase=mydo, key=mysettings.mycpv) |
947 |
- return retval |
948 |
- |
949 |
- # Note: PORTAGE_BIN_PATH may differ from the global |
950 |
- # constant when portage is reinstalling itself. |
951 |
- portage_bin_path = mysettings["PORTAGE_BIN_PATH"] |
952 |
- ebuild_sh_binary = os.path.join(portage_bin_path, |
953 |
- os.path.basename(EBUILD_SH_BINARY)) |
954 |
- misc_sh_binary = os.path.join(portage_bin_path, |
955 |
- os.path.basename(MISC_SH_BINARY)) |
956 |
- |
957 |
- logfile=None |
958 |
- builddir_lock = None |
959 |
- tmpdir = None |
960 |
- tmpdir_orig = None |
961 |
- |
962 |
- try: |
963 |
- if mydo in ("digest", "manifest", "help"): |
964 |
- # Temporarily exempt the depend phase from manifest checks, in case |
965 |
- # aux_get calls trigger cache generation. |
966 |
- _doebuild_manifest_exempt_depend += 1 |
967 |
- |
968 |
- # If we don't need much space and we don't need a constant location, |
969 |
- # we can temporarily override PORTAGE_TMPDIR with a random temp dir |
970 |
- # so that there's no need for locking and it can be used even if the |
971 |
- # user isn't in the portage group. |
972 |
- if mydo in ("info",): |
973 |
- from tempfile import mkdtemp |
974 |
- tmpdir = mkdtemp() |
975 |
- tmpdir_orig = mysettings["PORTAGE_TMPDIR"] |
976 |
- mysettings["PORTAGE_TMPDIR"] = tmpdir |
977 |
- |
978 |
- doebuild_environment(myebuild, mydo, myroot, mysettings, debug, |
979 |
- use_cache, mydbapi) |
980 |
- |
981 |
- if mydo in clean_phases: |
982 |
- retval = spawn(_shell_quote(ebuild_sh_binary) + " clean", |
983 |
- mysettings, debug=debug, fd_pipes=fd_pipes, free=1, |
984 |
- logfile=None, returnpid=returnpid) |
985 |
- return retval |
986 |
- |
987 |
- restrict = set(mysettings.get('PORTAGE_RESTRICT', '').split()) |
988 |
- # get possible slot information from the deps file |
989 |
- if mydo == "depend": |
990 |
- writemsg("!!! DEBUG: dbkey: %s\n" % str(dbkey), 2) |
991 |
- droppriv = "userpriv" in mysettings.features |
992 |
- if returnpid: |
993 |
- mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend", |
994 |
- mysettings, fd_pipes=fd_pipes, returnpid=True, |
995 |
- droppriv=droppriv) |
996 |
- return mypids |
997 |
- elif isinstance(dbkey, dict): |
998 |
- mysettings["dbkey"] = "" |
999 |
- pr, pw = os.pipe() |
1000 |
- fd_pipes = { |
1001 |
- 0:sys.stdin.fileno(), |
1002 |
- 1:sys.stdout.fileno(), |
1003 |
- 2:sys.stderr.fileno(), |
1004 |
- 9:pw} |
1005 |
- mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend", |
1006 |
- mysettings, |
1007 |
- fd_pipes=fd_pipes, returnpid=True, droppriv=droppriv) |
1008 |
- os.close(pw) # belongs exclusively to the child process now |
1009 |
- f = os.fdopen(pr, 'rb') |
1010 |
- for k, v in zip(auxdbkeys, |
1011 |
- (_unicode_decode(line).rstrip('\n') for line in f)): |
1012 |
- dbkey[k] = v |
1013 |
- f.close() |
1014 |
- retval = os.waitpid(mypids[0], 0)[1] |
1015 |
- portage.process.spawned_pids.remove(mypids[0]) |
1016 |
- # If it got a signal, return the signal that was sent, but |
1017 |
- # shift in order to distinguish it from a return value. (just |
1018 |
- # like portage.process.spawn() would do). |
1019 |
- if retval & 0xff: |
1020 |
- retval = (retval & 0xff) << 8 |
1021 |
- else: |
1022 |
- # Otherwise, return its exit code. |
1023 |
- retval = retval >> 8 |
1024 |
- if retval == os.EX_OK and len(dbkey) != len(auxdbkeys): |
1025 |
- # Don't trust bash's returncode if the |
1026 |
- # number of lines is incorrect. |
1027 |
- retval = 1 |
1028 |
- return retval |
1029 |
- elif dbkey: |
1030 |
- mysettings["dbkey"] = dbkey |
1031 |
- else: |
1032 |
- mysettings["dbkey"] = \ |
1033 |
- os.path.join(mysettings.depcachedir, "aux_db_key_temp") |
1034 |
- |
1035 |
- return spawn(_shell_quote(ebuild_sh_binary) + " depend", |
1036 |
- mysettings, |
1037 |
- droppriv=droppriv) |
1038 |
- |
1039 |
- # Validate dependency metadata here to ensure that ebuilds with invalid |
1040 |
- # data are never installed via the ebuild command. Don't bother when |
1041 |
- # returnpid == True since there's no need to do this every time emerge |
1042 |
- # executes a phase. |
1043 |
- if not returnpid: |
1044 |
- rval = _validate_deps(mysettings, myroot, mydo, mydbapi) |
1045 |
- if rval != os.EX_OK: |
1046 |
- return rval |
1047 |
- |
1048 |
- if "PORTAGE_TMPDIR" not in mysettings or \ |
1049 |
- not os.path.isdir(mysettings["PORTAGE_TMPDIR"]): |
1050 |
- writemsg(_("The directory specified in your " |
1051 |
- "PORTAGE_TMPDIR variable, '%s',\n" |
1052 |
- "does not exist. Please create this directory or " |
1053 |
- "correct your PORTAGE_TMPDIR setting.\n") % mysettings.get("PORTAGE_TMPDIR", ""), noiselevel=-1) |
1054 |
- return 1 |
1055 |
- |
1056 |
- # as some people use a separate PORTAGE_TMPDIR mount |
1057 |
- # we prefer that as the checks below would otherwise be pointless |
1058 |
- # for those people. |
1059 |
- if os.path.exists(os.path.join(mysettings["PORTAGE_TMPDIR"], "portage")): |
1060 |
- checkdir = os.path.join(mysettings["PORTAGE_TMPDIR"], "portage") |
1061 |
- else: |
1062 |
- checkdir = mysettings["PORTAGE_TMPDIR"] |
1063 |
- |
1064 |
- if not os.access(checkdir, os.W_OK): |
1065 |
- writemsg(_("%s is not writable.\n" |
1066 |
- "Likely cause is that you've mounted it as readonly.\n") % checkdir, |
1067 |
- noiselevel=-1) |
1068 |
- return 1 |
1069 |
- else: |
1070 |
- from tempfile import NamedTemporaryFile |
1071 |
- fd = NamedTemporaryFile(prefix="exectest-", dir=checkdir) |
1072 |
- os.chmod(fd.name, 0o755) |
1073 |
- if not os.access(fd.name, os.X_OK): |
1074 |
- writemsg(_("Can not execute files in %s\n" |
1075 |
- "Likely cause is that you've mounted it with one of the\n" |
1076 |
- "following mount options: 'noexec', 'user', 'users'\n\n" |
1077 |
- "Please make sure that portage can execute files in this directory.\n") % checkdir, |
1078 |
- noiselevel=-1) |
1079 |
- fd.close() |
1080 |
- return 1 |
1081 |
- fd.close() |
1082 |
- del checkdir |
1083 |
- |
1084 |
- if mydo == "unmerge": |
1085 |
- return unmerge(mysettings["CATEGORY"], |
1086 |
- mysettings["PF"], myroot, mysettings, vartree=vartree) |
1087 |
- |
1088 |
- # Build directory creation isn't required for any of these. |
1089 |
- # In the fetch phase, the directory is needed only for RESTRICT=fetch |
1090 |
- # in order to satisfy the sane $PWD requirement (from bug #239560) |
1091 |
- # when pkg_nofetch is spawned. |
1092 |
- have_build_dirs = False |
1093 |
- if not parallel_fetchonly and \ |
1094 |
- mydo not in ('digest', 'help', 'manifest') and \ |
1095 |
- not (mydo == 'fetch' and 'fetch' not in restrict): |
1096 |
- mystatus = prepare_build_dirs(myroot, mysettings, cleanup) |
1097 |
- if mystatus: |
1098 |
- return mystatus |
1099 |
- have_build_dirs = True |
1100 |
- |
1101 |
- # emerge handles logging externally |
1102 |
- if not returnpid: |
1103 |
- # PORTAGE_LOG_FILE is set by the |
1104 |
- # above prepare_build_dirs() call. |
1105 |
- logfile = mysettings.get("PORTAGE_LOG_FILE") |
1106 |
- |
1107 |
- if have_build_dirs: |
1108 |
- env_file = os.path.join(mysettings["T"], "environment") |
1109 |
- env_stat = None |
1110 |
- saved_env = None |
1111 |
- try: |
1112 |
- env_stat = os.stat(env_file) |
1113 |
- except OSError as e: |
1114 |
- if e.errno != errno.ENOENT: |
1115 |
- raise |
1116 |
- del e |
1117 |
- if not env_stat: |
1118 |
- saved_env = os.path.join( |
1119 |
- os.path.dirname(myebuild), "environment.bz2") |
1120 |
- if not os.path.isfile(saved_env): |
1121 |
- saved_env = None |
1122 |
- if saved_env: |
1123 |
- retval = os.system( |
1124 |
- "bzip2 -dc %s > %s" % \ |
1125 |
- (_shell_quote(saved_env), |
1126 |
- _shell_quote(env_file))) |
1127 |
- try: |
1128 |
- env_stat = os.stat(env_file) |
1129 |
- except OSError as e: |
1130 |
- if e.errno != errno.ENOENT: |
1131 |
- raise |
1132 |
- del e |
1133 |
- if os.WIFEXITED(retval) and \ |
1134 |
- os.WEXITSTATUS(retval) == os.EX_OK and \ |
1135 |
- env_stat and env_stat.st_size > 0: |
1136 |
- # This is a signal to ebuild.sh, so that it knows to filter |
1137 |
- # out things like SANDBOX_{DENY,PREDICT,READ,WRITE} that |
1138 |
- # would be preserved between normal phases. |
1139 |
- open(_unicode_encode(env_file + '.raw'), 'w') |
1140 |
- else: |
1141 |
- writemsg(_("!!! Error extracting saved " |
1142 |
- "environment: '%s'\n") % \ |
1143 |
- saved_env, noiselevel=-1) |
1144 |
- try: |
1145 |
- os.unlink(env_file) |
1146 |
- except OSError as e: |
1147 |
- if e.errno != errno.ENOENT: |
1148 |
- raise |
1149 |
- del e |
1150 |
- env_stat = None |
1151 |
- if env_stat: |
1152 |
- pass |
1153 |
- else: |
1154 |
- for var in ("ARCH", ): |
1155 |
- value = mysettings.get(var) |
1156 |
- if value and value.strip(): |
1157 |
- continue |
1158 |
- msg = _("%(var)s is not set... " |
1159 |
- "Are you missing the '%(configroot)setc/make.profile' symlink? " |
1160 |
- "Is the symlink correct? " |
1161 |
- "Is your portage tree complete?") % \ |
1162 |
- {"var": var, "configroot": mysettings["PORTAGE_CONFIGROOT"]} |
1163 |
- from portage.elog.messages import eerror |
1164 |
- from textwrap import wrap |
1165 |
- for line in wrap(msg, 70): |
1166 |
- eerror(line, phase="setup", key=mysettings.mycpv) |
1167 |
- from portage.elog import elog_process |
1168 |
- elog_process(mysettings.mycpv, mysettings) |
1169 |
- return 1 |
1170 |
- del env_file, env_stat, saved_env |
1171 |
- _doebuild_exit_status_unlink( |
1172 |
- mysettings.get("EBUILD_EXIT_STATUS_FILE")) |
1173 |
- else: |
1174 |
- mysettings.pop("EBUILD_EXIT_STATUS_FILE", None) |
1175 |
- |
1176 |
- # if any of these are being called, handle them -- running them out of |
1177 |
- # the sandbox -- and stop now. |
1178 |
- if mydo == "help": |
1179 |
- return spawn(_shell_quote(ebuild_sh_binary) + " " + mydo, |
1180 |
- mysettings, debug=debug, free=1, logfile=logfile) |
1181 |
- elif mydo == "setup": |
1182 |
- retval = spawn( |
1183 |
- _shell_quote(ebuild_sh_binary) + " " + mydo, mysettings, |
1184 |
- debug=debug, free=1, logfile=logfile, fd_pipes=fd_pipes, |
1185 |
- returnpid=returnpid) |
1186 |
- if returnpid: |
1187 |
- return retval |
1188 |
- retval = exit_status_check(retval) |
1189 |
- if secpass >= 2: |
1190 |
- """ Privileged phases may have left files that need to be made |
1191 |
- writable to a less privileged user.""" |
1192 |
- apply_recursive_permissions(mysettings["T"], |
1193 |
- uid=portage_uid, gid=portage_gid, dirmode=0o70, dirmask=0, |
1194 |
- filemode=0o60, filemask=0) |
1195 |
- return retval |
1196 |
- elif mydo == "preinst": |
1197 |
- phase_retval = spawn( |
1198 |
- _shell_quote(ebuild_sh_binary) + " " + mydo, |
1199 |
- mysettings, debug=debug, free=1, logfile=logfile, |
1200 |
- fd_pipes=fd_pipes, returnpid=returnpid) |
1201 |
- |
1202 |
- if returnpid: |
1203 |
- return phase_retval |
1204 |
- |
1205 |
- phase_retval = exit_status_check(phase_retval) |
1206 |
- if phase_retval == os.EX_OK: |
1207 |
- _doebuild_exit_status_unlink( |
1208 |
- mysettings.get("EBUILD_EXIT_STATUS_FILE")) |
1209 |
- mysettings.pop("EBUILD_PHASE", None) |
1210 |
- phase_retval = spawn( |
1211 |
- " ".join(_post_pkg_preinst_cmd(mysettings)), |
1212 |
- mysettings, debug=debug, free=1, logfile=logfile) |
1213 |
- phase_retval = exit_status_check(phase_retval) |
1214 |
- if phase_retval != os.EX_OK: |
1215 |
- writemsg(_("!!! post preinst failed; exiting.\n"), |
1216 |
- noiselevel=-1) |
1217 |
- return phase_retval |
1218 |
- elif mydo == "postinst": |
1219 |
- phase_retval = spawn( |
1220 |
- _shell_quote(ebuild_sh_binary) + " " + mydo, |
1221 |
- mysettings, debug=debug, free=1, logfile=logfile, |
1222 |
- fd_pipes=fd_pipes, returnpid=returnpid) |
1223 |
- |
1224 |
- if returnpid: |
1225 |
- return phase_retval |
1226 |
- |
1227 |
- phase_retval = exit_status_check(phase_retval) |
1228 |
- if phase_retval == os.EX_OK: |
1229 |
- _doebuild_exit_status_unlink( |
1230 |
- mysettings.get("EBUILD_EXIT_STATUS_FILE")) |
1231 |
- mysettings.pop("EBUILD_PHASE", None) |
1232 |
- phase_retval = spawn(" ".join(_post_pkg_postinst_cmd(mysettings)), |
1233 |
- mysettings, debug=debug, free=1, logfile=logfile) |
1234 |
- phase_retval = exit_status_check(phase_retval) |
1235 |
- if phase_retval != os.EX_OK: |
1236 |
- writemsg(_("!!! post postinst failed; exiting.\n"), |
1237 |
- noiselevel=-1) |
1238 |
- return phase_retval |
1239 |
- elif mydo in ("prerm", "postrm", "config", "info"): |
1240 |
- retval = spawn( |
1241 |
- _shell_quote(ebuild_sh_binary) + " " + mydo, |
1242 |
- mysettings, debug=debug, free=1, logfile=logfile, |
1243 |
- fd_pipes=fd_pipes, returnpid=returnpid) |
1244 |
- |
1245 |
- if returnpid: |
1246 |
- return retval |
1247 |
- |
1248 |
- retval = exit_status_check(retval) |
1249 |
- return retval |
1250 |
- |
1251 |
- mycpv = "/".join((mysettings["CATEGORY"], mysettings["PF"])) |
1252 |
- |
1253 |
- emerge_skip_distfiles = returnpid |
1254 |
- emerge_skip_digest = returnpid |
1255 |
- # Only try and fetch the files if we are going to need them ... |
1256 |
- # otherwise, if user has FEATURES=noauto and they run `ebuild clean |
1257 |
- # unpack compile install`, we will try and fetch 4 times :/ |
1258 |
- need_distfiles = not emerge_skip_distfiles and \ |
1259 |
- (mydo in ("fetch", "unpack") or \ |
1260 |
- mydo not in ("digest", "manifest") and "noauto" not in features) |
1261 |
- alist = mysettings.configdict["pkg"].get("A") |
1262 |
- aalist = mysettings.configdict["pkg"].get("AA") |
1263 |
- if alist is None or aalist is None: |
1264 |
- # Make sure we get the correct tree in case there are overlays. |
1265 |
- mytree = os.path.realpath( |
1266 |
- os.path.dirname(os.path.dirname(mysettings["O"]))) |
1267 |
- useflags = mysettings["PORTAGE_USE"].split() |
1268 |
- try: |
1269 |
- alist = mydbapi.getFetchMap(mycpv, useflags=useflags, |
1270 |
- mytree=mytree) |
1271 |
- aalist = mydbapi.getFetchMap(mycpv, mytree=mytree) |
1272 |
- except portage.exception.InvalidDependString as e: |
1273 |
- writemsg("!!! %s\n" % str(e), noiselevel=-1) |
1274 |
- writemsg(_("!!! Invalid SRC_URI for '%s'.\n") % mycpv, |
1275 |
- noiselevel=-1) |
1276 |
- del e |
1277 |
- return 1 |
1278 |
- mysettings.configdict["pkg"]["A"] = " ".join(alist) |
1279 |
- mysettings.configdict["pkg"]["AA"] = " ".join(aalist) |
1280 |
- else: |
1281 |
- alist = set(alist.split()) |
1282 |
- aalist = set(aalist.split()) |
1283 |
- if ("mirror" in features) or fetchall: |
1284 |
- fetchme = aalist |
1285 |
- checkme = aalist |
1286 |
- else: |
1287 |
- fetchme = alist |
1288 |
- checkme = alist |
1289 |
- |
1290 |
- if mydo == "fetch": |
1291 |
- # Files are already checked inside fetch(), |
1292 |
- # so do not check them again. |
1293 |
- checkme = [] |
1294 |
- |
1295 |
- if not emerge_skip_distfiles and \ |
1296 |
- need_distfiles and not fetch( |
1297 |
- fetchme, mysettings, listonly=listonly, fetchonly=fetchonly): |
1298 |
- return 1 |
1299 |
- |
1300 |
- if mydo == "fetch" and listonly: |
1301 |
- return 0 |
1302 |
- |
1303 |
- try: |
1304 |
- if mydo == "manifest": |
1305 |
- return not digestgen(mysettings=mysettings, myportdb=mydbapi) |
1306 |
- elif mydo == "digest": |
1307 |
- return not digestgen(mysettings=mysettings, myportdb=mydbapi) |
1308 |
- elif mydo != 'fetch' and not emerge_skip_digest and \ |
1309 |
- "digest" in mysettings.features: |
1310 |
- # Don't do this when called by emerge or when called just |
1311 |
- # for fetch (especially parallel-fetch) since it's not needed |
1312 |
- # and it can interfere with parallel tasks. |
1313 |
- digestgen(mysettings=mysettings, myportdb=mydbapi) |
1314 |
- except portage.exception.PermissionDenied as e: |
1315 |
- writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=-1) |
1316 |
- if mydo in ("digest", "manifest"): |
1317 |
- return 1 |
1318 |
- |
1319 |
- # See above comment about fetching only when needed |
1320 |
- if not emerge_skip_distfiles and \ |
1321 |
- not digestcheck(checkme, mysettings, "strict" in features): |
1322 |
- return 1 |
1323 |
- |
1324 |
- if mydo == "fetch": |
1325 |
- return 0 |
1326 |
- |
1327 |
- # remove PORTAGE_ACTUAL_DISTDIR once cvs/svn is supported via SRC_URI |
1328 |
- if (mydo != "setup" and "noauto" not in features) or mydo == "unpack": |
1329 |
- orig_distdir = mysettings["DISTDIR"] |
1330 |
- mysettings["PORTAGE_ACTUAL_DISTDIR"] = orig_distdir |
1331 |
- edpath = mysettings["DISTDIR"] = \ |
1332 |
- os.path.join(mysettings["PORTAGE_BUILDDIR"], "distdir") |
1333 |
- portage.util.ensure_dirs(edpath, gid=portage_gid, mode=0o755) |
1334 |
- |
1335 |
- # Remove any unexpected files or directories. |
1336 |
- for x in os.listdir(edpath): |
1337 |
- symlink_path = os.path.join(edpath, x) |
1338 |
- st = os.lstat(symlink_path) |
1339 |
- if x in alist and stat.S_ISLNK(st.st_mode): |
1340 |
- continue |
1341 |
- if stat.S_ISDIR(st.st_mode): |
1342 |
- shutil.rmtree(symlink_path) |
1343 |
- else: |
1344 |
- os.unlink(symlink_path) |
1345 |
- |
1346 |
- # Check for existing symlinks and recreate if necessary. |
1347 |
- for x in alist: |
1348 |
- symlink_path = os.path.join(edpath, x) |
1349 |
- target = os.path.join(orig_distdir, x) |
1350 |
- try: |
1351 |
- link_target = os.readlink(symlink_path) |
1352 |
- except OSError: |
1353 |
- os.symlink(target, symlink_path) |
1354 |
- else: |
1355 |
- if link_target != target: |
1356 |
- os.unlink(symlink_path) |
1357 |
- os.symlink(target, symlink_path) |
1358 |
- |
1359 |
- #initial dep checks complete; time to process main commands |
1360 |
- |
1361 |
- restrict = mysettings["PORTAGE_RESTRICT"].split() |
1362 |
- nosandbox = (("userpriv" in features) and \ |
1363 |
- ("usersandbox" not in features) and \ |
1364 |
- "userpriv" not in restrict and \ |
1365 |
- "nouserpriv" not in restrict) |
1366 |
- if nosandbox and ("userpriv" not in features or \ |
1367 |
- "userpriv" in restrict or \ |
1368 |
- "nouserpriv" in restrict): |
1369 |
- nosandbox = ("sandbox" not in features and \ |
1370 |
- "usersandbox" not in features) |
1371 |
- |
1372 |
- if not process.sandbox_capable: |
1373 |
- nosandbox = True |
1374 |
- |
1375 |
- sesandbox = mysettings.selinux_enabled() and \ |
1376 |
- "sesandbox" in mysettings.features |
1377 |
- |
1378 |
- droppriv = "userpriv" in mysettings.features and \ |
1379 |
- "userpriv" not in restrict and \ |
1380 |
- secpass >= 2 |
1381 |
- |
1382 |
- fakeroot = "fakeroot" in mysettings.features |
1383 |
- |
1384 |
- ebuild_sh = _shell_quote(ebuild_sh_binary) + " %s" |
1385 |
- misc_sh = _shell_quote(misc_sh_binary) + " dyn_%s" |
1386 |
- |
1387 |
- # args are for the to spawn function |
1388 |
- actionmap = { |
1389 |
-"pretend": {"cmd":ebuild_sh, "args":{"droppriv":0, "free":1, "sesandbox":0, "fakeroot":0}}, |
1390 |
-"setup": {"cmd":ebuild_sh, "args":{"droppriv":0, "free":1, "sesandbox":0, "fakeroot":0}}, |
1391 |
-"unpack": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":0, "sesandbox":sesandbox, "fakeroot":0}}, |
1392 |
-"prepare": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":0, "sesandbox":sesandbox, "fakeroot":0}}, |
1393 |
-"configure":{"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}}, |
1394 |
-"compile": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}}, |
1395 |
-"test": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}}, |
1396 |
-"install": {"cmd":ebuild_sh, "args":{"droppriv":0, "free":0, "sesandbox":sesandbox, "fakeroot":fakeroot}}, |
1397 |
-"rpm": {"cmd":misc_sh, "args":{"droppriv":0, "free":0, "sesandbox":0, "fakeroot":fakeroot}}, |
1398 |
-"package": {"cmd":misc_sh, "args":{"droppriv":0, "free":0, "sesandbox":0, "fakeroot":fakeroot}}, |
1399 |
- } |
1400 |
- |
1401 |
- # merge the deps in so we have again a 'full' actionmap |
1402 |
- # be glad when this can die. |
1403 |
- for x in actionmap: |
1404 |
- if len(actionmap_deps.get(x, [])): |
1405 |
- actionmap[x]["dep"] = ' '.join(actionmap_deps[x]) |
1406 |
- |
1407 |
- if mydo in actionmap: |
1408 |
- if mydo == "package": |
1409 |
- # Make sure the package directory exists before executing |
1410 |
- # this phase. This can raise PermissionDenied if |
1411 |
- # the current user doesn't have write access to $PKGDIR. |
1412 |
- parent_dir = os.path.join(mysettings["PKGDIR"], |
1413 |
- mysettings["CATEGORY"]) |
1414 |
- portage.util.ensure_dirs(parent_dir) |
1415 |
- if not os.access(parent_dir, os.W_OK): |
1416 |
- raise portage.exception.PermissionDenied( |
1417 |
- "access('%s', os.W_OK)" % parent_dir) |
1418 |
- retval = spawnebuild(mydo, |
1419 |
- actionmap, mysettings, debug, logfile=logfile, |
1420 |
- fd_pipes=fd_pipes, returnpid=returnpid) |
1421 |
- elif mydo=="qmerge": |
1422 |
- # check to ensure install was run. this *only* pops up when users |
1423 |
- # forget it and are using ebuild |
1424 |
- if not os.path.exists( |
1425 |
- os.path.join(mysettings["PORTAGE_BUILDDIR"], ".installed")): |
1426 |
- writemsg(_("!!! mydo=qmerge, but the install phase has not been run\n"), |
1427 |
- noiselevel=-1) |
1428 |
- return 1 |
1429 |
- # qmerge is a special phase that implies noclean. |
1430 |
- if "noclean" not in mysettings.features: |
1431 |
- mysettings.features.add("noclean") |
1432 |
- #qmerge is specifically not supposed to do a runtime dep check |
1433 |
- retval = merge( |
1434 |
- mysettings["CATEGORY"], mysettings["PF"], mysettings["D"], |
1435 |
- os.path.join(mysettings["PORTAGE_BUILDDIR"], "build-info"), |
1436 |
- myroot, mysettings, myebuild=mysettings["EBUILD"], mytree=tree, |
1437 |
- mydbapi=mydbapi, vartree=vartree, prev_mtimes=prev_mtimes) |
1438 |
- elif mydo=="merge": |
1439 |
- retval = spawnebuild("install", actionmap, mysettings, debug, |
1440 |
- alwaysdep=1, logfile=logfile, fd_pipes=fd_pipes, |
1441 |
- returnpid=returnpid) |
1442 |
- retval = exit_status_check(retval) |
1443 |
- if retval != os.EX_OK: |
1444 |
- # The merge phase handles this already. Callers don't know how |
1445 |
- # far this function got, so we have to call elog_process() here |
1446 |
- # so that it's only called once. |
1447 |
- from portage.elog import elog_process |
1448 |
- elog_process(mysettings.mycpv, mysettings) |
1449 |
- if retval == os.EX_OK: |
1450 |
- retval = merge(mysettings["CATEGORY"], mysettings["PF"], |
1451 |
- mysettings["D"], os.path.join(mysettings["PORTAGE_BUILDDIR"], |
1452 |
- "build-info"), myroot, mysettings, |
1453 |
- myebuild=mysettings["EBUILD"], mytree=tree, mydbapi=mydbapi, |
1454 |
- vartree=vartree, prev_mtimes=prev_mtimes) |
1455 |
- else: |
1456 |
- print(_("!!! Unknown mydo: %s") % mydo) |
1457 |
- return 1 |
1458 |
- |
1459 |
- return retval |
1460 |
- |
1461 |
- finally: |
1462 |
- |
1463 |
- if tmpdir: |
1464 |
- mysettings["PORTAGE_TMPDIR"] = tmpdir_orig |
1465 |
- shutil.rmtree(tmpdir) |
1466 |
- if builddir_lock: |
1467 |
- portage.locks.unlockdir(builddir_lock) |
1468 |
- |
1469 |
- # Make sure that DISTDIR is restored to it's normal value before we return! |
1470 |
- if "PORTAGE_ACTUAL_DISTDIR" in mysettings: |
1471 |
- mysettings["DISTDIR"] = mysettings["PORTAGE_ACTUAL_DISTDIR"] |
1472 |
- del mysettings["PORTAGE_ACTUAL_DISTDIR"] |
1473 |
- |
1474 |
- if logfile: |
1475 |
- try: |
1476 |
- if os.stat(logfile).st_size == 0: |
1477 |
- os.unlink(logfile) |
1478 |
- except OSError: |
1479 |
- pass |
1480 |
- |
1481 |
- if mydo in ("digest", "manifest", "help"): |
1482 |
- # If necessary, depend phase has been triggered by aux_get calls |
1483 |
- # and the exemption is no longer needed. |
1484 |
- _doebuild_manifest_exempt_depend -= 1 |
1485 |
- |
1486 |
-def _validate_deps(mysettings, myroot, mydo, mydbapi): |
1487 |
- |
1488 |
- invalid_dep_exempt_phases = \ |
1489 |
- set(["clean", "cleanrm", "help", "prerm", "postrm"]) |
1490 |
- dep_keys = ["DEPEND", "RDEPEND", "PDEPEND"] |
1491 |
- misc_keys = ["LICENSE", "PROPERTIES", "PROVIDE", "RESTRICT", "SRC_URI"] |
1492 |
- other_keys = ["SLOT"] |
1493 |
- all_keys = dep_keys + misc_keys + other_keys |
1494 |
- metadata = dict(zip(all_keys, |
1495 |
- mydbapi.aux_get(mysettings.mycpv, all_keys))) |
1496 |
- |
1497 |
- class FakeTree(object): |
1498 |
- def __init__(self, mydb): |
1499 |
- self.dbapi = mydb |
1500 |
- dep_check_trees = {myroot:{}} |
1501 |
- dep_check_trees[myroot]["porttree"] = \ |
1502 |
- FakeTree(fakedbapi(settings=mysettings)) |
1503 |
- |
1504 |
- msgs = [] |
1505 |
- for dep_type in dep_keys: |
1506 |
- mycheck = dep_check(metadata[dep_type], None, mysettings, |
1507 |
- myuse="all", myroot=myroot, trees=dep_check_trees) |
1508 |
- if not mycheck[0]: |
1509 |
- msgs.append(" %s: %s\n %s\n" % ( |
1510 |
- dep_type, metadata[dep_type], mycheck[1])) |
1511 |
- |
1512 |
- for k in misc_keys: |
1513 |
- try: |
1514 |
- portage.dep.use_reduce( |
1515 |
- portage.dep.paren_reduce(metadata[k]), matchall=True) |
1516 |
- except portage.exception.InvalidDependString as e: |
1517 |
- msgs.append(" %s: %s\n %s\n" % ( |
1518 |
- k, metadata[k], str(e))) |
1519 |
- |
1520 |
- if not metadata["SLOT"]: |
1521 |
- msgs.append(_(" SLOT is undefined\n")) |
1522 |
- |
1523 |
- if msgs: |
1524 |
- portage.util.writemsg_level(_("Error(s) in metadata for '%s':\n") % \ |
1525 |
- (mysettings.mycpv,), level=logging.ERROR, noiselevel=-1) |
1526 |
- for x in msgs: |
1527 |
- portage.util.writemsg_level(x, |
1528 |
- level=logging.ERROR, noiselevel=-1) |
1529 |
- if mydo not in invalid_dep_exempt_phases: |
1530 |
- return 1 |
1531 |
- |
1532 |
- return os.EX_OK |
1533 |
- |
1534 |
-expandcache={} |
1535 |
- |
1536 |
-======= |
1537 |
->>>>>>> .merge-right.r15449 |
1538 |
def _movefile(src, dest, **kwargs): |
1539 |
"""Calls movefile and raises a PortageException if an error occurs.""" |
1540 |
if movefile(src, dest, **kwargs) is None: |
1541 |
|
1542 |
Modified: main/branches/prefix/pym/portage/package/ebuild/doebuild.py |
1543 |
=================================================================== |
1544 |
--- main/branches/prefix/pym/portage/package/ebuild/doebuild.py 2010-02-27 18:30:51 UTC (rev 15478) |
1545 |
+++ main/branches/prefix/pym/portage/package/ebuild/doebuild.py 2010-02-27 18:53:28 UTC (rev 15479) |
1546 |
@@ -102,6 +102,7 @@ |
1547 |
# due to how it's coded... Don't overwrite this so we can use it. |
1548 |
mysettings["PORTAGE_DEBUG"] = "1" |
1549 |
|
1550 |
+ mysettings["EPREFIX"] = EPREFIX.rstrip(os.path.sep) |
1551 |
mysettings["EBUILD"] = ebuild_path |
1552 |
mysettings["O"] = pkg_dir |
1553 |
mysettings.configdict["pkg"]["CATEGORY"] = cat |
1554 |
@@ -192,8 +193,9 @@ |
1555 |
mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep |
1556 |
mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp") |
1557 |
|
1558 |
- # Prefix forward compatability |
1559 |
- mysettings["ED"] = mysettings["D"] |
1560 |
+ ## Prefix forward compatability |
1561 |
+ #mysettings["ED"] = mysettings["D"] |
1562 |
+ mysettings["ED"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image" + mysettings["EPREFIX"]) + os.sep |
1563 |
|
1564 |
mysettings["PORTAGE_BASHRC"] = os.path.join( |
1565 |
mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE) |
1566 |
@@ -209,7 +211,7 @@ |
1567 |
mydo in ('compile', 'config', 'configure', 'info', |
1568 |
'install', 'nofetch', 'postinst', 'postrm', 'preinst', |
1569 |
'prepare', 'prerm', 'setup', 'test', 'unpack'): |
1570 |
- mykv,err1=ExtractKernelVersion(os.path.join(myroot, "usr/src/linux")) |
1571 |
+ mykv,err1=ExtractKernelVersion(os.path.join(myroot, EPREFIX_LSTRIP, "usr/src/linux")) |
1572 |
if mykv: |
1573 |
# Regular source tree |
1574 |
mysettings["KV"]=mykv |
1575 |
|
1576 |
Modified: main/branches/prefix/pym/portage/package/ebuild/prepare_build_dirs.py |
1577 |
=================================================================== |
1578 |
--- main/branches/prefix/pym/portage/package/ebuild/prepare_build_dirs.py 2010-02-27 18:30:51 UTC (rev 15478) |
1579 |
+++ main/branches/prefix/pym/portage/package/ebuild/prepare_build_dirs.py 2010-02-27 18:53:28 UTC (rev 15479) |
1580 |
@@ -131,12 +131,12 @@ |
1581 |
|
1582 |
features_dirs = { |
1583 |
"ccache":{ |
1584 |
- "path_dir": "/usr/lib/ccache/bin", |
1585 |
+ "path_dir": EPREFIX+"/usr/lib/ccache/bin", |
1586 |
"basedir_var":"CCACHE_DIR", |
1587 |
"default_dir":os.path.join(mysettings["PORTAGE_TMPDIR"], "ccache"), |
1588 |
"always_recurse":False}, |
1589 |
"distcc":{ |
1590 |
- "path_dir": "/usr/lib/distcc/bin", |
1591 |
+ "path_dir": EPREFIX+"/usr/lib/distcc/bin", |
1592 |
"basedir_var":"DISTCC_DIR", |
1593 |
"default_dir":os.path.join(mysettings["BUILD_PREFIX"], ".distcc"), |
1594 |
"subdirs":("lock", "state"), |