aboutsummaryrefslogtreecommitdiffstats
path: root/test-compilation.sh
blob: 0c64bd51085e03177d8ce59f1d769d920a6bcaa0 (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
#!/bin/bash

## ==========================================================================
#                               _         __
#                              (_)____   / /_   _____
#                             / // __ \ / __ \ / ___/
#                            / // /_/ // /_/ /(__  )
#                         __/ / \____//_.___//____/
#                        /___/
## ==========================================================================


prepare()
{
    project="${1}"
    slot="${2}"
    project_dir="${3}"

    # clone
    if ! git clone "${project_dir}" "${project}-${slot}"
    then
        echo "couldn't clone, sorry"
        exit 1
    fi

    # prepare directory for distcheck, we need to at least once call autogen
    # and configure (doesn't matter with what parameters

    cd "${project}-${slot}"
    ./autogen.sh
    ./configure
}

build()
{
    opts="${1}"
    project="${2}"
    slot="${3}"
    project_dir="${4}"

    cd "${project}-${slot}"
    export AM_DISTCHECK_CONFIGURE_FLAGS="${opts}"
    make distcheck
    ret=${?}

    if [ ${ret} -eq 0 ]
    then
        echo "[ok]   ${opts}" >> "${project_dir}/compilation-test-results"
    else
        echo "[nok]  ${opts}" >> "${project_dir}/compilation-test-results"
    fi
}


## ==========================================================================
#                                                      __   _
#       ____   _____ ___   ____   ____ _ _____ ____ _ / /_ (_)____   ____
#      / __ \ / ___// _ \ / __ \ / __ `// ___// __ `// __// // __ \ / __ \
#     / /_/ // /   /  __// /_/ // /_/ // /   / /_/ // /_ / // /_/ // / / /
#    / .___//_/    \___// .___/ \__,_//_/    \__,_/ \__//_/ \____//_/ /_/
#   /_/                /_/
## ==========================================================================


workdir="/tmp/parallel-test-compilation"
combination_file="${workdir}/combinations"
project="embedlog"
optfile="test-compilation-options"
project_dir="$(dirname "${0}")"
cd "${project_dir}"
project_dir="$(pwd)"

export -f build
export -f prepare

if [ ${#} -ne 1 ]
then
    echo "usage ${0} <number-of-jobs>"
    exit 1
fi

num_jobs=${1}

# some sanity checks

if [ ${num_jobs} -ne ${num_jobs} ]
then
    echo "num jobs is garbage: ${num_jobs}"
    exit 1
fi

if [ ! -f "${optfile}" ]
then
    echo "file with options doesn't exist"
    exit 1
fi


## ==========================================================================
#                                __                __
#                         _____ / /_ ____ _ _____ / /_
#                        / ___// __// __ `// ___// __/
#                       (__  )/ /_ / /_/ // /   / /_
#                      /____/ \__/ \__,_//_/    \__/
#
## ==========================================================================


mapfile -t options < "${optfile}"

# distcheck (when failed) leave readonly files which cannot be deleted
chmod u+rwx -R "${workdir}"
rm -rf "${workdir}"
mkdir "${workdir}"
cd "${workdir}"
pwd

# generate all combination of build options

iterations=$((2**${#options[@]} - 1))
echo -n "" > "${combination_file}"
for i in $(seq 0 1 $iterations)
do
    opts=
    flags=`echo "obase=2;${i}" | bc | rev`
    for j in `seq 1 1 ${#flags}`
    do
        if [ "${flags:j-1:1}" == "1" ]
        then
            opts+="${options[j - 1]} "
        fi
    done
    echo "${opts}" >> "${combination_file}"
    echo -ne "\rgenerating combinations ${i}/${iterations}"
done

# remove traling spaces from our combination files
sed -i 's/[ ]*$//' "${combination_file}"

echo ""

# ok, so first we need to clone as many directories as many jobs in parallel
# will be run, it's because of the make distcheck that has harcoded values and
# it won't work in parallel in same directory as another distcheck

slots=
for i in $(seq 1 1 ${num_jobs})
do
    slots+="${i} "
done

# run preparation
parallel --output-as-files --bar --results "${workdir}" \
    --halt-on-error now,fail=1 --jobs ${num_jobs} \
    prepare ::: "${project}" ::: ${slots} ::: "${project_dir}"

# and run distcheck tests, will take a loooong time
cat ${combination_file} | parallel --output-as-files --bar \
    --results "${workdir}" --halt-on-error now,fail=1 --jobs ${num_jobs} \
    build {} "${project}" {%} "${project_dir}"