File: run-ci.sh

package info (click to toggle)
libheif 1.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,572 kB
  • sloc: cpp: 83,285; python: 3,032; sh: 952; ansic: 453; javascript: 160; makefile: 76
file content (295 lines) | stat: -rwxr-xr-x 11,240 bytes parent folder | download
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
set -e
#
# HEIF codec.
# Copyright (c) 2018 struktur AG, Joachim Bauch <bauch@struktur.de>
#
# This file is part of libheif.
#
# libheif 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.
#
# libheif 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 libheif.  If not, see <http://www.gnu.org/licenses/>.
#

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

BUILD_ROOT=$ROOT/..
CURRENT_OS=$TRAVIS_OS_NAME
if [ -z "$CURRENT_OS" ]; then
    if [ "$(uname)" != "Darwin" ]; then
        CURRENT_OS=linux
    else
        CURRENT_OS=osx
    fi
fi

# Don't run regular tests on Coverity scan builds.
if [ ! -z "${COVERITY_SCAN_BRANCH}" ]; then
    echo "Skipping tests on Coverity scan build ..."
    exit 0
fi

if [ ! -z "$CHECK_LICENSES" ]; then
    echo "Checking licenses ..."
    ./scripts/check-licenses.sh
fi

if [ ! -z "$CPPLINT" ]; then
    PYTHON=$(which python || true)
    if [ -z "$PYTHON" ]; then
        PYTHON=$(which python3 || true)
        if [ -z "$PYTHON" ]; then
            echo "Could not find valid Python interpreter to run cpplint."
            echo "Make sure you have either python or python3 in your PATH."
            exit 1
        fi
    fi
    echo "Running cpplint with $PYTHON ..."
    find -name "*.c" -o -name "*.cc" -o -name "*.h" | sort | xargs "$PYTHON" ./scripts/cpplint.py --extensions=c,cc,h
    ./scripts/check-emscripten-enums.sh
    ./scripts/check-go-enums.sh

    echo "Running gofmt ..."
    ./scripts/check-gofmt.sh
    exit 0
fi

BIN_SUFFIX=
BIN_WRAPPER=
if [ "$MINGW" == "32" ]; then
    # Make sure the correct compiler will be used.
    export CC=i686-w64-mingw32-gcc
    export CXX=i686-w64-mingw32-g++
    BIN_SUFFIX=.exe
    BIN_WRAPPER=/usr/lib/wine/wine
    MINGW_SYSROOT="/usr/i686-w64-mingw32"
    export WINEPATH="$(dirname $($CXX --print-file-name=libstdc++.a));$MINGW_SYSROOT/lib"
elif [ "$MINGW" == "64" ]; then
    # Make sure the correct compiler will be used.
    export CC=x86_64-w64-mingw32-gcc
    export CXX=x86_64-w64-mingw32-g++
    BIN_SUFFIX=.exe
    BIN_WRAPPER=/usr/lib/wine/wine64
    MINGW_SYSROOT="/usr/x86_64-w64-mingw32"
    export WINEPATH="$(dirname $($CXX --print-file-name=libstdc++.a));$MINGW_SYSROOT/lib"
fi

PKG_CONFIG_PATH=
if [ "$WITH_LIBDE265" = "2" ]; then
    PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$BUILD_ROOT/libde265/dist/lib/pkgconfig/"
fi

if [ "$WITH_RAV1E" = "1" ]; then
    PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$BUILD_ROOT/third-party/rav1e/dist/lib/pkgconfig/"
fi

if [ "$WITH_DAV1D" = "1" ]; then
    PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$BUILD_ROOT/third-party/dav1d/dist/lib/x86_64-linux-gnu/pkgconfig/"
fi
if [ ! -z "$PKG_CONFIG_PATH" ]; then
    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
fi

WITH_AVIF_DECODER=
if [ ! -z "$WITH_AOM" ] || [ ! -z "$WITH_DAV1D" ]; then
    WITH_AVIF_DECODER=1
fi
WITH_HEIF_DECODER=
if [ ! -z "$WITH_LIBDE265" ] ; then
    WITH_HEIF_DECODER=1
