Skip to content

Commit

Permalink
improve build telemetry (#8239)
Browse files Browse the repository at this point in the history
* add windows build telemetry

* fix linux build telemetry
  • Loading branch information
brettfo authored Jan 17, 2020
1 parent 4d1e140 commit 04119ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
10 changes: 10 additions & 0 deletions eng/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ param (

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
$BuildCategory = ""
$BuildMessage = ""

function Print-Usage() {
Write-Host "Common settings:"
Expand Down Expand Up @@ -303,6 +305,9 @@ function EnablePreviewSdks() {
}

try {
$script:BuildCategory = "Build"
$script:BuildMessage = "Failure preparing build"

Process-Arguments

. (Join-Path $PSScriptRoot "build-utils.ps1")
Expand All @@ -317,9 +322,11 @@ try {
}

if ($bootstrap) {
$script:BuildMessage = "Failure building bootstrap compiler"
$bootstrapDir = Make-BootstrapBuild
}

$script:BuildMessage = "Failure building product"
if ($restore -or $build -or $rebuild -or $pack -or $sign -or $publish) {
if ($noVisualStudio) {
BuildCompiler
Expand All @@ -332,6 +339,8 @@ try {
VerifyAssemblyVersionsAndSymbols
}

$script:BuildCategory = "Test"
$script:BuildMessage = "Failure running tests"
$desktopTargetFramework = "net472"
$coreclrTargetFramework = "netcoreapp3.0"

Expand Down Expand Up @@ -421,6 +430,7 @@ catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
Write-PipelineTelemetryError -Category $script:BuildCategory -Message $script:BuildMessage
ExitWithExitCode 1
}
finally {
Expand Down
46 changes: 25 additions & 21 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ properties=""
docker=false
args=""

BuildCategory=""
BuildMessage=""

if [[ $# = 0 ]]
then
usage
Expand Down Expand Up @@ -150,6 +153,8 @@ done
. "$scriptroot/common/tools.sh"

function TestUsingNUnit() {
BuildCategory="Test"
BuildMessage="Error running tests"
testproject=""
targetframework=""
while [[ $# > 0 ]]; do
Expand Down Expand Up @@ -180,14 +185,12 @@ function TestUsingNUnit() {
projectname="${projectname%.*}"
testlogpath="$artifacts_dir/TestResults/$configuration/${projectname}_$targetframework.xml"
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"nunit;LogFilePath=$testlogpath\""
"$DOTNET_INSTALL_DIR/dotnet" $args || {
local exit_code=$?
Write-PipelineTelemetryError -category 'Test' "dotnet test failed for $testproject:$targetframework (exit code $exit_code)."
ExitWithExitCode $exit_code
}
"$DOTNET_INSTALL_DIR/dotnet" $args || exit $?
}

function BuildSolution {
BuildCategory="Build"
BuildMessage="Error preparing build"
local solution="FSharp.sln"
echo "$solution:"

Expand Down Expand Up @@ -229,33 +232,28 @@ function BuildSolution {
rm -fr $bootstrap_dir
fi
if [ ! -f "$bootstrap_dir/fslex.dll" ]; then
BuildMessage="Error building tools"
MSBuild "$repo_root/src/buildtools/buildtools.proj" \
/restore \
/p:Configuration=$bootstrap_config \
/t:Publish || {
local exit_code=$?
Write-PipelineTelemetryError -category 'Build' "Error building buildtools (exit code '$exit_code')."
ExitWithExitCode $exit_code
}
/t:Publish

mkdir -p "$bootstrap_dir"
cp -pr $artifacts_dir/bin/fslex/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fslex
cp -pr $artifacts_dir/bin/fsyacc/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fsyacc
fi
if [ ! -f "$bootstrap_dir/fsc.exe" ]; then
BuildMessage="Error building bootstrap"
MSBuild "$repo_root/proto.proj" \
/restore \
/p:Configuration=$bootstrap_config \
/t:Publish || {
local exit_code=$?
Write-PipelineTelemetryError -category 'Build' "Error building bootstrap compiler (exit code '$exit_code')."
ExitWithExitCode $exit_code
}
/t:Publish

cp -pr $artifacts_dir/bin/fsc/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fsc
fi

# do real build
BuildMessage="Error building solution"
MSBuild $toolset_build_proj \
$bl \
/v:$verbosity \
Expand All @@ -271,13 +269,20 @@ function BuildSolution {
/p:ContinuousIntegrationBuild=$ci \
/p:QuietRestore=$quiet_restore \
/p:QuietRestoreBinaryLog="$binary_log" \
$properties || {
local exit_code=$?
Write-PipelineTelemetryError -category 'Build' "Error building solution (exit code '$exit_code')."
ExitWithExitCode $exit_code
}
$properties
}

function TrapAndReportError {
local exit_code=$?
if [[ ! $exit_code == 0 ]]; then
Write-PipelineTelemetryError -category $BuildCategory "$BuildMessage (exit code '$exit_code')."
ExitWithExitCode $exit_code
fi
}

# allow early termination to report the appropriate build failure reason
trap TrapAndReportError EXIT

InitializeDotNetCli $restore

BuildSolution
Expand All @@ -293,4 +298,3 @@ if [[ "$test_core_clr" == true ]]; then
fi

ExitWithExitCode 0

0 comments on commit 04119ce

Please sign in to comment.