Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check exitcodes in build script #3236

Merged
merged 2 commits into from
Jan 6, 2022

Conversation

nohwnd
Copy link
Member

@nohwnd nohwnd commented Jan 5, 2022

Description

Check exit codes of executables we call and write the actual call into verbose rather than a copy of the command that is sometimes not updated.

Related issue

Kindly link any related issues. E.g. Fixes #xyz.

[string] $Arguments,
[int[]] $IgnoreExitCode
)
Write-Verbose "Invoking: $Command $Arguments"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided that my understanding is correct, the only mandatory argument of this function is $Command, in which case how would Write-Verbose work if we provide no arguments to the command ? Will the $Arguments be empty or null ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$Arguments will be defined and will be $null, so it will make no difference to the output, and won't fail even if we were running in strict mode.

@@ -51,15 +53,25 @@ $env:DOTNET_CLI_VERSION = $GlobalJson.tools.dotnet
$env:VSWHERE_VERSION = "2.0.2"
$env:MSBUILD_VERSION = "15.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this MSBUILD_VERSION be updated too ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK I updated the build tools because they were using parameter that is not present in the referenced version, and because the exit code was not checked it just "silently" failed. I don't see that environment variable used anywhere, and if it has significance to msbuild, then it is not breaking, and I don't want to fiddle with this any more than I need to 😁

Write-Output "... $message"
try {
$Host.UI.RawUI.ForegroundColor = if ("Success" -eq $Level) { "Green" } else { "Red" }
if ($message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe do some kind of early return here and basically do nothing, not even change the ForegroundColor if the $message variable is empty ? Something along the lines of:

function Write-Log {
    param (...)

    if (!$message)
    {
        return
    }

    try {
        ...
    }
    finally {
        ...
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might, but it won't save any time. Thanks for the feedback, but I won't do it now.

@@ -54,6 +54,8 @@ Param(
[String[]] $Steps = @("InstallDotnet", "Restore", "UpdateLocalization", "Build", "Publish", "PrepareAcceptanceTests")
)

$ErrorActionPreference = 'Stop'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be any use case in which we'd like to have this error action preference configurable ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. This is a best practice. The common.lib.ps1 file actually sets this as well. Setting this to Stop, and optionally overriding it to Continue on commands that are allowed to fail is how this is done.

@nohwnd nohwnd merged commit eb16336 into microsoft:main Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants