-
Notifications
You must be signed in to change notification settings - Fork 0
/
yast-travis-cpp
executable file
·194 lines (167 loc) · 4.94 KB
/
yast-travis-cpp
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
191
192
193
194
#! /bin/bash
# This is a CI build script for running inside the Travis builds.
# It's designed for the YaST packages written in C++.
# exit on error immediately
set -e
# all known steps in this script
ALL_STEPS="pot, spelling, package, perl_syntax"
# when adding a new step
# 1) add it to $ALL_STEPS
# 2) handle it in disable_all(), set_defaults(), exclude(), run_only()
# and dump_settings()
# 3) run it in the "main" part
function usage() {
echo "Usage: $0 [OPTIONS]"
echo
echo "OPTIONS:"
echo -e "\\t -x <step> \\t exclude the specified step"
echo -e "\\t -o <step> \\t run only the specified step"
echo -e "\\t -d \\t enable debug mode"
echo -e "\\t -h \\t print this help"
echo
echo "The known steps are: $ALL_STEPS"
echo
echo "The script analyzes the configuration files and runs the checks accordingly."
echo "You can manually override the autodection using the -x or -o option."
echo
echo "Options -x and -o are exclusive and cannot be used together,"
echo "but they can be used repeatedly to specify several steps."
}
# disable all steps
function disable_all() {
# run this only once
if [ "$DISABLE_ALL" != "1" ]; then
RUN_CHECK_PERL=0
RUN_BUILD_PACKAGE=0
DISABLE_ALL=1
fi
}
# set defaults, run everything possible
function set_defaults() {
# run the perl syntax check by default when there is at least one Perl file
if [ -n "$(find . -type f -name '*.p[ml]' -print -quit)" ]; then
RUN_CHECK_PERL=1
else
RUN_CHECK_PERL=0
fi
RUN_BUILD_PACKAGE=1
}
function exclude() {
if [ "$RUN_ONLY_USED" == "1" ]; then
echo "ERROR: Options -x -o are exclusive and cannot be used together!"
exit 1
fi
case $1 in
package)
RUN_BUILD_PACKAGE=0
;;
perl_syntax)
RUN_CHECK_PERL=0
;;
*)
echo "ERROR: Unknown step: '$1'"
echo "Known steps: $ALL_STEPS"
exit 1
esac
EXCLUDE_USED=1
}
function run_only() {
if [ "$EXCLUDE_USED" == "1" ]; then
echo "ERROR: Options -x -o are exclusive and cannot be used together!"
exit 1
fi
# disable the other steps
disable_all
case $1 in
package)
RUN_BUILD_PACKAGE=1
;;
perl_syntax)
RUN_CHECK_PERL=1
;;
*)
echo "ERROR: Unknown step: '$1'"
echo "Known steps: $ALL_STEPS"
exit 1
esac
RUN_ONLY_USED=1
}
function dump_settings() {
echo "Script configuration:"
echo "RUN_CHECK_PERL: $RUN_CHECK_PERL"
echo "RUN_BUILD_PACKAGE: $RUN_BUILD_PACKAGE"
echo
}
# check the syntax of the perl files
function check_perl() {
# Perl allows checking the syntax only for one file at once, we need to use -n1
# xargs option, to speed it up run the checks in parallel (-P option).
# If you need to specify an additional search path use the PERL5LIB environment variable.
find . -type f -name '*.p[ml]' -print0 \
| xargs -0 -P"$(nproc)" -n1 perl -I src/modules -I /usr/share/YaST2/modules -w -c
}
# initializa the defaults and parse the command line options
set_defaults
while getopts ":x:o:dhy" arg; do
case $arg in
x)
exclude "$OPTARG"
;;
o)
run_only "$OPTARG"
;;
h)
usage
exit 0
;;
d)
DEBUG=1
;;
*)
usage
exit 1
;;
esac
done
# start the main script
# enable debug
if [ "$DEBUG" == "1" ]; then
dump_settings
set -x
fi
# run syntax check for the perl files
[ "$RUN_CHECK_PERL" == "1" ] && check_perl
# the rest is a package build if it is disabled then just finish now
[ "$RUN_BUILD_PACKAGE" == "0" ] && exit 0
# Build the binary package locally, use plain "rpmbuild" to make it simple.
# "osc build" is too resource hungry (builds a complete chroot from scratch).
# Moreover it does not work in a Docker container (it fails when trying to mount
# /proc and /sys in the chroot).
if [ -f utils/make_package ]; then
utils/make_package
elif [ -f Makefile.repo ]; then
make -f Makefile.repo
make package
elif [ -f Rakefile ]; then
rake pot
rake tarball > /dev/null 2>&1
else
echo "ERROR: Missing Makefile.repo or Rakefile, cannot build the package"
exit 1
fi
if [ -d package ]; then
# run the osc source validator to check the .spec and .changes locally
(cd package && /usr/lib/obs/service/source_validator)
fi
cp package/* /usr/src/packages/SOURCES/
# Build the binary package, if it fails try to build the package with ignored
# deps, maybe it can work anyway...
# (e.g. yast2-packager requires yast2_theme which is not needed in simple rpmbuild)
rpmbuild -bb package/*.spec || rpmbuild -bb --nodeps package/*.spec
# test the %pre/%post scripts by installing/updating/removing the built packages
# ignore the dependencies to make the test easier, as a smoke test it's good enough
rpm -iv --force --nodeps /usr/src/packages/RPMS/**/*.rpm
rpm -Uv --force --nodeps /usr/src/packages/RPMS/**/*.rpm
# get the plain package names and remove all packages at once
mapfile -t packages < <(rpm -q --qf '%{NAME}\n' -p /usr/src/packages/RPMS/*/*.rpm)
rpm -ev --nodeps "${packages[@]}"