aboutsummaryrefslogtreecommitdiff
path: root/lib/control.sh
blob: d8ceb9d898ddd4eec0c3ddca22e890b5b228e2df (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
182
183
184
185
186
187
188
189
190
#!/bin/bash
# 
#   Copyright (C) 2016 Linaro, Inc
# 
# This program 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 3 of the License, or
# (at your option) any later version.
# 
# This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 

# This file contains the logic which sequences the steps which are performed
# during a build

# build_steps is an associative array. The keys are the names of the enabled
# build steps
declare -A build_steps

# build_step_required indicates whether a step is required for the build to
# proceed further.
declare -A build_step_required

build_component_list=""
check_component_list=""

build_step_required[RETRIEVE]=1
build_step_RETRIEVE()
{
    retrieve_all "$build_component_list"
}


build_step_required[CHECKOUT]=1
build_step_CHECKOUT()
{
    checkout_all "$build_component_list"
}

build_step_required[MANIFEST]=1
build_step_MANIFEST()
{
    manifest="$(manifest)"
}

build_step_required[BUILD]=1
build_step_BUILD()
{
    build_all "$build_component_list"
}

build_step_HELLO_WORLD()
{
    if ! is_package_in_runtests "${build_component_list}" "stage2"; then
        notice "Hello World test skipped because stage2 was not built"
        return 0
    fi

    dryrun "(hello_world)"
    if test $? -eq 0; then
        notice "Hello World test succeeded"
        return 0
    fi

    error "Hello World test failed"
    return 1
}

build_step_CHECK()
{
    local check=""
    # Replace pseudo component names by the actual component name:
    # stage[12] -> gcc
    # libc -> newlib|glibc|eglibc
    local build_names="$(echo $build_component_list | sed -e 's/stage[12]/gcc/' -e s/\\blibc\\b/${clibrary}/)"
    local component
    for component in $check_component_list; do
        if is_package_in_runtests "${build_names}" "$component"; then
	    check="$check ${component}"
	fi
    done
    notice "Checking $check"
    check_all "$check"
}

build_step_INSTALL_SYSROOT()
{
    do_install_sysroot
}

build_step_TARSRC()
{
    do_tarsrc
}

build_step_TARBIN()
{
    do_tarbin
}

perform_build_steps()
{
    notice "enabled build steps (not in order): ${!build_steps[*]}"

    local step
    for step in RETRIEVE CHECKOUT MANIFEST BUILD CHECK INSTALL_SYSROOT HELLO_WORLD TARSRC TARBIN; do
        if [ ! -z "${build_steps[$step]}" ]; then
	    # this step is enabled
	    notice "Performing build step $step"
            eval "build_step_$step"
	    if test $? -ne 0; then
		error "Step $step failed"
		return 1
	    fi
	else
	    # this step is not enabled, so we finish here if it's a
	    # required step.
	    if [ ! -z "${build_step_required[$step]}" ]; then
		break
	    fi
	fi
    done
}

# convert high-level command line operations into the list of steps which
# must be performed.
#
# set_build_steps <checkout|build|tarsrc|tarbin|check>
#
set_build_steps()
{
    case "$1" in
	retrieve)
	    build_steps[RETRIEVE]=1
	    ;;
	checkout)
	    build_steps[RETRIEVE]=1
	    build_steps[CHECKOUT]=1
	    build_steps[MANIFEST]=1
	    ;;
	build)
	    build_steps[RETRIEVE]=1
	    build_steps[CHECKOUT]=1
	    build_steps[MANIFEST]=1
	    build_steps[BUILD]=1
	    build_steps[INSTALL_SYSROOT]=1
	    build_steps[HELLO_WORLD]=1
	    ;;
	tarsrc)
	    build_steps[TARSRC]=1
	    ;;
	tarbin)
	    build_steps[TARBIN]=1
	    ;;
	check)
	    build_steps[CHECK]=1
	    ;;
    esac
}

# set list of components to be checked out and built (if those steps are
# enabled in build_steps array)
set_build_component_list()
{
   build_component_list="$1"
}

get_build_component_list()
{
   echo "${build_component_list}"
}

# set list of components to be checked (make check) if CHECK build step is
# enabled in build_steps array)
set_check_component_list()
{
   check_component_list="$1"
}

get_check_component_list()
{
   echo "${check_component_list}"
}