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

Add Microsoft.WinGet.Configuration module to ReleaseStatic configuration #3262

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/AppInstallerCLI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,10 @@ Global
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Fuzzing|x86.ActiveCfg = Debug|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Fuzzing|x86.Build.0 = Debug|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|ARM64.ActiveCfg = Release|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.ActiveCfg = Release|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.ActiveCfg = Release|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|ARM64.ActiveCfg = Release|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|ARM64.Build.0 = Release|Any CPU
{71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|x64.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1063,8 +1065,10 @@ Global
{167F634B-A3AD-494E-8E67-B888103E35FF}.Fuzzing|x86.ActiveCfg = Debug|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.Fuzzing|x86.Build.0 = Debug|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|ARM64.ActiveCfg = Release|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.ActiveCfg = Release|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.ActiveCfg = Release|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.Release|ARM64.ActiveCfg = Release|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.Release|ARM64.Build.0 = Release|Any CPU
{167F634B-A3AD-494E-8E67-B888103E35FF}.Release|x64.ActiveCfg = Release|Any CPU
Expand All @@ -1090,8 +1094,10 @@ Global
{C54F80ED-B736-49B0-9BD3-662F57024D01}.Fuzzing|x86.ActiveCfg = Debug|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.Fuzzing|x86.Build.0 = Debug|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|ARM64.ActiveCfg = Release|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.ActiveCfg = Release|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.ActiveCfg = Release|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|ARM64.ActiveCfg = Release|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|ARM64.Build.0 = Release|Any CPU
{C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|x64.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<!-- Disable warning for CS1591 for cswinrt auto-generated files -->
<NoWarn>1591</NoWarn>
<Configurations>Debug;Release;ReleaseStatic</Configurations>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<CsWinRTComponent>true</CsWinRTComponent>
<CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ namespace Microsoft.WinGet.Configuration.Acl
/// </summary>
internal class CustomAssemblyLoadContext : AssemblyLoadContext
{
// The assemblies must be loaded in the default context.
// Loading WinRT.Runtime.dll in an ALC when is already loaded in the default context
// will result on 'Attempt to update previously set global instance.'
private static readonly IEnumerable<string> DefaultContextAssemblies = new string[]
{
@"WinRT.Runtime.dll",
};

private static readonly string SharedDependencyPath = Path.Combine(
Path.GetDirectoryName(typeof(CustomAssemblyLoadContext).Assembly.Location),
"SharedDependencies");
Expand Down Expand Up @@ -64,6 +72,16 @@ private CustomAssemblyLoadContext()
/// <returns>The assembly, null if not in our assembly location.</returns>
internal static Assembly ResolvingHandler(AssemblyLoadContext context, AssemblyName assemblyName)
{
string name = $"{assemblyName.Name}.dll";
if (DefaultContextAssemblies.Any(a => a.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
string sharedPath = Path.Combine(SharedDependencyPath, name);
if (File.Exists(sharedPath))
{
return AssemblyLoadContext.Default.LoadFromAssemblyPath(sharedPath);
}
}

string path = $"{Path.Combine(DirectDependencyPath, assemblyName.Name)}.dll";
if (File.Exists(path))
{
Expand All @@ -76,6 +94,12 @@ internal static Assembly ResolvingHandler(AssemblyLoadContext context, AssemblyN
/// <inheritdoc/>
protected override Assembly Load(AssemblyName assemblyName)
{
string name = $"{assemblyName.Name}.dll";
if (DefaultContextAssemblies.Any(a => a.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
return null;
}

string path = $"{Path.Combine(SharedDependencyPath, assemblyName.Name)}.dll";
if (File.Exists(path))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Keep in sync with attributes in AssemblyInfo.cs -->
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>$(OutputPath)\$(MSBuildProjectName).xml</DocumentationFile>
<RuntimeIdentifier>win</RuntimeIdentifier>
<BuildOutputDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</BuildOutputDirectory>
<RootNamespace>Microsoft.WinGet.Configuration</RootNamespace>
<Configurations>Debug;Release;ReleaseStatic</Configurations>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -----------------------------------------------------------------------------
// <copyright file="AssemblyInfo.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------

#if NET

using System.Runtime.Versioning;

// Forcibly set the target and supported platforms due to the internal build setup.
// Keep in sync with project versions.
[assembly: TargetPlatform("Windows10.0.19041.0")]
[assembly: SupportedOSPlatform("Windows10.0.18362.0")]

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ internal Task<TResult> RunOnMTA<TResult>(Func<Task<TResult>> func)
/// Waits for the task to be completed. This MUST be called from the main thread.
/// </summary>
/// <param name="runningTask">Task to wait for.</param>
internal void Wait(Task runningTask)
/// <param name="writeCommand">The command that can write to PowerShell.</param>
internal void Wait(Task runningTask, AsyncCommand? writeCommand = null)
{
writeCommand ??= this;

// This must be called in the main thread.
if (this.originalThread != Thread.CurrentThread)
{
Expand All @@ -204,9 +207,9 @@ internal void Wait(Task runningTask)

do
{
this.ConsumeStreams();
this.ConsumeAndWriteStreams(writeCommand);
}
while (!runningTask.IsCompleted && this.queuedStreams.IsCompleted);
while (!(runningTask.IsCompleted && this.queuedStreams.IsCompleted));

if (runningTask.IsFaulted)
{
Expand Down Expand Up @@ -237,7 +240,7 @@ internal void Write(StreamType type, object data)

if (this.originalThread == Thread.CurrentThread)
{
this.CmdletWrite(type, data);
this.CmdletWrite(type, data, this);
return;
}

Expand Down Expand Up @@ -319,7 +322,8 @@ internal void CompleteProgress(int activityId, string activity, string status)
/// This method must be called in the original thread.
/// WARNING: You must only call this when the task is completed or in Wait.
/// </summary>
internal void ConsumeStreams()
/// <param name="writeCommand">The command that can write to PowerShell.</param>
internal void ConsumeAndWriteStreams(AsyncCommand writeCommand)
{
// This must be called in the main thread.
if (this.originalThread != Thread.CurrentThread)
Expand All @@ -335,7 +339,7 @@ internal void ConsumeStreams()
var queuedOutput = this.queuedStreams.Take();
if (queuedOutput != null)
{
this.CmdletWrite(queuedOutput.Type, queuedOutput.Data);
this.CmdletWrite(queuedOutput.Type, queuedOutput.Data, writeCommand);
}
}
}
Expand All @@ -355,36 +359,36 @@ internal int GetNewProgressActivityId()
return Interlocked.Increment(ref this.progressActivityId);
}

private void CmdletWrite(StreamType streamType, object data)
private void CmdletWrite(StreamType streamType, object data, AsyncCommand writeCommand)
{
switch (streamType)
{
case StreamType.Debug:
this.PsCmdlet.WriteDebug((string)data);
writeCommand.PsCmdlet.WriteDebug((string)data);
break;
case StreamType.Verbose:
this.PsCmdlet.WriteVerbose((string)data);
writeCommand.PsCmdlet.WriteVerbose((string)data);
break;
case StreamType.Warning:
this.PsCmdlet.WriteWarning((string)data);
writeCommand.PsCmdlet.WriteWarning((string)data);
break;
case StreamType.Error:
this.PsCmdlet.WriteError((ErrorRecord)data);
writeCommand.PsCmdlet.WriteError((ErrorRecord)data);
break;
case StreamType.Progress:
// If the activity is already completed don't write progress.
var progressRecord = (ProgressRecord)data;
if (this.progressRecords[progressRecord.ActivityId] == ProgressRecordType.Processing)
{
this.PsCmdlet.WriteProgress(progressRecord);
writeCommand.PsCmdlet.WriteProgress(progressRecord);
}

break;
case StreamType.Object:
this.PsCmdlet.WriteObject(data);
writeCommand.PsCmdlet.WriteObject(data);
break;
case StreamType.Information:
this.PsCmdlet.WriteInformation(data, WriteInformationTags);
writeCommand.PsCmdlet.WriteInformation(data, WriteInformationTags);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void Continue(PSConfigurationJob psConfigurationJob)
if (psConfigurationJob.ConfigurationTask.IsCompleted)
{
// It is safe to print all output.
psConfigurationJob.StartCommand.ConsumeStreams();
psConfigurationJob.StartCommand.ConsumeAndWriteStreams(this);

this.Write(StreamType.Verbose, "The task was completed before waiting");
if (psConfigurationJob.ConfigurationTask.IsCompletedSuccessfully)
Expand Down Expand Up @@ -225,7 +225,7 @@ private void ContinueHelper(PSConfigurationJob psConfigurationJob)
{
// Signal the command that it can write to streams and wait for task.
this.Write(StreamType.Verbose, "Waiting for task to complete");
psConfigurationJob.StartCommand.Wait(psConfigurationJob.ConfigurationTask);
psConfigurationJob.StartCommand.Wait(psConfigurationJob.ConfigurationTask, this);
this.Write(StreamType.Object, psConfigurationJob.ConfigurationTask.Result);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Keep in sync with attributes in AssemblyInfo.cs -->
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Nullable>enable</Nullable>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>$(OutputPath)\$(MSBuildProjectName).xml</DocumentationFile>
<RuntimeIdentifier>win</RuntimeIdentifier>
<Configurations>Debug;Release;ReleaseStatic</Configurations>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -----------------------------------------------------------------------------
// <copyright file="AssemblyInfo.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------

#if NET

using System.Runtime.Versioning;

// Forcibly set the target and supported platforms due to the internal build setup.
// Keep in sync with project versions.
[assembly: TargetPlatform("Windows10.0.19041.0")]
[assembly: SupportedOSPlatform("Windows10.0.18362.0")]

#endif