aboutsummaryrefslogtreecommitdiff
path: root/ebuild/ebuild.bash
blob: a23040fefa01e1ce7a64b3d010b75576c11e2d1d (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
#
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
# Gentoo Foundation and distributed under the terms of the GNU General
# Public License v2.
#
# 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

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

shopt -s expand_aliases

EBUILD_KILL_PID=$$
alias die='diefunc "$FUNCNAME" "$LINENO"'
alias assert='_pipestatus="${PIPESTATUS[*]}"; [[ -z "${_pipestatus//[ 0]/}" ]] || diefunc "$FUNCNAME" "$LINENO" "$_pipestatus"'
trap 'echo "die trap: exiting with error." 1>&2 ; exit 250' 15

diefunc()
{
    local func="$1" line="$2"
    shift 2
    echo 1>&2
    echo "ERROR in ${CATEGORY:-?}/${PF:-?}:" 1>&2
    echo "!!! In ${func:-?} at line ${line:-?}" 1>&2
    echo "!!! ${*:-(no message provided)}" 1>&2
    echo 1>&2

    kill ${EBUILD_KILL_PID}
    exit 249
}

EBUILD_MODULES_DIR=$(readlink -f $(dirname $0 ) )
[[ -d ${EBUILD_MODULES_DIR} ]] || die "${EBUILD_MODULES_DIR} is not a directory"
export PALUDIS_EBUILD_MODULES_DIR="${EBUILD_MODULES_DIR}"

ebuild_load_module()
{
    source "${EBUILD_MODULES_DIR}/${1}.bash" || die "Error loading module ${1}"
}

source /sbin/functions.sh || die "Couldn't source functions.sh"
ebuild_load_module echo_functions
ebuild_load_module sandbox_stubs
ebuild_load_module portage_stubs
ebuild_load_module list_functions
ebuild_load_module multilib_functions
ebuild_load_module install_functions
ebuild_load_module build_functions
ebuild_load_module unpack_functions
ebuild_load_module eclass_functions

ebuild_source_profile()
{
    if [[ -f ${1}/make.defaults ]] ; then
        source ${1}/make.defaults || die "Couldn't source ${1}/make.defaults"
    fi

    if [[ -f ${1}/bashrc ]] ; then
        source ${1}/bashrc || die "Couldn't source ${1}/bashrc"
    fi

    if [[ -f ${1}/parent ]] ; then
        ebuild_source_profile $(readlink -f ${1}/$(< ${1}/parent) )
    fi
}

save_vars="USE USE_EXPAND"

for var in ${save_vars} ; do
    eval "export save_var_${var}='${!var}'"
done

if [[ -n "${PALUDIS_PROFILE_DIR}" ]] ; then
    ebuild_source_profile $(readlink -f "${PALUDIS_PROFILE_DIR}")
fi

unset ${save_vars}

for f in ${PALUDIS_BASHRC_FILES} ; do
    if [[ -f ${f} ]] ; then
        ebuild_notice "debug" "Loading bashrc file ${f}"
        source ${f}
    else
        ebuild_notice "debug" "Skipping bashrc file ${f}"
    fi
done

for var in ${save_vars}; do
    if [[ -n ${!var} ]]; then
        die "${var} should not be set in bashrc. Aborting."
    fi
done

for var in ${save_vars} ; do
    eval "export ${var}=\${save_var_${var}}"
done

ebuild_load_ebuild()
{
    export EBUILD="${1}"
    if [[ "${CATEGORY}" == "virtual" ]] ; then
        if [[ -f "${1}" ]] ; then
            source ${1} || die "Error sourcing ebuild '${1}'"
        elif [[ -e "${1}" ]] ; then
            die "'${1}' exists but is not a regular file"
        fi
    else
        [[ -f "${1}" ]] || die "Ebuild '${1}' is not a file"
        source ${1} || die "Error sourcing ebuild '${1}'"
    fi
    [[ ${RDEPEND-unset} == "unset" ]] && RDEPEND="${DEPEND}"
}

ebuild_main()
{
    local action ebuild="$1"
    shift

    for action in $@ ; do
        case ${action} in
            metadata)
                ebuild_load_module depend
                ;;

            init|fetch|merge|unmerge|tidyup|strip)
                ebuild_load_module builtin_${action}
            ;;

            unpack|compile|install|test)
                ebuild_load_module src_${action}
            ;;

            setup|config|nofetch|preinst|postinst|prerm|postrm)
                ebuild_load_module pkg_${action}
            ;;

            *)
                ebuild_load_module usage_error
                ebuild_f_usage_error "Unknown action '${action}'"
                exit 1
            ;;
        esac
    done

    if [[ $1 == metadata ]] ; then
        for f in cut tr ; do
            eval "export ebuild_real_${f}=\"$(which $f )\""
            eval "${f}() { ebuild_notice qa 'global scope ${f}' ; $(which $f ) \"\$@\" ; }"
        done
        PATH="" ebuild_load_ebuild "${ebuild}"
        ebuild_f_depend || die "${1} failed"
    else
        ebuild_load_ebuild "${ebuild}"
        for action in $@ ; do
            ebuild_f_${action} || die "${action} failed"
            if [[ ${action} == "init" ]] ; then
                ebuild_load_ebuild "${ebuild}"
            fi
        done
    fi
}

ebuild_main $@