-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-app
executable file
·133 lines (109 loc) · 2.86 KB
/
build-app
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
#!/bin/bash
set -euo pipefail
PROGNAME=$(basename $0)
DESCRIPTION="
Provides all the steps to build the application. This script is called by the
CI to build the application, but you can run it on your local machine as well.
"
pushd $PWD > /dev/null
cd $(dirname $0)/..
SRC_DIR=$PWD
popd > /dev/null
CI_DIR=$SRC_DIR/ci
WORK_DIR=${WORK_DIR:-$SRC_DIR/_work}
BUILD_DIR=$WORK_DIR/build
INSTALL_DIR=$WORK_DIR/install
ENV_FILE=$WORK_DIR/env.sh
BUILD_TYPE=Release
BUILD_CMD="cmake --build $BUILD_DIR --config $BUILD_TYPE"
. $CI_DIR/lib/common.sh
# Call this function here because we need $OS to load the right
# OS-dependencies.sh file
detect_os
. $CI_DIR/lib/common-dependencies.sh
. $CI_DIR/lib/$OS-dependencies.sh
#- Build steps ----------------------------------------------------------------
step_install-dependencies() {
echo_title "Installing dependencies"
# The install_dependencies() function can define environment variables to
# help the other steps do their work: adding directories to $PATH or
# defining the installation directory of libraries so that the build step
# can find them.
> $ENV_FILE
install_dependencies
}
step_build() {
echo_title Configuring
. $ENV_FILE
mkdir $BUILD_DIR
cd $BUILD_DIR
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $SRC_DIR
echo_title Updating translations
$BUILD_CMD --target lupdate
echo_title Building
$BUILD_CMD --parallel $NPROC
}
step_tests() {
echo_title Running tests
. $ENV_FILE
local test_cmd="$BUILD_CMD --target check"
if is_linux && [ -z "${DISPLAY:-}" ] ; then
xvfb-run $CI_DIR/lib/headless-test-helper $test_cmd
else
$test_cmd
fi
}
step_install() {
echo_title Installing
$BUILD_CMD --target install
}
step_binary-packages() {
echo_title "Creating binary packages"
$BUILD_CMD --target package
}
step_source-package() {
echo_title "Creating source package"
$BUILD_CMD --target package_source
}
#- Main -----------------------------------------------------------------------
check_step_exists() {
[ $(type -t "step_$1") = "function" ]
}
usage() {
if [ "$*" != "" ] ; then
echo "Error: $*"
fi
cat << EOF
Usage: $PROGNAME [OPTION ...] [steps...]
$DESCRIPTION
Options:
-h, --help display this usage message and exit
Steps:
EOF
grep '^step_[-a-z]*() {' $CI_DIR/$PROGNAME | sed -e 's/step_/ /' -e 's/() {//'
exit 1
}
main() {
init_run_as_root
init_nproc
init_python_cmd
steps=""
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
usage
;;
*)
check_step_exists $1 || usage "Unknown step '$1'"
steps="$steps step_$1"
;;
esac
shift
done
mkdir -p $WORK_DIR
mkdir -p $INSTALL_DIR
for step in $steps ; do
$step
done
}
main $@