Use one env var to work around msbuild escaping

This commit is contained in:
Jackson Schuster 2024-03-22 10:37:04 -07:00
parent a82bdc9bf3
commit 2a70b8a4dc
3 changed files with 21 additions and 15 deletions

View file

@ -34,7 +34,7 @@
<RootRepo Condition="'$(ShortStack)' == 'true'">runtime</RootRepo>
</PropertyGroup>
<!-- See https://github.com/dotnet/arcade/blob/main/Documentation/UnifiedBuild/Unified-Build-Controls.md#output-controls for
<!-- See https://github.com/dotnet/arcade/blob/main/Documentation/UnifiedBuild/Unified-Build-Controls.md#output-controls for
control set definition. -->
<PropertyGroup Label="CalculateArch">
<!-- Build architecture is what we are building on. -->
@ -205,7 +205,6 @@
<PropertyGroup>
<XPlatSourceBuildTasksAssembly>$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'Microsoft.DotNet.SourceBuild.Tasks.XPlat', '$(Configuration)', 'Microsoft.DotNet.SourceBuild.Tasks.XPlat.dll'))</XPlatSourceBuildTasksAssembly>
<LeakDetectionTasksAssembly>$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'Microsoft.DotNet.SourceBuild.Tasks.LeakDetection', '$(Configuration)', 'Microsoft.DotNet.SourceBuild.Tasks.LeakDetection.dll'))</LeakDetectionTasksAssembly>
<SdkArchiveDiffTasksAssembly>$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff', '$(Configuration)', 'Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff.dll'))</SdkArchiveDiffTasksAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(EnablePoison)' == 'true'">

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<UnifiedBuildValidationTestsDir>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'test', 'Microsoft.DotNet.UnifiedBuild.Tests'))</UnifiedBuildValidationTestsDir>
<UnifiedBuildValidationTestsProject>$([MSBuild]::NormalizeDirectory('$(UnifiedBuildValidationTestsDir)', 'Microsoft.DotNet.UnifiedBuild.Tests'))</UnifiedBuildValidationTestsProject>
<UnifiedBuildValidationTestsProject>$([MSBuild]::NormalizePath('$(UnifiedBuildValidationTestsDir)', 'Microsoft.DotNet.UnifiedBuild.Tests.csproj'))</UnifiedBuildValidationTestsProject>
</PropertyGroup>
<Target Name="RunUnifiedBuildValidation"
@ -18,13 +18,17 @@
<PropertyGroup>
<SdkTarballPath>%(SdkTarballItem.Identity)</SdkTarballPath>
<_EnvVarRunSettingsPrefix>RunConfiguration.EnvironmentVariables</_EnvVarRunSettingsPrefix>
<EnvironmentVariableRunSettings>@(_UnifiedBuildValidationEnvVar->'$(RunConfiguration.EnvironmentVariables).%(Identity)=%(Value)')</EnvironmentVariableRunSettings>
<EnvironmentVariableRunSettings>@(_UnifiedBuildValidationEnvVar->'%(Identity)=%(Value)')</EnvironmentVariableRunSettings>
<runSettings>RunConfiguration.EnvironmentVariables.UNIFIED_BUILD_VALIDATION_ARGS=$([MSBuild]::Escape($(EnvironmentVariableRunSettings)))</runSettings>
</PropertyGroup>
<MSBuild Projects="$(UnifiedBuildValidationTestsDir)"
Targets="Test"
Properties="Configuration=$(Configuration);VSTestUseMSBuildOutput=false;VSTestLogger=trx;VSTestCLIRunSettings=$(EnvironmentVariableRunSettings)" />
<MSBuild Projects="$(UnifiedBuildValidationTestsProject)"
Targets="VSTest"
Properties="VsTestUseMSBuildOutput=true;
IsTestProject=true;
Configuration=$(Configuration);
VSTestLogger=trx;
VSTestCLIRunSettings=$(runSettings)" />
</Target>

View file

@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
@ -11,20 +12,22 @@ using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
public class Config : IDisposable
{
IMessageSink _sink;
public Config(IMessageSink sink)
{
_sink = sink;
BuildVersion = Environment.GetEnvironmentVariable(BuildVersionEnv) ?? throw new InvalidOperationException($"'{BuildVersionEnv}' must be specified");
PortableRid = Environment.GetEnvironmentVariable(PortableRidEnv) ?? throw new InvalidOperationException($"'{PortableRidEnv}' must be specified");
UbSdkArchivePath = Environment.GetEnvironmentVariable(UbSdkTarballPathEnv) ?? throw new InvalidOperationException($"'{UbSdkTarballPathEnv}' must be specified");
TargetRid = Environment.GetEnvironmentVariable(TargetRidEnv) ?? throw new InvalidOperationException($"'{TargetRidEnv}' must be specified");
sink.OnMessage(new DiagnosticMessage($"Environment: '{Environment.GetEnvironmentVariable("UNIFIED_BUILD_VALIDATION_ARGS")}'"));
var env = Environment.GetEnvironmentVariable("UNIFIED_BUILD_VALIDATION_ARGS") ?? throw new InvalidOperationException("UNIFIED_BUILD_VALIDATION_ARGS must be specified");
var envDict = env.Split(';').Select(s => s.Split('=')).ToDictionary(s => s[0], s => s[1]);
BuildVersion = envDict[BuildVersionEnv];
PortableRid = envDict[PortableRidEnv];
UbSdkArchivePath = envDict[UbSdkTarballPathEnv];
TargetRid = envDict[TargetRidEnv];
TargetArchitecture = TargetRid.Split('-')[1];
WarnOnSdkContentDiffs = bool.TryParse(Environment.GetEnvironmentVariable(WarnSdkContentDiffsEnv), out bool warnOnSdkContentDiffs) && warnOnSdkContentDiffs;
MsftSdkArchivePath = Environment.GetEnvironmentVariable(MsftSdkTarballPathEnv) ?? DownloadMsftSdkArchive().Result;
MsftSdkArchivePath = envDict.TryGetValue(MsftSdkTarballPathEnv, out var msftSdkPath) ? msftSdkPath : DownloadMsftSdkArchive().Result;
}
public const string BuildVersionEnv = "UNIFIED_BUILD_VALIDATION_BUILD_VERSION";