summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/EbuildProcess.py
blob: 50edaa16d45249bfd97a9a1776aec1f9746f2751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
import portage
portage.proxy.lazyimport.lazyimport(globals(),
	'portage.package.ebuild.doebuild:_post_phase_userpriv_perms,' + \
		'_spawn_actionmap,spawn@doebuild_spawn'
)
from portage import _shell_quote
from portage import os
from portage.const import EBUILD_SH_BINARY

class EbuildProcess(AbstractEbuildProcess):

	__slots__ = ('actionmap',)

	_unsandboxed_phases = frozenset([
		"clean", "cleanrm", "config",
		"help", "info", "postinst",
		"preinst", "pretend", "postrm",
		"prerm", "setup"])

	def _start(self):
		# Don't open the log file during the clean phase since the
		# open file can result in an nfs lock on $T/build.log which
		# prevents the clean phase from removing $T.
		if self.phase not in ("clean", "cleanrm"):
			self.logfile = self.settings.get("PORTAGE_LOG_FILE")
		AbstractEbuildProcess._start(self)

	def _spawn(self, args, **kwargs):
		self.settings["EBUILD_PHASE"] = self.phase
		if self.phase in self._unsandboxed_phases:
			kwargs['free'] = True
		if self.phase == 'depend':
			kwargs['droppriv'] = 'userpriv' in self.settings.features
		actionmap = self.actionmap
		if actionmap is None:
			actionmap = _spawn_actionmap(self.settings)
		if self.phase in actionmap:
			kwargs.update(actionmap[self.phase]["args"])
			cmd = actionmap[self.phase]["cmd"] % self.phase
		else:
			if self.phase == 'cleanrm':
				ebuild_sh_arg = 'clean'
			else:
				ebuild_sh_arg = self.phase

			cmd = "%s %s" % (_shell_quote(os.path.join(
				self.settings["PORTAGE_BIN_PATH"],
				os.path.basename(EBUILD_SH_BINARY))), ebuild_sh_arg)
		try:
			return doebuild_spawn(cmd, self.settings, **kwargs)
		finally:
			self.settings.pop("EBUILD_PHASE", None)

	def _set_returncode(self, wait_retval):
		AbstractEbuildProcess._set_returncode(self, wait_retval)

		if self.phase == "test" and self.returncode != os.EX_OK and \
			"test-fail-continue" in self.settings.features:
			self.returncode = os.EX_OK

		_post_phase_userpriv_perms(self.settings)