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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
from _emerge.EbuildProcess import EbuildProcess
from _emerge.CompositeTask import CompositeTask
from portage.util import writemsg, writemsg_stdout
import portage
portage.proxy.lazyimport.lazyimport(globals(),
'portage.package.ebuild.doebuild:_check_build_log,' + \
'_post_phase_cmds,_post_phase_userpriv_perms,' + \
'_post_src_install_chost_fix,' + \
'_post_src_install_uid_fix'
)
from portage import os
from portage import _encodings
from portage import _unicode_decode
from portage import _unicode_encode
import codecs
class EbuildPhase(CompositeTask):
__slots__ = ("actionmap", "phase", "settings")
def _start(self):
if self.phase == 'prerm':
env_extractor = BinpkgEnvExtractor(background=self.background,
scheduler=self.scheduler, settings=self.settings)
if env_extractor.saved_env_exists():
self._start_task(env_extractor, self._env_extractor_exit)
return
# If the environment.bz2 doesn't exist, then ebuild.sh will
# source the ebuild as a fallback.
self._start_ebuild()
def _env_extractor_exit(self, env_extractor):
if self._default_exit(env_extractor) != os.EX_OK:
self._unlock_builddir()
self.wait()
return
self._start_ebuild()
def _start_ebuild(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.
logfile = self.settings.get("PORTAGE_LOG_FILE")
if self.phase in ("clean", "cleanrm"):
logfile = None
ebuild_process = EbuildProcess(actionmap=self.actionmap,
background=self.background, logfile=logfile,
phase=self.phase, scheduler=self.scheduler,
settings=self.settings)
self._start_task(ebuild_process, self._ebuild_exit)
def _ebuild_exit(self, ebuild_process):
fail = False
if self._default_exit(ebuild_process) != os.EX_OK:
if self.phase == "test" and \
"test-fail-continue" in self.settings.features:
pass
else:
fail = True
if not fail:
self.returncode = None
if self.phase == "install":
out = portage.StringIO()
log_path = self.settings.get("PORTAGE_LOG_FILE")
log_file = None
if log_path is not None:
log_file = codecs.open(_unicode_encode(log_path,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'], errors='replace')
try:
_check_build_log(self.settings, out=out)
msg = _unicode_decode(out.getvalue(),
encoding=_encodings['content'], errors='replace')
if msg:
if not self.background:
writemsg_stdout(msg, noiselevel=-1)
if log_file is not None:
log_file.write(msg)
finally:
if log_file is not None:
log_file.close()
if fail:
self._die_hooks()
return
settings = self.settings
_post_phase_userpriv_perms(settings)
if self.phase == "install":
out = portage.StringIO()
_post_src_install_chost_fix(settings)
_post_src_install_uid_fix(settings, out)
msg = _unicode_decode(out.getvalue(),
encoding=_encodings['content'], errors='replace')
if msg:
if not self.background:
writemsg_stdout(msg, noiselevel=-1)
log_path = self.settings.get("PORTAGE_LOG_FILE")
if log_path is not None:
log_file = codecs.open(_unicode_encode(log_path,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'], errors='replace')
log_file.write(msg)
log_file.close()
post_phase_cmds = _post_phase_cmds.get(self.phase)
if post_phase_cmds is not None:
post_phase = MiscFunctionsProcess(background=self.background,
commands=post_phase_cmds, phase=self.phase,
scheduler=self.scheduler, settings=settings)
self._start_task(post_phase, self._post_phase_exit)
return
self.returncode = ebuild_process.returncode
self._current_task = None
self.wait()
def _post_phase_exit(self, post_phase):
if self._final_exit(post_phase) != os.EX_OK:
writemsg("!!! post %s failed; exiting.\n" % self.phase,
noiselevel=-1)
self._die_hooks()
return
self._current_task = None
self.wait()
return
def _die_hooks(self):
self.returncode = None
phase = 'die_hooks'
die_hooks = MiscFunctionsProcess(background=self.background,
commands=[phase], phase=phase,
scheduler=self.scheduler, settings=self.settings)
self._start_task(die_hooks, self._die_hooks_exit)
def _die_hooks_exit(self, die_hooks):
if self.phase != 'clean' and \
'noclean' not in self.settings.features and \
'fail-clean' in self.settings.features:
self._default_exit(die_hooks)
self._fail_clean()
return
self._final_exit(die_hooks)
self.returncode = 1
self.wait()
def _fail_clean(self):
self.returncode = None
portage.elog.elog_process(self.settings.mycpv, self.settings)
phase = "clean"
clean_phase = EbuildPhase(background=self.background,
phase=phase, scheduler=self.scheduler, settings=self.settings)
self._start_task(clean_phase, self._fail_clean_exit)
return
def _fail_clean_exit(self, clean_phase):
self._final_exit(clean_phase)
self.returncode = 1
self.wait()
|