cibuild.sh 7.3 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.0.0-alpha-build2576
14
BUILD_CONFIGURATION=Debug
J
jaredpar 已提交
15
OS_NAME=$(uname -s)
J
Jared Parsons 已提交
16
USE_CACHE=true
17
MONO_ARGS='--debug=mdb-optimizations --attach=disable'
J
jaredpar 已提交
18

19 20 21 22 23
# There are some stability issues that are causing Jenkins builds to fail at an 
# unacceptable rate.  To temporarily work around that we are going to retry the 
# unstable tasks a number of times.  
RETRY_COUNT=5

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

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
acquire_sem_or_wait()
{
    local lockpath="/tmp/${1}.lock.d"
    echo "Acquiring ${lockpath}"
    while true; do
        mkdir "${lockpath}" 2>/dev/null
        if [ $? -eq 0 ]; then
            break;
        fi
        echo "Waiting for lock $1"
        sleep 10
    done
}

release_sem()
{
    rmdir "/tmp/${1}.lock.d"
}

78 79
restore_nuget()
{
80 81 82
    # restore coreclr runtime package
    pushd /tmp
    local coreclr_package_name="coreclr.linux.1.zip"
83
    rm $coreclr_package_name 2>/dev/null
84 85 86 87
    curl -O https://dotnetci.blob.core.windows.net/roslyn/$coreclr_package_name
    unzip -uoq $coreclr_package_name -d ~/
    popd

88 89
    acquire_sem_or_wait "restore_nuget"

J
Jared Parsons 已提交
90
    local package_name="nuget.15.zip"
91
    local target="/tmp/$package_name"
A
Andy Gocke 已提交
92 93
    echo "Installing NuGet Packages $target"
    if [ -f $target ]; then
94 95
        if [ "$USE_CACHE" = "true" ]; then
            echo "Already installed"
96
            release_sem "restore_nuget"
97 98 99 100
            return
        fi
    fi

101
    pushd /tmp/
102 103 104

    rm $package_name 2>/dev/null
    curl -O https://dotnetci.blob.core.windows.net/roslyn/$package_name
105
    unzip -uoq $package_name -d ~/
106 107
    if [ $? -ne 0 ]; then
        echo "Unable to download NuGet packages"
108
        release_sem "restore_nuget"
109 110 111 112
        exit 1
    fi

    popd
113 114

    release_sem "restore_nuget"
115 116
}

117
run_msbuild()
J
jaredpar 已提交
118
{
119 120 121 122
    local is_good=false
    
    for i in `seq 1 $RETRY_COUNT`
    do
123
        mono $MONO_ARGS ~/.nuget/packages/Microsoft.Build.Mono.Debug/14.1.0-prerelease/lib/MSBuild.exe /v:m /p:SignAssembly=false /p:UseRoslynAnalyzers=false /p:DebugSymbols=false "$@"
124 125 126 127 128 129 130 131 132 133
        if [ $? -eq 0 ]; then
            is_good=true
            break
        fi

        echo Build retry $i
    done

    if [ "$is_good" != "true" ]; then
        echo Build failed
J
jaredpar 已提交
134 135 136 137
        exit 1
    fi
}

J
jaredpar 已提交
138 139 140 141
# NuGet crashes on occasion during restore.  This isn't a fatal action so 
# we re-run it a number of times.  
run_nuget()
{
142 143 144
    local is_good=false
    for i in `seq 1 $RETRY_COUNT`
    do
J
Jared Parsons 已提交
145
        mono $MONO_ARGS .nuget/NuGet.exe "$@"
J
jaredpar 已提交
146
        if [ $? -eq 0 ]; then
147 148
            is_good=true
            break
J
jaredpar 已提交
149 150 151
        fi
    done

152 153
    if [ "$is_good" != "true" ]; then
        echo NuGet failed
J
jaredpar 已提交
154 155 156 157
        exit 1
    fi
}

J
Jared Parsons 已提交
158
# Run the compilation.  Can pass additional build arguments as parameters
J
jaredpar 已提交
159 160 161
compile_toolset()
{
    echo Compiling the toolset compilers
J
Jared Parsons 已提交
162
    echo -e "Compiling the C# compiler"
A
Andy Gocke 已提交
163
    run_msbuild src/Compilers/CSharp/CscCore/CscCore.csproj /p:Configuration=$BUILD_CONFIGURATION
J
Jared Parsons 已提交
164
    echo -e "Compiling the VB compiler"
A
Andy Gocke 已提交
165
    run_msbuild src/Compilers/VisualBasic/VbcCore/VbcCore.csproj /p:Configuration=$BUILD_CONFIGURATION
J
jaredpar 已提交
166 167
}