fi
WITH_AVIF_ENCODER=
WITH_HEIF_ENCODER=
# Need decoded images before encoding.
if [ ! -z "$WITH_AVIF_DECODER" ]; then
    if [ ! -z "$WITH_RAV1E" ]; then
        WITH_AVIF_ENCODER=1
    fi
fi
if [ ! -z "$WITH_HEIF_DECODER" ]; then
    if [ ! -z "$WITH_X265" ] ; then
        WITH_HEIF_ENCODER=1
    fi
fi


echo "Preparing cmake build files ..."

if [ ! -z "$FUZZER" ]; then
    CMAKE_OPTIONS="--preset=fuzzing"
fi
if [ ! -z "$TESTS" ]; then
    CMAKE_OPTIONS="--preset=testing"
fi
if [ -z "$FUZZER" ] && [ -z "$TESTS" ]; then
    CMAKE_OPTIONS="--preset=release -DENABLE_PLUGIN_LOADING=OFF"
fi
	
if [ "$CURRENT_OS" = "osx" ] ; then
    # Make sure the homebrew installed libraries are used when building instead
    # of the libraries provided by Apple.
    CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_FIND_FRAMEWORK=LAST"
fi
if [ -n "$MINGW" ]; then
    CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_FIND_ROOT_PATH=$MINGW_SYSROOT"
fi
if [ "$CLANG_TIDY" = "1" ]; then
    CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi

echo "install prefix: ${BUILD_ROOT}/dist"
mkdir ${BUILD_ROOT}/dist
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_INSTALL_PREFIX=${BUILD_ROOT}/dist"

# turn on warnings-as-errors
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_COMPILE_WARNING_AS_ERROR=1"

# compilation mode
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE=Release"


if [ ! -z "$FUZZER" ] && [ "$CURRENT_OS" = "linux" ]; then
    export ASAN_SYMBOLIZER="$BUILD_ROOT/clang/bin/llvm-symbolizer"
fi

