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

Remove MS.CA.Test.Resources.Proprietary PackageReference #75037

Merged
merged 5 commits into from
Sep 11, 2024
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
1 change: 0 additions & 1 deletion eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Test.Resources.Proprietary" Version="2.0.44" />
<PackageVersion Include="Microsoft.DiaSymReader.Converter" Version="1.1.0-beta2-22302-02" />
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22302-02" />
<PackageVersion Include="Microsoft.Metadata.Visualizer" Version="1.0.0-beta3.21075.2" />
Expand Down
3 changes: 1 addition & 2 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Test.Resources.Proprietary;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.DiaSymReader;
Expand Down Expand Up @@ -4339,7 +4338,7 @@ public void AppConfigBasic()
</runtime>
</configuration>");

var silverlight = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).Path;
var silverlight = Temp.CreateFile().WriteAllBytes(Silverlight.System).Path;
var net4_0dll = Temp.CreateFile().WriteAllBytes(Net461.Resources.System).Path;

// Test linking two appconfig dlls with simple src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Runtime.InteropServices;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Resources.Proprietary;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void AppConfigCsc()
</runtime>
</configuration>").Path;

var silverlight = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).Path;
var silverlight = Temp.CreateFile().WriteAllBytes(Silverlight.System).Path;
var net4_0dll = Temp.CreateFile().WriteAllBytes(Net461.Resources.System).Path;

var outWriter = new StringWriter(CultureInfo.InvariantCulture);
Expand Down
7 changes: 4 additions & 3 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
using System.IO;
using System.Linq;
using System.Threading;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Resources.Proprietary;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -473,7 +473,8 @@ public static void Main(string[] args)
}
}";
var tree = Parse(source);
var compilation = CreateEmptyCompilation(tree, new[] { MscorlibRefSilverlight }, TestOptions.ReleaseExe, assemblyName: "Test");
var compilation = CreateEmptyCompilation(tree, [Net461.References.mscorlib], TestOptions.ReleaseExe, assemblyName: "Test");
compilation.MakeMemberMissing(SpecialMember.System_Array__LongLength);
CompileAndVerify(compilation, expectedOutput: "k");
}

Expand Down Expand Up @@ -15130,7 +15131,7 @@ static void Main()
}
}";

var testReference = AssemblyMetadata.CreateFromImage(ProprietaryTestResources.Repros.BadDefaultParameterValue).GetReference();
var testReference = AssemblyMetadata.CreateFromImage(TestResources.SymbolsTests.Metadata.BadDefaultParameterValue).GetReference();
var compilation = CompileAndVerify(source, references: new[] { testReference });
compilation.VerifyIL("Program.Main", @"
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Resources.Proprietary;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Collections.Immutable;
using System.Linq;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
Expand Down Expand Up @@ -2119,7 +2120,7 @@ void Test(string s)
}
";

var comp = CreateEmptyCompilation(source, new[] { MscorlibRefPortable });
var comp = CreateEmptyCompilation(source, [SystemRuntimePP7Ref]);
comp.VerifyDiagnostics();

var tree = comp.SyntaxTrees.Single();
Expand Down
21 changes: 12 additions & 9 deletions src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ public static void Goo(Func<Y> func)

var comp1 = CreateCompilation(
Parse(text1),
new[] { TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true) },
targetFramework: TargetFramework.NetFramework,
references: [TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true)],
options: TestOptions.ReleaseDll);

var text2 = @"
Expand All @@ -429,22 +430,24 @@ public static void Main()

var comp2 = CreateCompilation(
Parse(text2),
new MetadataReference[]
{
targetFramework: TargetFramework.NetFramework,
references:
[
new CSharpCompilationReference(comp1),
TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true)
},
TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true)
],
options: TestOptions.ReleaseExe);

CompileAndVerify(comp2, expectedOutput: "Y").Diagnostics.Verify();

var comp3 = CreateCompilation(
Parse(text2),
new MetadataReference[]
{
targetFramework: TargetFramework.NetFramework,
references:
[
comp1.EmitToImageReference(),
TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true)
},
TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true)
],
options: TestOptions.ReleaseExe);

