build.sh 5.3 KB
Newer Older
K
khyperia 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env bash
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e
set -u

usage()
{
    echo "Main interface to running builds on Mac/Linux"
    echo "Usage: build.sh [options]"
    echo ""
    echo "Options"
    echo "  --debug               Build Debug (default)"
    echo "  --release             Build Release"
    echo "  --restore             Restore projects required to build"
    echo "  --build               Build all projects"
    echo "  --test                Run unit tests"
A
Ashley Hauck 已提交
19
    echo "  --mono                Run unit tests with mono"
K
khyperia 已提交
20 21 22 23 24
    echo "  --build-bootstrap     Build the bootstrap compilers"
    echo "  --use-bootstrap       Use the built bootstrap compilers when running main build"
    echo "  --bootstrap           Implies --build-bootstrap and --use-bootstrap"
}

K
khyperia 已提交
25
root_path="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
K
khyperia 已提交
26 27 28 29
binaries_path="${root_path}"/Binaries
bootstrap_path="${binaries_path}"/Bootstrap
bootstrap_framework=netcoreapp2.0

30 31
args=
build_in_docker=false
K
khyperia 已提交
32 33 34 35
build_configuration=Debug
restore=false
build=false
test_=false
A
Ashley Hauck 已提交
36
use_mono=false
K
khyperia 已提交
37 38
build_bootstrap=false
use_bootstrap=false
39
stop_vbcscompiler=false
K
khyperia 已提交
40 41 42 43 44

# LTTNG is the logging infrastructure used by coreclr.  Need this variable set
# so it doesn't output warnings to the console.
export LTTNG_HOME="$HOME"

45 46 47 48 49 50 51 52
if [[ $# = 0 ]]
then
    usage
    echo ""
    echo "To build and test this repo, try: ./build.sh --restore --build --test"
    exit 1
fi

K
khyperia 已提交
53 54 55 56 57
while [[ $# > 0 ]]
do
    opt="$(echo "$1" | awk '{print tolower($0)}')"
    case "$opt" in
        -h|--help)
58 59 60 61 62
            usage
            exit 1
            ;;
        --docker)
            build_in_docker=true
63 64
            shift
            continue
65
            ;;
K
khyperia 已提交
66
        --debug)
67 68
            build_configuration=Debug
            ;;
K
khyperia 已提交
69
        --release)
70 71
            build_configuration=Release
            ;;
K
khyperia 已提交
72
        --restore|-r)
73 74
            restore=true
            ;;
K
khyperia 已提交
75
        --build|-b)
76 77
            build=true
            ;;
K
khyperia 已提交
78
        --test|-t)
79 80
            test_=true
            ;;
A
Ashley Hauck 已提交
81
        --mono)
82 83
            use_mono=true
            ;;
K
khyperia 已提交
84
        --build-bootstrap)
85 86
            build_bootstrap=true
            ;;
K
khyperia 已提交
87
        --use-bootstrap)
88 89
            use_bootstrap=true
            ;;
K
khyperia 已提交
90
        --bootstrap)
91 92 93
            build_bootstrap=true
            use_bootstrap=true
            ;;
94
        --stop-vbcscompiler)
95 96
            stop_vbcscompiler=true
            ;;
K
khyperia 已提交
97
        *)
98 99 100
            echo "$1"
            usage
            exit 1
K
khyperia 已提交
101 102
        ;;
    esac
103 104
    args="$args $1"
    shift
K
khyperia 已提交
105 106
done

107 108 109 110 111 112
config_path=${binaries_path}/${build_configuration}
logs_path=${config_path}/Logs
mkdir -p ${binaries_path}
mkdir -p ${config_path}
mkdir -p ${logs_path}

113 114 115 116 117 118 119
if [[ "$build_in_docker" = true ]]
then
    echo "Docker exec: $args"
    BUILD_COMMAND=/opt/code/build.sh "$root_path"/build/scripts/dockerrun.sh $args
    exit
fi

K
khyperia 已提交
120 121
source "${root_path}"/build/scripts/obtain_dotnet.sh

K
khyperia 已提交
122 123
if [[ "$restore" == true ]]
then
124 125 126 127
    echo "Restoring RoslynToolset.csproj"
    dotnet restore "${root_path}/build/ToolsetPackages/RoslynToolset.csproj" /bl:${logs_path}/Restore-RoslynToolset.binlog
    echo "Restoring Compilers.sln"
    dotnet restore "${root_path}/Compilers.sln" /bl:${logs_path}/Restore-Compilers.binlog
K
khyperia 已提交
128 129 130 131 132 133 134 135 136 137 138
fi

build_args="--no-restore -c ${build_configuration} /nologo /maxcpucount:1"

if [[ "$build_bootstrap" == true ]]
then
    echo "Building bootstrap toolset"
    bootstrap_build_args="${build_args} /p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP"
    dotnet publish "${root_path}"/src/Compilers/CSharp/csc -o "${bootstrap_path}/bincore" --framework ${bootstrap_framework} ${bootstrap_build_args} "/bl:${binaries_path}/BootstrapCsc.binlog"
    dotnet publish "${root_path}"/src/Compilers/VisualBasic/vbc -o "${bootstrap_path}/bincore" --framework ${bootstrap_framework} ${bootstrap_build_args} "/bl:${binaries_path}/BootstrapVbc.binlog"
    dotnet publish "${root_path}"/src/Compilers/Server/VBCSCompiler -o "${bootstrap_path}/bincore" --framework ${bootstrap_framework} ${bootstrap_build_args} "/bl:${binaries_path}/BootstrapVBCSCompiler.binlog"
139
    dotnet publish "${root_path}"/src/Compilers/Core/MSBuildTask -o "${bootstrap_path}" --framework ${bootstrap_framework} ${bootstrap_build_args} "/bl:${binaries_path}/BoostrapMSBuildTask.binlog"
K
khyperia 已提交
140 141 142 143 144 145 146
fi

if [[ "${use_bootstrap}" == true ]]
then
    build_args+=" /p:BootstrapBuildPath=${bootstrap_path}"
fi

J
Jared Parsons 已提交
147 148 149 150 151 152 153
# https://github.com/dotnet/roslyn/issues/23736
UNAME="$(uname)"
if [[ "$UNAME" == "Darwin" ]]
then
    build_args+=" /p:UseRoslynAnalyzers=false"
fi

K
khyperia 已提交
154 155 156 157 158 159
if [[ "${build}" == true ]]
then
    echo "Building Compilers.sln"
    dotnet build "${root_path}"/Compilers.sln ${build_args} "/bl:${binaries_path}/Build.binlog"
fi

160 161
if [[ "${stop_vbcscompiler}" == true ]]
then
162 163 164 165 166
    if [[ "${use_bootstrap}" == true ]]
    then
        echo "Stopping VBCSCompiler"
        dotnet "${bootstrap_path}"/bincore/VBCSCompiler.dll -shutdown
    else
167 168
        echo "--stop-vbcscompiler requires --use-bootstrap. Aborting."
        exit 1
169
    fi
170 171
fi

K
khyperia 已提交
172 173
if [[ "${test_}" == true ]]
then
A
Ashley Hauck 已提交
174 175 176 177 178 179 180
    if [[ "${use_mono}" == true ]]
    then
        test_runtime=mono
    else
        test_runtime=dotnet
    fi
    "${root_path}"/build/scripts/tests.sh "${build_configuration}" "${test_runtime}"
K
khyperia 已提交
181
fi