168
# Save the toolset binaries from Binaries/BUILD_CONFIGURATION to Binaries/Bootstrap
J
jaredpar 已提交
169 170 171
save_toolset()
{
    mkdir Binaries/Bootstrap
A
Andy Gocke 已提交
172 173 174 175 176 177 178 179 180 181 182 183
    cp Binaries/$BUILD_CONFIGURATION/core-clr/* Binaries/Bootstrap

    if [ "$OS_NAME" == "Linux" ]; then
      # Copy over the CoreCLR runtime
      ./build/linux/copy-coreclr-runtime.sh Binaries/Bootstrap
      if [ $? -ne 0 ]; then
        echo Saving bootstrap binaries failed
        exit 1
      fi
      chmod +x Binaries/Bootstrap/csc
      chmod +x Binaries/Bootstrap/vbc
    fi 
J
jaredpar 已提交
184 185 186 187 188 189 190
}

# 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
191
    mono $MONO_ARGS ~/.nuget/packages/Microsoft.Build.Mono.Debug/14.1.0-prerelease/lib/MSBuild.exe /v:m /t:Clean build/Toolset.sln /p:Configuration=$BUILD_CONFIGURATION
192
    rm -rf Binaries/$BUILD_CONFIGURATION
J
jaredpar 已提交
193 194 195
}

build_roslyn()
196
{    
A
Andy Gocke 已提交
197 198 199 200 201 202
    local bootstrapArg=""

    if [ "$OS_NAME" == "Linux" ]; then
      bootstrapArg="/p:CscToolPath=$(pwd)/Binaries/Bootstrap /p:CscToolExe=csc \
/p:VbcToolPath=$(pwd)/Binaries/Bootstrap /p:VbcToolExe=vbc"
    fi
J
jaredpar 已提交
203

J
Jared Parsons 已提交
204
    echo Building CrossPlatform.sln
205
    run_msbuild $bootstrapArg CrossPlatform.sln /p:Configuration=$BUILD_CONFIGURATION
J
jaredpar 已提交
206 207
}

J
jaredpar 已提交
208 209 210
# Install the specified Mono toolset from our Azure blob storage.
install_mono_toolset()
{
211
    local target=/tmp/$1
J
jaredpar 已提交
212
    echo "Installing Mono toolset $1"
213 214 215

    acquire_sem_or_wait "$1"

216
    if [ -d $target ]; then
J
Jared Parsons 已提交
217 218
        if [ "$USE_CACHE" = "true" ]; then
            echo "Already installed"
219
            release_sem "$1"
J
Jared Parsons 已提交
220 221
            return
        fi
J
jaredpar 已提交
222 223 224 225
    fi

    pushd /tmp

226
    rm -r $target 2>/dev/null
J
Jared Parsons 已提交
227
    rm $1.tar.bz2 2>/dev/null
J
jaredpar 已提交
228 229 230 231
    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"
232
        release_sem "$1"
J
jaredpar 已提交
233 234 235 236
        exit 1
    fi

    popd
237
    release_sem "$1"
J
jaredpar 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
}

# 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
256
        MONO_TOOLSET_NAME=mono.mac.3
J
jaredpar 已提交
257
    elif [ "$OS_NAME" = "Linux" ]; then
A
Andy Gocke 已提交
258
        MONO_TOOLSET_NAME=mono.linux.3
J
jaredpar 已提交
259 260 261 262 263 264 265 266 267
    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 已提交
268 269
test_roslyn()
{
270
    local xunit_runner=~/.nuget/packages/xunit.runners/$XUNIT_VERSION/tools/xunit.console.x86.exe
271 272
    local test_binaries=(
        Roslyn.Compilers.CSharp.CommandLine.UnitTests
J
jaredpar 已提交
273 274 275
        Roslyn.Compilers.CSharp.Syntax.UnitTests
        Roslyn.Compilers.CSharp.Semantic.UnitTests
        Roslyn.Compilers.CSharp.Symbol.UnitTests
276 277
        Roslyn.Compilers.VisualBasic.Syntax.UnitTests)
    local any_failed=false
J
jaredpar 已提交
278

279 280
    for i in "${test_binaries[@]}"
    do
J
Jared Parsons 已提交
281
        mono $MONO_ARGS $xunit_runner Binaries/$BUILD_CONFIGURATION/$i.dll -xml Binaries/$BUILD_CONFIGURATION/$i.TestResults.xml -noshadow
282 283 284 285
        if [ $? -ne 0 ]; then
            any_failed=true
        fi
    done
J
jaredpar 已提交
286

287 288
    if [ "$any_failed" = "true" ]; then
        echo Unit test failed
J
jaredpar 已提交
289
        exit 1
J
jaredpar 已提交
290
    fi
J
Jared Parsons 已提交
291 292
}

J
Jared Parsons 已提交
293 294 295
echo Clean out the enlistment
git clean -dxf . 

296
restore_nuget
J
Jared Parsons 已提交
297 298
set_mono_path
which mono
J
jaredpar 已提交
299 300 301 302
compile_toolset
save_toolset
clean_roslyn
build_roslyn
J
jaredpar 已提交
303
test_roslyn
J
jaredpar 已提交
304