aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/ebuild/builtin_merge.bash
blob: ef3103faf11c71df52160d432e5324c2f04007fe (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
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
#!/bin/bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA

builtin_merge()
{
    ebuild_section "Merging to '${ROOT:-/}'..."

    shopt -q dotglob
    local olddotglob=$?
    shopt -s dotglob

    local v=$(vdb_path)
    if [[ -z "${v}" ]] ; then
        v=${ROOT}/var/db/pkg
    fi
    local dbdir="${v}/${CATEGORY}/${PF}"
    ebuild_section "Writing VDB entry to '${dbdir}'..."
    install -d "${dbdir}" || die "couldn't make pkg db directory (\"${dbdir}\")"
    install -d "${v}/".cache || die "couldn't make pkg db cache"

    local v VDB_FORMAT="paludis-2" COUNTER="0"
    for v in CATEGORY CBUILD CHOST COUNTER DEPEND DESCRIPTION EAPI \
        FEATURES HOMEPAGE INHERITED IUSE KEYWORDS LICENSE PDEPEND PF \
        PROVIDE RDEPEND SLOT SRC_URI USE CONFIG_PROTECT CONFIG_PROTECT_MASK \
        VDB_FORMAT PKGMANAGER ; do
        echo "${!v}" > "${dbdir}"/${v} || die "pkg db write ${v} failed"
        ebuild_notice "debug" "Writing VDB key ${v}=${!v}"
    done
    for v in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX CXXFLAGS \
        EXTRA_ECONF EXTRA_EINSTALL EXTRA_EMAKE LDFLAGS LIBCXXFLAGS \
        REPOSITORY ; do
        [[ -z "${!v}" ]] && continue
        echo "${!v}" > "${dbdir}"/${v} || die "pkg db write ${v} failed"
        ebuild_notice "debug" "Writing VDB key ${v}=${!v}"
    done

    if [[ -n ${PALUDIS_EBUILD_OVERRIDE_CONFIG_PROTECT} ]]; then
        CONFIG_PROTECT=${PALUDIS_EBUILD_OVERRIDE_CONFIG_PROTECT}
    fi
    if [[ -n ${PALUDIS_EBUILD_OVERRIDE_CONFIG_PROTECT_MASK} ]]; then
        CONFIG_PROTECT_MASK=${PALUDIS_EBUILD_OVERRIDE_CONFIG_PROTECT_MASK}
    fi

    export CONFIG_PROTECT="${CONFIG_PROTECT}"
    export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK}"

    [[ -f "${EBUILD}" ]] && cp "${EBUILD}" ${dbdir}/

    local reinstall=
    if [[ -f "${dbdir}/CONTENTS" ]] ; then
        mv "${dbdir}/CONTENTS" "${dbdir}/OLDCONTENTS" || die "save contents failed"
        reinstall="yes"
    fi

    ebuild_notice "debug" "Writing VDB environment.bz2"
    for v in ${USE_EXPAND} ; do
        ebuild_notice "debug" "USE_EXPAND ${v}=${!v}"
    done
    ( set ; export -p | sed 's:^declare -rx:declare -x:' ) | bzip2 > ${dbdir}/environment.bz2
    > ${dbdir}/CONTENTS

    if [[ -n "${D}" ]] && [[ -d "${D}" ]] ; then
        install -d "${ROOT%/}/" || die "couldn't make \${ROOT} (\"${ROOT}\")"
        if [[ -d "${D}" ]] ; then
            merge "${D%/}/" "${ROOT%/}/" "${dbdir}/CONTENTS" \
                || die "merge failed"
        fi
    fi

    if ! /bin/sh -c 'echo Good, our shell is still usable' ; then
        echo "Looks like our shell broke. Trying an ldconfig to fix it..."
        ldconfig -r ${ROOT}
    fi

    if [[ -n "${reinstall}" ]] ; then
        unmerge "${ROOT%/}/" "${dbdir}/OLDCONTENTS" \
            || die "unmerge failed"

        if ! /bin/sh -c 'echo Good, our shell is still usable' ; then
            echo "Looks like our shell broke. Trying an ldconfig to fix it..."
            ldconfig -r ${ROOT}
        fi

        rm -f "${dbdir}/OLDCONTENTS"
    fi

    [[ $olddotglob != 0 ]] && shopt -u dotglob
    shopt -q dotglob
    [[ $olddotglob == $? ]] || ebuild_notice "warning" "shopt dotglob restore failed"
}

ebuild_f_merge()
{
    local old_sandbox_write="${SANDBOX_WRITE}"
    SANDBOX_WRITE="${SANDBOX_WRITE+${SANDBOX_WRITE}:}${ROOT%/}/"
    local old_sandbox_on="${SANDBOX_ON}"
    [[ "$(canonicalise ${ROOT} )" != "/" ]] || SANDBOX_ON=0

    if hasq "merge" ${RESTRICT} ; then
        ebuild_section "Skipping builtin_merge (RESTRICT)"
    elif hasq "merge" ${SKIP_FUNCTIONS} ; then
        ebuild_section "Skipping builtin_merge (SKIP_FUNCTIONS)"
    else
        ebuild_section "Starting builtin_merge"
        builtin_merge
        ebuild_section "Done builtin_merge"
    fi

    SANDBOX_WRITE="${old_sandbox_write}"
    SANDBOX_ON="${old_sandbox_on}"
}