forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map shortened scala test suite names to long names on Windows (digita…
…l-asset#10628) * Generate short to long name mapping in aspect Maps shortened test names in da_scala_test_suite on Windows to their long name on Linux and MacOS. Names are shortened on Windows to avoid exceeding MAX_PATH. * Script to generate scala test name mapping * Generate scala-test-suite-name-map.json on Windows changelog_begin changelog_end * Generate UTF-8 with Unix line endings Otherwise the file will be formatted using UTF-16 with CRLF line endings, which confuses `jq` on Linux. * Apply Scala test name remapping before ES upload * Pipe bazel output into intermediate file Bazel writes the output of --experimental_show_artifacts to stderr instead of stdout. In Powershell this means that these outputs are not plain strings, but instead error objects. Simply redirecting these to stdout and piping them into further processing will lead to indeterministically missing items or indeterministically introduced additional newlines which may break paths. To work around this we extract the error message from error objects, introduce appropriate newlines, and write the output to a temporary file before further processing. This solution is taken and adapted from https://stackoverflow.com/a/48671797/841562 * Add copyright header Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
- Loading branch information
1 parent
6e4a24c
commit 7b94b06
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# $ErrorActionPreference = 'Stop' causes the script to fail because Bazel writes to stderr. | ||
$ErrorActionPreference = 'Continue' | ||
|
||
[string[]]$scala_test_targets = bazel.exe query "kind(scala_test, deps(kind(test_suite, //...), 1))" | ||
if ($lastexitcode -ne 0) { | ||
throw "bazel query returned non-zero exit code: $lastexitcode" | ||
} | ||
|
||
if ($scala_test_targets.count -gt 0) { | ||
|
||
try { | ||
|
||
# Bazel writes the output of --experimental_show_artifacts to stderr | ||
# instead of stdout. In Powershell this means that these outputs are not | ||
# plain strings, but instead error objects. Simply redirecting these to | ||
# stdout and piping them into further processing will lead to | ||
# indeterministically missing items or indeterministically introduced | ||
# additional newlines which may break paths. | ||
# | ||
# To work around this we extract the error message from error objects, | ||
# introduce appropriate newlines, and write the output to a temporary file | ||
# before further processing. | ||
# | ||
# This solution is taken and adapted from | ||
# https://stackoverflow.com/a/48671797/841562 | ||
$bazelexitcode = 0 | ||
$tmp = New-TemporaryFile | ||
try { | ||
$append = $false | ||
$out = [System.IO.StreamWriter]::new($tmp, $append) | ||
bazel.exe build ` | ||
"--aspects=//bazel_tools:scala.bzl%da_scala_test_short_name_aspect" ` | ||
"--output_groups=scala_test_info" ` | ||
"--experimental_show_artifacts" ` | ||
@scala_test_targets ` | ||
2>&1 | % { | ||
if ($_ -is [System.Management.Automation.ErrorRecord]) { | ||
if ($_.TargetObject -ne $null) { | ||
$out.WriteLine(); | ||
} | ||
$out.Write($_.Exception.Message) | ||
} else { | ||
$out.WriteLine($_) | ||
} | ||
} | ||
$bazelexitcode = $lastexitcode | ||
} finally { | ||
$out.Close() | ||
} | ||
|
||
if ($bazelexitcode -ne 0) { | ||
$errmsg = Get-Content $tmp | ||
Write-Error -Message "$errmsg" | ||
throw "bazel build returned non-zero exit code: $lastexitcode" | ||
} | ||
|
||
Get-Content $tmp | | ||
% { if ( $_ -match ">>>(?<filename>.*)" ) { Get-Content $Matches.filename } } | | ||
jq -acsS "map({key:.short_label,value:.long_label})|from_entries" | ||
|
||
if ($lastexitcode -ne 0) { | ||
throw "jq returned non-zero exit code: $lastexitcode" | ||
} | ||
} finally { | ||
Remove-Item $tmp | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters