From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: ulm@gentoo.org, zmedico@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] Introduce multibuild_merge_root() to merge interim installs.
Date: Mon, 25 Mar 2013 23:42:50 +0100 [thread overview]
Message-ID: <1364251370-1579-1-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <20813.57273.945749.854552@a1i15.kph.uni-mainz.de>
This is mostly a copy from distutils-r1. The function does copy all the
files from one location onto another, preserving whatever possible. It
can be run in parallel too without the risk of race conditions.
As suggested by Ulrich and Zac, I've modified the code to use checks
based on userland rather than tool checking. The code supports BSD and
GNU userlands as defined in the profiles. With any other userland, it
explicitly dies.
---
gx86/eclass/distutils-r1.eclass | 41 +-------------------------------
gx86/eclass/multibuild.eclass | 52 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 40 deletions(-)
diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
index 0982e6c..3c21741 100644
--- a/gx86/eclass/distutils-r1.eclass
+++ b/gx86/eclass/distutils-r1.eclass
@@ -449,49 +449,10 @@ distutils-r1_python_install() {
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
_distutils-r1_rename_scripts "${root}"
- _distutils-r1_merge_root "${root}" "${D}"
+ multibuild_merge_root "${root}" "${D}"
fi
}
-# @FUNCTION: distutils-r1_merge_root
-# @USAGE: <src-root> <dest-root>
-# @INTERNAL
-# @DESCRIPTION:
-# Merge the directory tree from <src-root> to <dest-root>, removing
-# the <src-root> in the process.
-_distutils-r1_merge_root() {
- local src=${1}
- local dest=${2}
-
- local lockfile=${T}/distutils-r1-merge-lock
-
- if type -P lockf &>/dev/null; then
- # On BSD, we have 'lockf' wrapper.
- tar -C "${src}" -f - -c . \
- | lockf "${lockfile}" tar -x -f - -C "${dest}"
- else
- local lock_fd
- if type -P flock &>/dev/null; then
- # On Linux, we have 'flock' which can lock fd.
- redirect_alloc_fd lock_fd "${lockfile}" '>>'
- flock ${lock_fd}
- else
- ewarn "distutils-r1: no locking service found, please report."
- fi
-
- cp -a -l -n "${src}"/. "${dest}"/
-
- if [[ ${lock_fd} ]]; then
- # Close the lock file when we are done with it.
- # Prevents deadlock if we aren't in a subshell.
- eval "exec ${lock_fd}>&-"
- fi
- fi
- [[ ${?} == 0 ]] || die "Merging ${EPYTHON} image failed."
-
- rm -rf "${src}"
-}
-
# @FUNCTION: distutils-r1_python_install_all
# @DESCRIPTION:
# The default python_install_all(). It installs the documentation.
diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
index a3f1402..1152245 100644
--- a/gx86/eclass/multibuild.eclass
+++ b/gx86/eclass/multibuild.eclass
@@ -238,5 +238,57 @@ run_in_build_dir() {
return ${ret}
}
+# @FUNCTION: multibuild_merge_root
+# @USAGE: <src-root> <dest-root>
+# @DESCRIPTION:
+# Merge the directory tree (fake root) from <src-root> to <dest-root>
+# (the real root). Both directories have to be real, absolute paths
+# (i.e. including ${D}). Source root will be removed.
+#
+# This functions uses locking to support merging during parallel
+# installs.
+multibuild_merge_root() {
+ local src=${1}
+ local dest=${2}
+
+ local lockfile=${T}/multibuild_merge_lock
+ local ret
+
+ if use userland_BSD; then
+ # Locking is done by 'lockf' which can wrap a command.
+ # 'cp -a -n' is broken:
+ # http://www.freebsd.org/cgi/query-pr.cgi?pr=174489
+ # using tar instead which is universal but terribly slow.
+
+ tar -C "${src}" -f - -c . \
+ | lockf "${lockfile}" tar -x -f - -C "${dest}"
+ [[ ${PIPESTATUS[*]} == '0 0' ]]
+ ret=${?}
+ elif use userland_GNU; then
+ # GNU has 'flock' which can't wrap commands but can lock
+ # a fd which is good enough for us.
+ # and cp works with '-a -n'.
+
+ local lock_fd
+ redirect_alloc_fd lock_fd "${lockfile}" '>>'
+ flock ${lock_fd}
+
+ cp -a -l -n "${src}"/. "${dest}"/
+ ret=${?}
+
+ # Close the lock file when we are done with it.
+ # Prevents deadlock if we aren't in a subshell.
+ eval "exec ${lock_fd}>&-"
+ else
+ die "Unsupported userland (${USERLAND}), please report."
+ fi
+
+ if [[ ${ret} -ne 0 ]]; then
+ die "${MULTIBUILD_VARIANT:-(unknown)}: merging image failed."
+ fi
+
+ rm -rf "${src}"
+}
+
_MULTIBUILD=1
fi
--
1.8.1.5
next prev parent reply other threads:[~2013-03-25 22:42 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-23 16:25 [gentoo-dev] [PATCHES] Header wrapping support for multilib Michał Górny
2013-03-23 16:26 ` [gentoo-dev] [PATCH 1/2] Introduce multibuild_merge_root() to merge interim installs Michał Górny
2013-03-23 17:00 ` Ulrich Mueller
2013-03-23 17:28 ` Michał Górny
2013-03-24 7:47 ` Ulrich Mueller
2013-03-24 10:09 ` Michał Górny
2013-03-24 13:40 ` Ulrich Mueller
2013-03-24 14:13 ` Michał Górny
2013-03-24 20:18 ` Zac Medico
2013-03-25 22:42 ` Michał Górny [this message]
2013-03-23 17:44 ` Alec Warner
2013-03-23 18:57 ` Michał Górny
2013-03-23 18:57 ` [gentoo-dev] " Jonathan Callen
2013-03-23 19:02 ` Alec Warner
2013-03-23 16:26 ` [gentoo-dev] [PATCH 2/2] Support wrapping headers for multilib ABIs Michał Górny
2013-03-24 15:14 ` Alexis Ballier
2013-03-24 15:41 ` Michał Górny
2013-03-24 20:01 ` Alexis Ballier
2013-03-25 22:22 ` [gentoo-dev] [PATCH] " Michał Górny
2013-03-23 16:46 ` [gentoo-dev] [PATCHES] Header wrapping support for multilib Diego Elio Pettenò
2013-03-23 17:32 ` Michał Górny
2013-03-23 17:32 ` Diego Elio Pettenò
2013-03-23 19:56 ` [gentoo-dev] [PATCH] Support wrapping headers for multilib ABIs Michał Górny
2013-03-23 20:03 ` Michał Górny
2013-03-23 22:01 ` [gentoo-dev] " Jonathan Callen
2013-04-01 9:19 ` [gentoo-dev] [PATCHES] Header wrapping support for multilib Michał Górny
2013-04-02 10:59 ` Alexis Ballier
2013-04-02 11:47 ` Michał Górny
2013-04-04 8:07 ` Alexis Ballier
2013-04-04 17:53 ` Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364251370-1579-1-git-send-email-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
--cc=ulm@gentoo.org \
--cc=zmedico@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox