1#!/bin/bash
2
3# Copyright 2020 Rene Rivera, Sam Darwin
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE.txt or copy at http://boost.org/LICENSE_1_0.txt)
6
7set -e
8export TRAVIS_BUILD_DIR=$(pwd)
9export DRONE_BUILD_DIR=$(pwd)
10export TRAVIS_BRANCH=$DRONE_BRANCH
11export VCS_COMMIT_ID=$DRONE_COMMIT
12export GIT_COMMIT=$DRONE_COMMIT
13export REPO_NAME=$DRONE_REPO
14export USER=$(whoami)
15export CC=${CC:-gcc}
16export PATH=~/.local/bin:/usr/local/bin:$PATH
17export BOOST_ROOT="$HOME/boost"
18export BOOST_BUILD_PATH="$HOME/build-boost"
19export TRAVIS_PULL_REQUEST=${DRONE_PULL_REQUEST:-false}
20export TRAVIS_REPO_SLUG=$REPO_NAME
21
22if [ "$DRONE_JOB_BUILDTYPE" == "boost" ]; then
23
24echo '==================================> INSTALL'
25
26export CACHE_NAME=$TRAVIS_OS_NAME-$TOOLSET-$STD-$JOB
27export PATH=$BOOST_ROOT:$PATH
28if [[ "$TRAVIS_COMPILER" =~ ^clang- ]]; then export STDLIB=stdlib=libc++ ; fi
29# Creating ~/user-config.jam file
30sed 's/^  //' > ~/user-config.jam << 'EOF'
31
32import feature ;
33import os ;
34import regex ;
35import toolset ;
36
37
38local TOOLSET = [ os.environ TRAVIS_COMPILER ] ;
39local toolset-parts = [ regex.split $(TOOLSET) "-" ] ;
40local toolset-name = $(toolset-parts[1]) ;
41local toolset-feature = $(toolset-parts[2-]:J="-") ;
42
43local cxx ;
44switch $(toolset-name) {
45    case gcc   : cxx ?= [ regex.replace $(TOOLSET) "gcc" "g++" ] ;
46    case clang : cxx ?= [ regex.replace $(TOOLSET) "clang" "clang++" ] ;
47    case *     : EXIT "user-config: Unsupported toolset $(toolset-name)" ;
48}
49
50using $(toolset-name) : $(toolset-feature) : ccache $(cxx) ;
51
52# Release variant with enabled asserts
53variant sanitize : <optimization>speed <debug-symbols>off <inlining>full
54                   <runtime-debugging>off ;
55
56# Ignore some warnings
57feature.feature known-warnings : suppress : optional incidental propagated ;
58toolset.flags gcc.compile OPTIONS <known-warnings>suppress :
59    -Wno-maybe-uninitialized  # this warning is known to give false positives
60  # -Wextra warnings:
61    -Wno-deprecated-copy      # Proto, Phoenix, GCC bug 92145
62  : unchecked ;
63toolset.flags clang-linux.compile OPTIONS <known-warnings>suppress :
64    -Wno-deprecated-copy      # Proto, Phoenix
65  : unchecked ;
66
67# Determining the root branch
68if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
69  export BRANCH=$TRAVIS_BRANCH
70else
71  # It is a pull request. Retrieve the base branch from GitHub
72  GH_PR_API=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
73  export BRANCH=`curl -s $GH_PR_API | jq -r .head.ref`;
74fi
75if [[ ! "$BRANCH" =~ ^(master|develop)$ ]]; then
76  # Travis has been triggered not from our main branches.
77  # Find out the base branch from the git history
78  # TODO: Not implemented yet, but in most cases it will be develop branch
79  export BRANCH=develop
80fi
81echo Root branch is $BRANCH
82
83env
84sed 's/--depth=1/--depth=9/g' `which git` > ~/git && chmod +x ~/git
85~/git clone -j10 --branch=$BRANCH --depth=1 --quiet --recurse-submodules=":(exclude)$PROJECT" --shallow-submodules https://github.com/boostorg/boost.git $BOOST_ROOT
86pushd $BOOST_ROOT
87rm -rf $PROJECT
88./bootstrap.sh --with-toolset=clang
89./b2 headers
90cp -rp $TRAVIS_BUILD_DIR $PROJECT
91ln -s $PROJECT $TRAVIS_BUILD_DIR
92cd $PROJECT
93cd $JOB
94
95echo '==================================> SCRIPT'
96
97b2 link=shared threading=multi variant=release,sanitize toolset=$TRAVIS_COMPILER cxxstd=$STD $STDLIB warnings=extra known-warnings=suppress warnings-as-errors=on
98
99fi
100