if [ -z "$EMSCRIPTEN_VERSION" ] && [ -z "$CHECK_LICENSES" ] && [ -z "$TARBALL" ] ; then
    echo "Building libheif ..."
    cmake . $CMAKE_OPTIONS
    make -j $(nproc)
    if [ "$CURRENT_OS" = "linux" ] && [ -z "$MINGW" ] && [ -z "$FUZZER" ] && [ ! -z "$TESTS" ] ; then
        echo "Running tests ..."
        make test
    fi
    if [ -z "$FUZZER" ] ; then
	echo "List available encoders"
        ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} --list-encoders

	echo "List available decoders"
        ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} --list-decoders

        echo "Dumping information of sample file ..."
        #${BIN_WRAPPER} gdb -batch -ex "run" -ex "bt" --args ./examples/heif-info${BIN_SUFFIX} --dump-boxes examples/example.heic
        ${BIN_WRAPPER} ./examples/heif-info${BIN_SUFFIX} --dump-boxes examples/example.heic
        if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_HEIF_DECODER" ]; then
            echo "Converting sample HEIF file to JPEG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.heic example.jpg
            echo "Checking first generated file ..."
            [ -s "example-1.jpg" ] || exit 1
            echo "Checking second generated file ..."
            [ -s "example-2.jpg" ] || exit 1
            echo "Converting sample HEIF file to PNG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.heic example.png
            echo "Checking first generated file ..."
            [ -s "example-1.png" ] || exit 1
            echo "Checking second generated file ..."
            [ -s "example-2.png" ] || exit 1
        fi
        if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_AVIF_DECODER" ]; then
            echo "Converting sample AVIF file to JPEG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.avif example.jpg
            echo "Checking generated file ..."
            [ -s "example.jpg" ] || exit 1
            echo "Converting sample AVIF file to PNG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.avif example.png
            echo "Checking generated file ..."
            [ -s "example.png" ] || exit 1
        fi
        if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_HEIF_ENCODER" ]; then
            echo "Converting single JPEG file to heif ..."
            ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} -o output-single.heic --verbose --verbose --verbose --thumb 320x240 example-1.jpg
            echo "Checking generated file ..."
            [ -s "output-single.heic" ] || exit 1
            echo "Converting back generated heif to JPEG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-single.heic output-single.jpg
            echo "Checking generated file ..."
            [ -s "output-single.jpg" ] || exit 1
            echo "Converting multiple JPEG files to heif ..."
            ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} -o output-multi.heic --verbose --verbose --verbose --thumb 320x240 example-1.jpg example-2.jpg
            echo "Checking generated file ..."
            [ -s "output-multi.heic" ] || exit 1
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-multi.heic output-multi.jpg
            echo "Checking first generated file ..."
            [ -s "output-multi-1.jpg" ] || exit 1
            echo "Checking second generated file ..."
            [ -s "output-multi-2.jpg" ] || exit 1
        fi
        if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_AVIF_ENCODER" ]; then
            echo "Converting JPEG file to AVIF ..."
            ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} -o output-jpeg.avif --verbose --verbose --verbose -A --thumb 320x240 example.jpg
            echo "Checking generated file ..."
            [ -s "output-jpeg.avif" ] || exit 1
            echo "Converting back generated AVIF to JPEG ..."
            ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-jpeg.avif output-jpeg.jpg
            echo "Checking generated file ..."
            [ -s "output-jpeg.jpg" ] || exit 1
        fi
        if [ ! -z "$GO" ]; then
            echo "Installing library ..."
            make -j $(nproc) install

            echo "Running golang example ..."
            export GOPATH="$BUILD_ROOT/gopath"
            export PKG_CONFIG_PATH="$BUILD_ROOT/dist/lib/pkgconfig:$BUILD_ROOT/libde265/dist/lib/pkgconfig/"
            export LD_LIBRARY_PATH="$BUILD_ROOT/dist/lib:$BUILD_ROOT/libde265/dist/lib"
            mkdir -p "$GOPATH/src/github.com/strukturag"
            ln -s "$BUILD_ROOT" "$GOPATH/src/github.com/strukturag/libheif"
            go run examples/heif-test.go examples/example.heic
            echo "Checking first generated file ..."
            [ -s "examples/example_lowlevel.png" ] || exit 1
            echo "Checking second generated file ..."
            [ -s "examples/example_highlevel.png" ] || exit 1
            echo "Checking race tester ..."
            go run tests/test-race.go examples/example.heic
        fi
    fi
fi

if [ ! -z "$EMSCRIPTEN_VERSION" ]; then
    echo "Building with emscripten $EMSCRIPTEN_VERSION ..."
    source ./emscripten/emsdk/emsdk_env.sh && USE_WASM=0 ./build-emscripten.sh .
    source ./emscripten/emsdk/emsdk_env.sh && node scripts/test-javascript.js
fi

if [ ! -z "$TARBALL" ]; then
    VERSION=$(grep project CMakeLists.txt | sed -r 's/^[^0-9]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
    echo "Creating tarball for version $VERSION ..."
    mkdir build
    pushd build
    cmake .. --preset=release
    make package_source
    mv libheif-$VERSION.tar.gz ..
    popd

    echo "Building from tarball ..."
    tar xf libheif-$VERSION.tar*
    pushd libheif-$VERSION
    mkdir build
    pushd build
    cmake .. --preset=release
    make -j $(nproc)
    popd
fi

if [ ! -z "$FUZZER" ] && [ "$CURRENT_OS" = "linux" ]; then
    ./fuzzing/color_conversion_fuzzer ./fuzzing/data/corpus/*color-conversion-fuzzer*
    ./fuzzing/file_fuzzer ./fuzzing/data/corpus/*.heic

    echo "Running color conversion fuzzer ..."
    ./fuzzing/color_conversion_fuzzer -max_total_time=120

    # Do not run encoder_fuzzer because it will just find errors in x265...
    #echo "Running encoder fuzzer ..."
    #./fuzzing/encoder_fuzzer -max_total_time=120
    
    echo "Running file fuzzer ..."
    ./fuzzing/file_fuzzer -dict=./fuzzing/data/dictionary.txt -max_total_time=120
fi