cibuild.sh 5.2 KB
Newer Older
1
#!/usr/bin/env bash
J
jaredpar 已提交
2

D
Drew DeVault 已提交
3 4 5 6 7 8 9
usage()
{
    echo "Runs our integration suite on Linux"
    echo "usage: cibuild.sh [options]"
    echo ""
    echo "Options"
    echo "  --mono-path <path>  Path to the mono installation to use for the run" 
10
    echo "  --os <os>           OS to run (Linux / Darwin)"
D
Drew DeVault 已提交
11 12
}

13
XUNIT_VERSION=2.1.0-beta3-build3029
14
BUILD_CONFIGURATION=Debug
J
jaredpar 已提交
15
OS_NAME=$(uname -s)
J
Jared Parsons 已提交
16
USE_CACHE=true
J
jaredpar 已提交
17

J
jaredpar 已提交
18 19 20 21 22 23 24 25 26 27 28 29
while [[ $# > 0 ]]
do
    opt="$1"
    case $opt in
        -h|--help)
        usage
        exit 1
        ;;
        --mono-path)
        CUSTOM_MONO_PATH=$2
        shift 2
        ;;
J
jaredpar 已提交
30 31 32 33
        --os)
        OS_NAME=$2
        shift 2
        ;;
34 35 36 37 38 39 40 41
        --debug)
        BUILD_CONFIGURATION=Debug
        shift 1
        ;;
        --release)
        BUILD_CONFIGURATION=Release
        shift 1
        ;;
J
Jared Parsons 已提交
42 43 44 45
        --nocache)
        USE_CACHE=false
        shift 1
        ;;
J
jaredpar 已提交
46 47 48 49 50 51 52
        *)
        usage 
        exit 1
        ;;
    esac
done

J
jaredpar 已提交
53 54 55 56 57 58 59 60 61
run_xbuild()
{
    xbuild /v:m /p:SignAssembly=false /p:DebugSymbols=false "$@"
    if [ $? -ne 0 ]; then
        echo Compilation failed
        exit 1
    fi
}

J
jaredpar 已提交
62 63 64 65 66 67
# NuGet crashes on occasion during restore.  This isn't a fatal action so 
# we re-run it a number of times.  
run_nuget()
{
    i=5
    while [ $i -gt 0 ]; do
68
        mono .nuget/NuGet.exe "$@"
J
jaredpar 已提交
69 70
        if [ $? -eq 0 ]; then
            i=0
J
Jared Parsons 已提交
71 72
        else
            i=$((i - 1))
J
jaredpar 已提交
73 74 75 76 77 78 79 80 81
        fi
    done

    if [ $? -ne 0 ]; then
        echo NuGet Failed
        exit 1
    fi
}

J
Jared Parsons 已提交
82
# Run the compilation.  Can pass additional build arguments as parameters
J
jaredpar 已提交
83 84 85 86
compile_toolset()
{
    echo Compiling the toolset compilers
    echo -e "\tCompiling the C# compiler"
87
    run_xbuild src/Compilers/CSharp/csc/csc.csproj /p:Configuration=$BUILD_CONFIGURATION
J
Jared Parsons 已提交
88
    run_xbuild src/Compilers/VisualBasic/vbc/vbc.csproj /p:Configuration=$BUILD_CONFIGURATION
J
jaredpar 已提交
89 90
}

91
# Save the toolset binaries from Binaries/BUILD_CONFIGURATION to Binaries/Bootstrap
J
jaredpar 已提交
92 93
save_toolset()
{
J
jaredpar 已提交
94
    local compiler_binaries=(
J
jaredpar 已提交
95 96 97 98
        csc.exe
        Microsoft.CodeAnalysis.dll
        Microsoft.CodeAnalysis.CSharp.dll
        System.Collections.Immutable.dll
J
Jared Parsons 已提交
99 100 101
        System.Reflection.Metadata.dll
        vbc.exe
        Microsoft.CodeAnalysis.VisualBasic.dll)
J
jaredpar 已提交
102 103 104

    mkdir Binaries/Bootstrap
    for i in ${compiler_binaries[@]}; do
105
        cp Binaries/$BUILD_CONFIGURATION/${i} Binaries/Bootstrap/${i}
J
jaredpar 已提交
106 107 108 109 110 111 112 113 114 115 116 117
        if [ $? -ne 0 ]; then
            echo Saving bootstrap binaries failed
            exit 1
        fi
    done
}

