aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/ebuild/write_vdb_entry.bash
blob: 001457412ea8af7c7cac63d5157e355897dca964 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
#
# 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, version 2, as published by the Free Software Foundation.
#
# 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

unalias -a
set +C
unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
eval unset LANG ${!LC_*}

shopt -s expand_aliases
shopt -s extglob

if [[ -n "${PALUDIS_EBUILD_DIR_FALLBACK}" ]] ; then
    export PATH="${PALUDIS_EBUILD_DIR_FALLBACK}/utils:${PATH}"
fi
export PATH="${PALUDIS_EBUILD_DIR}/utils:${PATH}"
for p in ${PALUDIS_UTILITY_PATH_SUFFIXES} ; do
    export PATH="${PALUDIS_EBUILD_DIR}/utils/${p}:${PATH}"
done

# Force a few more things into PATH, since some users have crazy setups.
# See ticket:374.
export PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin"

EBUILD_MODULES_DIR=$(canonicalise $(dirname $0 ) )
if ! [[ -d ${EBUILD_MODULES_DIR} ]] ; then
    echo "${EBUILD_MODULES_DIR} is not a directory" 1>&2
    exit 123
fi

[[ -z "${PALUDIS_EBUILD_MODULE_SUFFIXES}" ]] && PALUDIS_EBUILD_MODULE_SUFFIXES=0
for p in ${PALUDIS_EBUILD_MODULE_SUFFIXES}; do
    EBUILD_MODULES_DIRS="${EBUILD_MODULES_DIRS} ${EBUILD_MODULES_DIR}/${p}"
done
for p in ${PALUDIS_EXTRA_EBUILD_MODULES_DIRS} ; do
    EBUILD_MODULES_DIRS="${EBUILD_MODULES_DIRS} ${p}"
done
EBUILD_MODULES_DIRS="${EBUILD_MODULES_DIRS} ${EBUILD_MODULES_DIR}"

export PALUDIS_EBUILD_MODULES_DIR="${EBUILD_MODULES_DIR}"

ebuild_load_module()
{
    for d in ${EBUILD_MODULES_DIRS}; do
        if [[ -f "${d}/${1}.bash" ]]; then
            if ! source "${d}/${1}.bash"; then
                type die &>/dev/null && eval die "\"Error loading module \${1}\""
                echo "Error loading module ${1}" 1>&2
                exit 123
            fi
            return
        fi
    done
    type die &>/dev/null && eval die "\"Couldn't find module \${1}\""
    echo "Couldn't find module ${1}" 1>&2
    exit 123
}

ebuild_load_module die_functions
ebuild_load_module 0/output_functions
ebuild_load_module echo_functions
ebuild_load_module source_functions

export PALUDIS_HOME="$(canonicalise ${PALUDIS_HOME:-${HOME}} )"

main()
{
    local vdbdir="${1}" envfile="${2}"

    if ! [[ -d "${vdbdir}" ]] ; then
        echo "!!! vdbdir \"${vdbdir}\" is not a directory"
        exit 1
    fi

    ebuild_section "Writing VDB entry to '${vdbdir}'..."

    ebuild_safe_source ${envfile}

    ebuild_section "Writing VDB entry keys ..."

    if [[ -z "${PALUDIS_VDB_FROM_ENV_VARIABLES}" ]] ; then
        ebuild_notice "warning" "VDB_FROM_ENV_VARIABLES not set, using defaults"
        PALUDIS_VDB_FROM_ENV_VARIABLES="\
            CATEGORY 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"
    fi

    if [[ -z "${PALUDIS_VDB_FROM_ENV_UNLESS_EMPTY_VARIABLES}" ]] ; then
        ebuild_notice "warning" "PALUDIS_VDB_FROM_ENV_UNLESS_EMPTY_VARIABLES not set, using defaults"
        PALUDIS_VDB_FROM_ENV_UNLESS_EMPTY_VARIABLES="\
            ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX CXXFLAGS \
            EXTRA_ECONF EXTRA_EINSTALL EXTRA_EMAKE LDFLAGS LIBCXXFLAGS \
            REPOSITORY"
    fi

    local new_IUSE i
    for i in ${IUSE} ; do
        new_IUSE="${new_IUSE} ${i#[+-]}"
    done
    IUSE="${new_IUSE}"

    local v VDB_FORMAT="paludis-2" COUNTER="$(date +%s )"
    for v in ${PALUDIS_VDB_FROM_ENV_VARIABLES} ; do
        if ! paludis_rewrite_var VDB "${v}" "${!v}" > "${vdbdir}"/${v} ; then
            echo "!!! vdb write ${v} failed"
            exit 1
        fi
    done

    for v in ${PALUDIS_VDB_FROM_ENV_UNLESS_EMPTY_VARIABLES} ; do
        [[ -z "${!v}" ]] && continue
        if ! paludis_rewrite_var VDB "${v}" "${!v}" > "${vdbdir}"/${v} ; then
            echo "!!! vdb write ${v} failed"
            exit 1
        fi
    done

    ebuild_section "Generating saved ebuild and environment..."

    [[ -f "${EBUILD}" ]] && cp "${EBUILD}" ${vdbdir}/
    bzip2 < ${envfile} > ${vdbdir}/environment.bz2

    ebuild_section "Finished writing VDB entry"

    true
}

main $@