Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/2] Introduce multibuild_merge_root() to merge interim installs.
Date: Sat, 23 Mar 2013 16:26:04
Message-Id: 1364055998-23674-1-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES] Header wrapping support for multilib by "Michał Górny"
1 This is mostly a copy from distutils-r1. The function does copy all the
2 files from one location onto another, preserving whatever possible. It
3 can be run in parallel too without the risk of race conditions.
4 ---
5 gx86/eclass/distutils-r1.eclass | 41 +------------------------------------
6 gx86/eclass/multibuild.eclass | 45 +++++++++++++++++++++++++++++++++++++++++
7 2 files changed, 46 insertions(+), 40 deletions(-)
8
9 diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
10 index 0982e6c..3c21741 100644
11 --- a/gx86/eclass/distutils-r1.eclass
12 +++ b/gx86/eclass/distutils-r1.eclass
13 @@ -449,49 +449,10 @@ distutils-r1_python_install() {
14
15 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
16 _distutils-r1_rename_scripts "${root}"
17 - _distutils-r1_merge_root "${root}" "${D}"
18 + multibuild_merge_root "${root}" "${D}"
19 fi
20 }
21
22 -# @FUNCTION: distutils-r1_merge_root
23 -# @USAGE: <src-root> <dest-root>
24 -# @INTERNAL
25 -# @DESCRIPTION:
26 -# Merge the directory tree from <src-root> to <dest-root>, removing
27 -# the <src-root> in the process.
28 -_distutils-r1_merge_root() {
29 - local src=${1}
30 - local dest=${2}
31 -
32 - local lockfile=${T}/distutils-r1-merge-lock
33 -
34 - if type -P lockf &>/dev/null; then
35 - # On BSD, we have 'lockf' wrapper.
36 - tar -C "${src}" -f - -c . \
37 - | lockf "${lockfile}" tar -x -f - -C "${dest}"
38 - else
39 - local lock_fd
40 - if type -P flock &>/dev/null; then
41 - # On Linux, we have 'flock' which can lock fd.
42 - redirect_alloc_fd lock_fd "${lockfile}" '>>'
43 - flock ${lock_fd}
44 - else
45 - ewarn "distutils-r1: no locking service found, please report."
46 - fi
47 -
48 - cp -a -l -n "${src}"/. "${dest}"/
49 -
50 - if [[ ${lock_fd} ]]; then
51 - # Close the lock file when we are done with it.
52 - # Prevents deadlock if we aren't in a subshell.
53 - eval "exec ${lock_fd}>&-"
54 - fi
55 - fi
56 - [[ ${?} == 0 ]] || die "Merging ${EPYTHON} image failed."
57 -
58 - rm -rf "${src}"
59 -}
60 -
61 # @FUNCTION: distutils-r1_python_install_all
62 # @DESCRIPTION:
63 # The default python_install_all(). It installs the documentation.
64 diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
65 index a3f1402..ed837d3 100644
66 --- a/gx86/eclass/multibuild.eclass
67 +++ b/gx86/eclass/multibuild.eclass
68 @@ -238,5 +238,50 @@ run_in_build_dir() {
69 return ${ret}
70 }
71
72 +# @FUNCTION: multibuild_merge_root
73 +# @USAGE: <src-root> <dest-root>
74 +# @DESCRIPTION:
75 +# Merge the directory tree (fake root) from <src-root> to <dest-root>
76 +# (the real root). Both directories have to be real, absolute paths
77 +# (i.e. including ${D}). Source root will be removed.
78 +#
79 +# This functions uses locking to support merging during parallel
80 +# installs.
81 +multibuild_merge_root() {
82 + local src=${1}
83 + local dest=${2}
84 +
85 + local lockfile=${T}/multibuild_merge_lock
86 +
87 + if type -P lockf &>/dev/null; then
88 + # On BSD, we have 'lockf' wrapper.
89 + tar -C "${src}" -f - -c . \
90 + | lockf "${lockfile}" tar -x -f - -C "${dest}"
91 + else
92 + local lock_fd
93 + if type -P flock &>/dev/null; then
94 + # On Linux, we have 'flock' which can lock fd.
95 + redirect_alloc_fd lock_fd "${lockfile}" '>>'
96 + flock ${lock_fd}
97 + else
98 + ewarn "multibuild: no locking service found, please report."
99 + fi
100 +
101 + cp -a -l -n "${src}"/. "${dest}"/
102 +
103 + if [[ ${lock_fd} ]]; then
104 + # Close the lock file when we are done with it.
105 + # Prevents deadlock if we aren't in a subshell.
106 + eval "exec ${lock_fd}>&-"
107 + fi
108 + fi
109 +
110 + if [[ ${?} -ne 0 ]]; then
111 + die "${MULTIBUILD_VARIANT:-(unknown)}: merging image failed."
112 + fi
113 +
114 + rm -rf "${src}"
115 +}
116 +
117 _MULTIBUILD=1
118 fi
119 --
120 1.8.1.5

Replies