# Clean out all existing binaries.  This ensures the bootstrap phase forces
# a rebuild instead of picking up older binaries.
clean_roslyn()
{
    echo Cleaning the enlistment
118
    xbuild /v:m /t:Clean build/Toolset.sln /p:Configuration=$BUILD_CONFIGURATION
119
    rm -rf Binaries/$BUILD_CONFIGURATION
J
jaredpar 已提交
120 121 122
}

build_roslyn()
J
Jared Parsons 已提交
123
{
J
jaredpar 已提交
124 125
    BOOTSTRAP_ARG=/p:BootstrapBuildPath=$(pwd)/Binaries/Bootstrap

J
Jared Parsons 已提交
126
    echo Building CrossPlatform.sln
127
    run_xbuild $BOOTSTRAP_ARG CrossPlatform.sln /p:Configuration=$BUILD_CONFIGURATION
J
jaredpar 已提交
128 129
}

J
jaredpar 已提交
130 131 132 133 134 135
# Install the specified Mono toolset from our Azure blob storage.
install_mono_toolset()
{
    TARGET=/tmp/$1
    echo "Installing Mono toolset $1"
    if [ -d $TARGET ]; then
J
Jared Parsons 已提交
136 137 138 139
        if [ "$USE_CACHE" = "true" ]; then
            echo "Already installed"
            return
        fi
J
jaredpar 已提交
140 141 142 143
    fi

    pushd /tmp

J
Jared Parsons 已提交
144 145
    rm -r $TARGET 2>/dev/null
    rm $1.tar.bz2 2>/dev/null
J
jaredpar 已提交
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
    curl -O https://dotnetci.blob.core.windows.net/roslyn/$1.tar.bz2
    tar -jxf $1.tar.bz2
    if [ $? -ne 0 ]; then
        echo "Unable to download toolset"
        exit 1
    fi

    popd
}

# This function will update the PATH variable to put the desired
# version of Mono ahead of the system one. 
set_mono_path()
{
    if [ "$CUSTOM_MONO_PATH" != "" ]; then
        if [ ! -d "$CUSTOM_MONO_PATH" ]; then
            echo "Not a valid directory $CUSTOM_MONO_PATH"
            exit 1
        fi
  
        echo "Using mono path $CUSTOM_MONO_PATH"
        PATH=$CUSTOM_MONO_PATH:$PATH
        return
    fi

    if [ "$OS_NAME" = "Darwin" ]; then
        MONO_TOOLSET_NAME=mono.mac.1
    elif [ "$OS_NAME" = "Linux" ]; then
        MONO_TOOLSET_NAME=mono.linux.1
    else
        echo "Error: Unsupported OS $OS_NAME"
        exit 1
    fi

    install_mono_toolset $MONO_TOOLSET_NAME
    PATH=/tmp/$MONO_TOOLSET_NAME/bin:$PATH
}

J
jaredpar 已提交
184 185
test_roslyn()
{
186
    local xunit_runner=packages/xunit.runner.console.$XUNIT_VERSION/tools/xunit.console.x86.exe
187 188
    local test_binaries=(
        Roslyn.Compilers.CSharp.CommandLine.UnitTests
J
jaredpar 已提交
189 190 191
        Roslyn.Compilers.CSharp.Syntax.UnitTests
        Roslyn.Compilers.CSharp.Semantic.UnitTests
        Roslyn.Compilers.CSharp.Symbol.UnitTests
192 193
        Roslyn.Compilers.VisualBasic.Syntax.UnitTests)
    local any_failed=false
J
jaredpar 已提交
194

195 196
    for i in "${test_binaries[@]}"
    do
197
        mono $xunit_runner Binaries/$BUILD_CONFIGURATION/$i.dll -xml Binaries/$BUILD_CONFIGURATION/$i.TestResults.xml -noshadow
198 199 200 201
        if [ $? -ne 0 ]; then
            any_failed=true
        fi
    done
J
jaredpar 已提交
202

203 204
    if [ "$any_failed" = "true" ]; then
        echo Unit test failed
J
jaredpar 已提交
205
        exit 1
J
jaredpar 已提交
206
    fi
J
Jared Parsons 已提交
207 208
}

209
# NuGet on mono crashes about every 5th time we run it.  This is causing
J
Jared Parsons 已提交
210
# Linux runs to fail frequently enough that we need to employ a 
211
# temporary work around.  
J
jaredpar 已提交
212
echo Restoring NuGet packages
213
run_nuget restore Roslyn.sln
J
jaredpar 已提交
214

J
jaredpar 已提交
215 216
set_mono_path
which mono
J
jaredpar 已提交
217 218 219 220
compile_toolset
save_toolset
clean_roslyn
build_roslyn
J
jaredpar 已提交
221
test_roslyn
J
jaredpar 已提交
222