@@ -10,20 +10,47 @@ function package_name() {
10
10
wheel_name=$name
11
11
}
12
12
13
+ # Terminate the build but ensure saving the cache
14
+ function goto_exit {
15
+ local EXIT_CODE=${1:- 1}
16
+
17
+ echo " Exiting build"
18
+
19
+ # Can't just `exit` because that would terminate the build without saving the cache
20
+ # Have to replace further actions with no-ops
21
+
22
+ local MESSAGE=" " ; if [ " $EXIT_CODE " -ne 0 ]; then
23
+ MESSAGE=' Building package took too long. Restart the build in Travis UI to continue from cache.'
24
+ fi
25
+
26
+ set +e
27
+
28
+ eval '
29
+ function install_run {' \
30
+ " $( if [ -n " $MESSAGE " ]; then
31
+ echo ' echo -e "\n' " $MESSAGE " ' \n"'
32
+ fi) " \
33
+ '
34
+ # Travis runs user scripts via `eval` i.e. in the same shell process.
35
+ # So have to unset errexit in order to get to cache save stage
36
+ set +e
37
+ return ' " $EXIT_CODE " '
38
+ }'
39
+ }
40
+
13
41
function pre_build_osx {
14
42
local repo_dir=$( abspath ${1:- $REPO_DIR } )
15
43
local build_dir=" $repo_dir /opencv/build"
16
44
local num_cpus=$( sysctl -n hw.ncpu)
17
45
num_cpus=${num_cpus:- 4}
46
+ local travis_start_time=$(( $TRAVIS_TIMER_START_TIME / 10 ** 9 ))
47
+ local time_limit=$(( 45 * 60 ))
18
48
19
49
cd " $repo_dir "
20
50
git submodule sync
21
51
git submodule update --init --recursive opencv
22
52
git submodule update --init --recursive opencv_contrib
23
53
24
- pip install scikit-build
25
- pip install numpy
26
-
27
54
if [ ! -d " $build_dir " ]; then
28
55
mkdir " $build_dir "
29
56
fi
@@ -127,13 +154,22 @@ function pre_build_osx {
127
154
)
128
155
for m in " ${CV_MODULES[@]} " ; do
129
156
if make help | grep -w " $m " ; then
157
+ # Check time limit (3min should be enough for a module to built)
158
+ local projected_time=$(( $(date +% s) - travis_start_time + 3 * 60 ))
159
+ if [ $projected_time -ge $time_limit ]; then
160
+ if [ -n " $USE_CCACHE " ]; then ccache -s; fi
161
+ goto_exit
162
+ return 1
163
+ fi
130
164
make -j${num_cpus} " $m "
165
+ local elapsed_time=$(( $(date +% s) - travis_start_time))
166
+ echo " Elapsed time: " $(( elapsed_time/ 60 )) " m (${elapsed_time} s)"
131
167
fi
132
168
done
133
169
make -j${num_cpus}
134
170
135
171
# Print ccache stats
136
- ccache -s
172
+ if [ -n " $USE_CCACHE " ] ; then ccache -s; fi
137
173
}
138
174
139
175
function build_osx {
@@ -170,9 +206,13 @@ function build_osx {
170
206
function build_bdist_osx_wheel {
171
207
local repo_dir=$( abspath ${1:- $REPO_DIR } )
172
208
[ -z " $repo_dir " ] && echo " repo_dir not defined" && exit 1
173
- pre_build_osx " $repo_dir "
174
- if [ -n " $BUILD_DEPENDS " ]; then
175
- pip install $( pip_opts) $BUILD_DEPENDS
176
- fi
209
+ local wheelhouse=$( abspath ${WHEEL_SDIR:- wheelhouse} )
210
+ start_spinner
211
+ if [ -n " $( is_function " pre_build" ) " ]; then pre_build; fi
212
+ stop_spinner
213
+ pip install scikit-build
214
+ pip install numpy
215
+ pre_build_osx " $repo_dir " || return $?
177
216
build_osx " $repo_dir "
217
+ repair_wheelhouse " $wheelhouse "
178
218
}
0 commit comments