1#!/usr/bin/env bash
2#############################################################################
3##
4## Copyright (C) 2019 Richard Weickelt.
5## Contact: https://www.qt.io/licensing/
6##
7## This file is part of Qbs.
8##
9## $QT_BEGIN_LICENSE:LGPL$
10## Commercial License Usage
11## Licensees holding valid commercial Qt licenses may use this file in
12## accordance with the commercial license agreement provided with the
13## Software or, alternatively, in accordance with the terms contained in
14## a written agreement between you and The Qt Company. For licensing terms
15## and conditions see https://www.qt.io/terms-conditions. For further
16## information use the contact form at https://www.qt.io/contact-us.
17##
18## GNU Lesser General Public License Usage
19## Alternatively, this file may be used under the terms of the GNU Lesser
20## General Public License version 3 as published by the Free Software
21## Foundation and appearing in the file LICENSE.LGPL3 included in the
22## packaging of this file. Please review the following information to
23## ensure the GNU Lesser General Public License version 3 requirements
24## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25##
26## GNU General Public License Usage
27## Alternatively, this file may be used under the terms of the GNU
28## General Public License version 2.0 or (at your option) the GNU General
29## Public license version 3 or any later version approved by the KDE Free
30## Qt Foundation. The licenses are as published by the Free Software
31## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32## included in the packaging of this file. Please review the following
33## information to ensure the GNU General Public License requirements will
34## be met: https://www.gnu.org/licenses/gpl-2.0.html and
35## https://www.gnu.org/licenses/gpl-3.0.html.
36##
37## $QT_END_LICENSE$
38##
39#############################################################################
40set -e
41
42#
43# Qbs is built with the address sanitizer enabled.
44# Suppress findings in some parts of Qbs / dependencies.
45#
46export LSAN_OPTIONS="suppressions=$( cd "$(dirname "$0")" ; pwd -P )/address-sanitizer-suppressions.txt:print_suppressions=0"
47
48if [ -z "${QBS_BUILD_PROFILE}" ]; then
49    QBS_BUILD_PROFILE=$(qbs config defaultProfile | cut -d: -f2 | tr -d '[:space:]')
50fi
51if [ -z "${QBS_BUILD_PROFILE}" ]; then
52    echo "Either QBS_BUILD_PROFILE or a defaultProfile must be set."
53    exit 1
54fi
55
56#
57# Additional build options
58#
59BUILD_OPTIONS="\
60    profile:${QBS_BUILD_PROFILE} \
61    modules.qbsbuildconfig.enableAddressSanitizer:true \
62    modules.qbsbuildconfig.enableUnitTests:true \
63    modules.cpp.treatWarningsAsErrors:true \
64    modules.cpp.separateDebugInformation:true \
65    ${BUILD_OPTIONS} \
66    config:release \
67"
68
69#
70# Build all default products of Qbs
71#
72qbs resolve ${BUILD_OPTIONS}
73qbs build ${BUILD_OPTIONS}
74
75WITH_DOCS=${WITH_DOCS:-1}
76if [ "$WITH_DOCS" -ne 0 ]; then
77    qbs build -p "qbs documentation" ${BUILD_OPTIONS}
78fi
79
80WITH_ARCHIVE=${WITH_ARCHIVE:-1}
81if [ "$WITH_ARCHIVE" -ne 0 ]; then
82    qbs build -p "qbs_archive" ${BUILD_OPTIONS}
83fi
84
85WITH_TESTS=${WITH_TESTS:-1}
86if [ "$WITH_TESTS" -eq 0 ]; then
87    exit 0
88fi
89
90QMAKE_PATH=${QMAKE_PATH:-$(which qmake)}
91
92#
93# Set up profiles for the freshly built Qbs if not
94# explicitly specified otherwise
95#
96if [ -z "${QBS_AUTOTEST_PROFILE}" ]; then
97
98    export QBS_AUTOTEST_PROFILE=autotestprofile
99    export QBS_AUTOTEST_SETTINGS_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'qbs-settings'`
100
101    QBS_AUTOTEST_QMAKE_PATH=${QBS_AUTOTEST_QMAKE_PATH:-${QMAKE_PATH}}
102
103    RUN_OPTIONS="\
104        --settings-dir ${QBS_AUTOTEST_SETTINGS_DIR} \
105    "
106
107    qbs run -p qbs_app ${BUILD_OPTIONS} -- setup-toolchains \
108            ${RUN_OPTIONS} \
109            --detect
110
111    qbs run -p qbs_app ${BUILD_OPTIONS} -- setup-qt \
112            ${RUN_OPTIONS} \
113            "${QBS_AUTOTEST_QMAKE_PATH}" ${QBS_AUTOTEST_PROFILE}
114
115    # Make sure that the Qt profile uses the same toolchain profile
116    # that was used for building in case a custom QBS_BUILD_PROFILE
117    # was set. Otherwise setup-qt automatically uses the default
118    # toolchain profile.
119    if [ -z "${QBS_AUTOTEST_BASE_PROFILE}" ]; then
120        QBS_AUTOTEST_BASE_PROFILE=$(qbs config profiles.${QBS_BUILD_PROFILE}.baseProfile | cut -d: -f2)
121    fi
122    if [ ! -z "${QBS_AUTOTEST_BASE_PROFILE}" ]; then
123        echo "Setting base profile for ${QBS_AUTOTEST_PROFILE} to ${QBS_AUTOTEST_BASE_PROFILE}"
124        qbs run -p qbs_app ${BUILD_OPTIONS} -- config \
125                ${RUN_OPTIONS} \
126                profiles.${QBS_AUTOTEST_PROFILE}.baseProfile ${QBS_AUTOTEST_BASE_PROFILE}
127    fi
128
129    qbs run -p qbs_app ${BUILD_OPTIONS} -- config \
130            ${RUN_OPTIONS} \
131            --list
132
133    # QBS_AUTOTEST_PROFILE has been added to the environment
134    # which requires a resolve step
135    qbs resolve ${BUILD_OPTIONS}
136fi
137
138#
139# Run all autotests with QBS_AUTOTEST_PROFILE. Some test cases might run for
140# over 10 minutes. Output an empty line every 9:50 minutes to prevent a 10min
141# timeout on Travis CI.
142#
143(while true; do echo "" && sleep 590; done) &
144trap "kill $!; wait $! 2>/dev/null || true; killall sleep || true" EXIT
145qbs build -p "autotest-runner" ${BUILD_OPTIONS}
146