1#!/usr/bin/env bash 2 3# MIT License 4# 5# Copyright (c) 2017 Maxim Biro <nurupo.contributions@gmail.com> 6# 7# Permission is hereby granted, free of charge, to any person obtaining a copy 8# of this software and associated documentation files (the "Software"), to deal 9# in the Software without restriction, including without limitation the rights 10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11# copies of the Software, and to permit persons to whom the Software is 12# furnished to do so, subject to the following conditions: 13# 14# The above copyright notice and this permission notice shall be included in 15# all copies or substantial portions of the Software. 16# 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23# THE SOFTWARE. 24 25# Fail out on error 26set -exuo pipefail 27 28readonly ARCH="$1" 29readonly BUILD_TYPE="$2" 30readonly CACHE_DIR="$3" 31readonly STAGE="$4" 32 33if [ -z "$ARCH" ] 34then 35 echo "Error: No architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script." 36 exit 1 37fi 38 39if [[ "$ARCH" != "i686" ]] && [[ "$ARCH" != "x86_64" ]] 40then 41 echo "Error: Incorrect architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script." 42 exit 1 43fi 44 45if [ -z "$BUILD_TYPE" ] 46then 47 echo "Error: No build type was specified. Please specify either 'release' or 'debug', case sensitive, as the second argument to the script." 48 exit 1 49fi 50 51if [[ "$BUILD_TYPE" != "release" ]] && [[ "$BUILD_TYPE" != "debug" ]] 52then 53 echo "Error: Incorrect build type was specified. Please specify either 'release' or 'debug', case sensitive, as the second argument to the script." 54 exit 1 55fi 56 57if [ -z "$CACHE_DIR" ] 58then 59 echo "Error: No cache directory path was specified. Please specify absolute path to the cache directory as the third argument to the script." 60 exit 1 61fi 62 63if [ -z "$STAGE" ] 64then 65 echo "Error: No stage was specified. Please specify either 'stage1', 'stage2' or 'stage3' as the fourth argument to the script." 66 exit 1 67fi 68 69if [[ "$STAGE" != "stage1" ]] && [[ "$STAGE" != "stage2" ]] && [[ "$STAGE" != "stage3" ]] 70then 71 echo "Error: Incorrect stage was specified. Please specify either 'stage1', 'stage2' or 'stage3', case sensitive, as the fourth argument to the script." 72 exit 1 73fi 74 75# make the build stage visible to the deploy process 76touch "$STAGE" 77 78# make the build type visible to the deploy process 79touch "$BUILD_TYPE" 80 81# for debugging of the stage files 82echo $PWD 83 84# Just make sure those exist, makes logic easier 85mkdir -p "$CACHE_DIR" 86touch "$CACHE_DIR"/hash 87mkdir -p workspace/"$ARCH"/dep-cache 88 89# Purely for debugging 90ls -lbh "$CACHE_DIR" 91 92 93# If build.sh has changed, i.e. its hash doesn't match the previously stored one, and it's Stage 1 94# Then we want to rebuild everything from scratch 95if [ "`cat $CACHE_DIR/hash`" != "`sha256sum windows/cross-compile/build.sh`" ] && [ "$STAGE" == "stage1" ] 96then 97 # Clear the cache, removing all the pre-built dependencies 98 rm -rf "$CACHE_DIR"/* 99 touch "$CACHE_DIR"/hash 100else 101 # Copy over all pre-built dependencies 102 cp -dR "$CACHE_DIR"/* workspace/"$ARCH"/dep-cache 103fi 104 105# Purely for debugging 106ls -lbh "$CACHE_DIR" 107 108# Purely for debugging 109ls -lbh "$PWD" 110 111sudo apt-get update -qq 112# even though we're building in docker, libseccomp2 is used by docker, and needs to be up to date 113# to support functionality used by Qt's configure 114sudo apt-get install libseccomp2 -y --force-yes 115 116# Build 117sudo docker run --rm \ 118 -v "$PWD/workspace":/workspace \ 119 -v "$PWD":/qtox \ 120 -e TRAVIS_CI_STAGE="$STAGE" \ 121 debian:buster-slim \ 122 /bin/bash /qtox/windows/cross-compile/build.sh "$ARCH" "$BUILD_TYPE" 123 124# Purely for debugging 125ls -lbh workspace/"$ARCH"/dep-cache/ 126 127# If we were building deps and it's any of the dependency building stages (Stage 1 or 2), copy over all the built dependencies to Travis cache 128if [ "`cat $CACHE_DIR/hash`" != "`sha256sum windows/cross-compile/build.sh`" ] && ( [ "$STAGE" == "stage1" ] || [ "$STAGE" == "stage2" ] ) 129then 130 # Clear out the cache 131 rm -rf "$CACHE_DIR"/* 132 touch "$CACHE_DIR"/hash 133 cp -dR workspace/"$ARCH"/dep-cache/* "$CACHE_DIR" 134fi 135 136# Update the hash 137if [ "`cat $CACHE_DIR/hash`" != "`sha256sum windows/cross-compile/build.sh`" ] && [ "$STAGE" == "stage2" ] 138then 139 sha256sum windows/cross-compile/build.sh > "$CACHE_DIR"/hash 140fi 141 142# Generate checksum files for releases 143if [ "$STAGE" == "stage3" ] 144then 145 readonly OUT_DIR=./workspace/"$ARCH"/qtox/"$BUILD_TYPE"/ 146 if [ "$BUILD_TYPE" == "release" ] 147 then 148 NAME=setup-qtox-"$ARCH"-"$BUILD_TYPE".exe 149 sha256sum "$OUT_DIR""$NAME" > "$OUT_DIR""$NAME".sha256 150 fi 151 NAME=qtox-"$ARCH"-"$BUILD_TYPE".zip 152 sha256sum "$OUT_DIR""$NAME" > "$OUT_DIR""$NAME".sha256 153fi 154 155# Purely for debugging 156touch "$CACHE_DIR"/"$STAGE" 157ls -lbh "$CACHE_DIR" 158