CompileAndVerify(comp3, expectedOutput: "Y").Diagnostics.Verify();
Expand Down
3 changes: 1 addition & 2 deletions src/Compilers/CSharp/Test/WinRT/Metadata/WinMdDumpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Resources.Proprietary;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
Expand All @@ -27,7 +26,7 @@ public class WinMdDumpTest : CSharpTestBase
private readonly MetadataReference _windowsRef = MetadataReference.CreateFromImage(TestResources.WinRt.Windows.AsImmutableOrNull());
private readonly MetadataReference _systemRuntimeRef = MetadataReference.CreateFromImage(Net461.Resources.SystemRuntime.AsImmutableOrNull());
private readonly MetadataReference _systemObjectModelRef = MetadataReference.CreateFromImage(Net461.Resources.SystemObjectModel.AsImmutableOrNull());
private readonly MetadataReference _windowsRuntimeUIXamlRef = MetadataReference.CreateFromImage(ProprietaryTestResources.v4_0_30319_17929.System_Runtime_WindowsRuntime_UI_Xaml.AsImmutableOrNull());
private readonly MetadataReference _windowsRuntimeUIXamlRef = MetadataReference.CreateFromImage(TestResources.NetFX.WinRt.SystemRuntimeWindowsRuntimeUIXaml.AsImmutableOrNull());
private readonly MetadataReference _interopServicesWindowsRuntimeRef = MetadataReference.CreateFromImage(Net461.Resources.SystemRuntimeInteropServicesWindowsRuntime.AsImmutableOrNull());

private void AppendMembers(StringBuilder result, NamespaceOrTypeSymbol container, string indent)
Expand Down
22 changes: 4 additions & 18 deletions src/Compilers/Core/CodeAnalysisTest/CryptoBlobParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,10 @@ public void TryGetPublicKeyFailsForInvalidKeyBlobs()
"0602000000240000DEADBEEF" + new string('0', 136 * 2), // public key blob without magic public key
};

Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[0]), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[1]), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[2]), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[3]), out _, out _));
}

private static ImmutableArray<byte> HexToBin(string input)
{
Assert.True(input != null && (input.Length & 1) == 0, "invalid input string.");

var result = new byte[input.Length >> 1];

for (var i = 0; i < result.Length; i++)
{
result[i] = byte.Parse(input.Substring(i << 1, 2), NumberStyles.HexNumber);
}

return ImmutableArray.Create(result);
Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[0].AsSpan()), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[1].AsSpan()), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[2].AsSpan()), out _, out _));
Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[3].AsSpan()), out _, out _));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiffPlex" />
<PackageReference Include="Microsoft.CodeAnalysis.Test.Resources.Proprietary" />
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" />
<PackageReference Include="Microsoft.Metadata.Visualizer" />
<PackageReference Include="Microsoft.NETCore.Platforms" />
Expand Down
105 changes: 105 additions & 0 deletions src/Compilers/Test/Core/Mocks/Silverlight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;

namespace Roslyn.Test.Utilities;

/// <summary>
/// The assemblies produced here are designed to mimic the public key token structure of
/// silverlight references. This often presents challenges to the compiler because it has
/// to know that two mscorlib with different public key tokens need to be treated as the
/// identicial. The assemblies produced here have the same identity of those that come
/// from silverlight but without necessarily the same type contents.
/// </summary>
Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth on this decision several times. The Silverlight references are only used right now to test assembly unification policies (that I could see). Rather than the overhead of bringing in more .dll files decided to just dynamically build the same assemblies that would let us test unification policy.

public static class Silverlight
{
private static readonly Lazy<(byte[], byte[])> s_tuple = new Lazy<(byte[], byte[])>(
() => BuildImages(),
LazyThreadSafetyMode.PublicationOnly);

public static byte[] Mscorlib => s_tuple.Value.Item1;

public static byte[] System => s_tuple.Value.Item2;

private static (byte[], byte[]) BuildImages()
{
const string corlibExtraCode = """
using System;
using System.Reflection;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: these usings look unnecessary. Maybe adding VerifyDiagnostics to the compilations we create here would catch that?


namespace System.Reflection;

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class AssemblyFileVersionAttribute : Attribute
{
public string Version { get; }
public AssemblyFileVersionAttribute(string version)
{
Version = version;
}
}
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class AssemblyVersionAttribute : Attribute
{
public string Version { get; }
public AssemblyVersionAttribute(string version)
{
Version = version;
}
}
""";

const string assemblyAttributes = """
using System.Reflection;

[assembly: AssemblyFileVersion("5.0.5.0")]
[assembly: AssemblyVersion("5.0.5.0")]
""";

var publicKeyText = "" +
"00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f" +
"383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148" +
"e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e" +
"5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab";
var publicKey = TestHelpers.HexToByte(publicKeyText.AsSpan());
var publicKeyToken = AssemblyIdentity.CalculatePublicKeyToken(publicKey);
Debug.Assert("7C-EC-85-D7-BE-A7-79-8E" == BitConverter.ToString(publicKeyToken.ToArray()));

var options = new CSharpCompilationOptions(
OutputKind.DynamicallyLinkedLibrary,
cryptoPublicKey: publicKey,
optimizationLevel: OptimizationLevel.Release);
var mscorlibCompilation = CSharpCompilation.Create(
"mscorlib",
[
CSharpSyntaxTree.ParseText(SourceText.From(TestResources.NetFX.Minimal.mincorlib_cs)),
CSharpSyntaxTree.ParseText(SourceText.From(corlibExtraCode)),
CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes)),
],
options: options);

var mscorlib = mscorlibCompilation.EmitToStream(EmitOptions.Default.WithRuntimeMetadataVersion("v4.0.30319"));

var systemCompilation = CSharpCompilation.Create(
"System",
syntaxTrees: [CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes))],
references: [mscorlibCompilation.EmitToImageReference()],
options: options);

var system = systemCompilation.EmitToStream();
return (mscorlib.ToArray(), system.ToArray());
}
}
83 changes: 83 additions & 0 deletions src/Compilers/Test/Core/Mocks/StdOle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;

namespace Roslyn.Test.Utilities;

/// <summary>
/// This type produces stdole.dll that mimic the version used in the original Roslyn
/// interop tests.
/// </summary>
public static class StdOle
{
public static PortableExecutableReference Build(IEnumerable<MetadataReference> references)
{
const string assemblyAttributes = """
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: ImportedFromTypeLib("stdole")]
[assembly: Guid("00020430-0000-0000-c000-000000000046")]
[assembly: PrimaryInteropAssembly(2, 0)]
[assembly: AssemblyVersion("7.0.3300.0")]

""";

const string code = """
using System.Runtime.InteropServices;
namespace stdole;

public struct GUID
{
public uint Data1;
public ushort Data2;
public ushort Data3;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] Data4;
}

[ComImport]
[Guid("00020400-0000-0000-C000-000000000046")]
[TypeLibType(512)]
public interface IDispatch
{
}
""";

var publicKeyText = "" +
"002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e8" +
"4aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980" +
"957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1" +
"dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293";
var publicKey = TestHelpers.HexToByte(publicKeyText.AsSpan());
var publicKeyToken = AssemblyIdentity.CalculatePublicKeyToken(publicKey);
Debug.Assert("B0-3F-5F-7F-11-D5-0A-3A" == BitConverter.ToString(publicKeyToken.ToArray()));

var options = new CSharpCompilationOptions(
OutputKind.DynamicallyLinkedLibrary,
cryptoPublicKey: publicKey,
optimizationLevel: OptimizationLevel.Release);
var compilation = CSharpCompilation.Create(
"stdole",
[
CSharpSyntaxTree.ParseText(SourceText.From(code)),
CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes))
],
references: references,
options);

return compilation.EmitToPortableExecutableReference();
}
}
Loading
Loading