1 |
commit: 689c79fc573879086aa809b62d9d4f4c8418f1fb |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue May 25 14:00:32 2021 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jun 11 17:48:06 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=689c79fc |
7 |
|
8 |
Use an explicit empty dir for pkg_* phases [WIP] |
9 |
|
10 |
Create and use an explicit ${PORTAGE_BUILDDIR}/empty as working |
11 |
directory for pkg_* phases, as proposed for EAPI 8. |
12 |
|
13 |
Note that this patch doesn't work fully -- empty is not cleared between |
14 |
pkg_preinst and pkg_postinst, and between pkg_prerm and pkg_postrm. |
15 |
|
16 |
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org> |
17 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
18 |
|
19 |
bin/ebuild.sh | 6 +++--- |
20 |
bin/phase-functions.sh | 3 ++- |
21 |
lib/_emerge/EbuildPhase.py | 5 ++++- |
22 |
lib/portage/package/ebuild/doebuild.py | 5 +++++ |
23 |
4 files changed, 14 insertions(+), 5 deletions(-) |
24 |
|
25 |
diff --git a/bin/ebuild.sh b/bin/ebuild.sh |
26 |
index c8fe3d0f1..2c3b985a9 100755 |
27 |
--- a/bin/ebuild.sh |
28 |
+++ b/bin/ebuild.sh |
29 |
@@ -186,9 +186,9 @@ export SANDBOX_ON=0 |
30 |
# Ensure that $PWD is sane whenever possible, to protect against |
31 |
# exploitation of insecure search path for python -c in ebuilds. |
32 |
# See bug #239560, bug #469338, and bug #595028. |
33 |
-if [[ -d ${HOME} ]]; then |
34 |
- # Use portage's temporary HOME directory if available. |
35 |
- cd "${HOME}" || die |
36 |
+# EAPI 8 requires us to use an empty directory here. |
37 |
+if [[ -d ${PORTAGE_BUILDDIR}/empty ]]; then |
38 |
+ cd "${PORTAGE_BUILDDIR}/empty" || die |
39 |
else |
40 |
cd "${PORTAGE_PYM_PATH}" || \ |
41 |
die "PORTAGE_PYM_PATH does not exist: '${PORTAGE_PYM_PATH}'" |
42 |
|
43 |
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh |
44 |
index 6a0300165..71411d414 100644 |
45 |
--- a/bin/phase-functions.sh |
46 |
+++ b/bin/phase-functions.sh |
47 |
@@ -278,7 +278,8 @@ __dyn_clean() { |
48 |
cd "${PORTAGE_PYM_PATH}" || \ |
49 |
die "PORTAGE_PYM_PATH does not exist: '${PORTAGE_PYM_PATH}'" |
50 |
|
51 |
- rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir" |
52 |
+ rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir" \ |
53 |
+ "${PORTAGE_BUILDDIR}/empty" |
54 |
rm -f "${PORTAGE_BUILDDIR}/.installed" |
55 |
|
56 |
if [[ $EMERGE_FROM = binary ]] || \ |
57 |
|
58 |
diff --git a/lib/_emerge/EbuildPhase.py b/lib/_emerge/EbuildPhase.py |
59 |
index 26c770d29..6c2e737c4 100644 |
60 |
--- a/lib/_emerge/EbuildPhase.py |
61 |
+++ b/lib/_emerge/EbuildPhase.py |
62 |
@@ -21,7 +21,7 @@ from portage.util._dyn_libs.soname_deps_qa import ( |
63 |
) |
64 |
from portage.package.ebuild.prepare_build_dirs import (_prepare_workdir, |
65 |
_prepare_fake_distdir, _prepare_fake_filesdir) |
66 |
-from portage.util import writemsg |
67 |
+from portage.util import writemsg, ensure_dirs |
68 |
from portage.util._async.AsyncTaskFuture import AsyncTaskFuture |
69 |
from portage.util._async.BuildLogger import BuildLogger |
70 |
from portage.util.futures import asyncio |
71 |
@@ -41,6 +41,7 @@ portage.proxy.lazyimport.lazyimport(globals(), |
72 |
'portage.elog:messages@elog_messages', |
73 |
'portage.package.ebuild.doebuild:_check_build_log,' + \ |
74 |
'_post_phase_cmds,_post_phase_userpriv_perms,' + \ |
75 |
+ '_post_phase_emptydir_cleanup,' + |
76 |
'_post_src_install_soname_symlinks,' + \ |
77 |
'_post_src_install_uid_fix,_postinst_bsdflags,' + \ |
78 |
'_post_src_install_write_metadata,' + \ |
79 |
@@ -89,6 +90,7 @@ class EbuildPhase(CompositeTask): |
80 |
'logging', self.phase)) |
81 |
except OSError: |
82 |
pass |
83 |
+ ensure_dirs(os.path.join(self.settings["PORTAGE_BUILDDIR"], "empty")) |
84 |
|
85 |
if self.phase in ('nofetch', 'pretend', 'setup'): |
86 |
|
87 |
@@ -270,6 +272,7 @@ class EbuildPhase(CompositeTask): |
88 |
|
89 |
settings = self.settings |
90 |
_post_phase_userpriv_perms(settings) |
91 |
+ _post_phase_emptydir_cleanup(settings) |
92 |
|
93 |
if self.phase == "unpack": |
94 |
# Bump WORKDIR timestamp, in case tar gave it a timestamp |
95 |
|
96 |
diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py |
97 |
index b1557edd7..0cbc2d01b 100644 |
98 |
--- a/lib/portage/package/ebuild/doebuild.py |
99 |
+++ b/lib/portage/package/ebuild/doebuild.py |
100 |
@@ -1770,6 +1770,11 @@ def _post_phase_userpriv_perms(mysettings): |
101 |
filemode=0o600, filemask=0) |
102 |
|
103 |
|
104 |
+def _post_phase_emptydir_cleanup(mysettings): |
105 |
+ empty_dir = os.path.join(mysettings["PORTAGE_BUILDDIR"], "empty") |
106 |
+ shutil.rmtree(empty_dir, ignore_errors=True) |
107 |
+ |
108 |
+ |
109 |
def _check_build_log(mysettings, out=None): |
110 |
""" |
111 |
Search the content of $PORTAGE_LOG_FILE if it exists |