Skip to content

Commit

Permalink
Merge pull request #5398 from TyOverby/4578-wildcard-deterministic
Browse files Browse the repository at this point in the history
Ban assembly versions with wildcards in deterministic builds
  • Loading branch information
TyOverby committed Sep 23, 2015
2 parents 50b4086 + dff44c3 commit af3c674
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@ private void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments<Attr
{
string verString = (string)attribute.CommonConstructorArguments[0].Value;
Version version;
if (!VersionHelper.TryParseAssemblyVersion(verString, allowWildcard: true, version: out version))
if (!VersionHelper.TryParseAssemblyVersion(verString, allowWildcard: !_compilation.IsEmitDeterministic, version: out version))
{
Location attributeArgumentSyntaxLocation = attribute.GetAttributeArgumentSyntaxLocation(0, arguments.AttributeSyntaxOpt);
arguments.Diagnostics.Add(ErrorCode.ERR_InvalidVersionFormat, attributeArgumentSyntaxLocation);
Expand Down
15 changes: 15 additions & 0 deletions src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ private ImmutableArray<byte> EmitDeterministic(string source, Platform platform,
return compilation.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(pdbFormat), pdbStream: new MemoryStream());
}

[Fact, WorkItem(4578, "https://github.com/dotnet/roslyn/issues/4578")]
public void BanVersionWildcards()
{
string source = @"[assembly: System.Reflection.AssemblyVersion(""10101.0.*"")] public class C {}";
var compilationDeterministic = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef },
parseOptions: TestOptions.Regular.WithFeature("deterministic", "true"));
var compilationNonDeterministic = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef });

var resultDeterministic = compilationDeterministic.Emit(Stream.Null, Stream.Null);
var resultNonDeterministic = compilationNonDeterministic.Emit(Stream.Null, Stream.Null);

Assert.False(resultDeterministic.Success);
Assert.True(resultNonDeterministic.Success);
}

[Fact, WorkItem(372, "https://github.com/dotnet/roslyn/issues/372")]
public void Simple()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
ElseIf attrData.IsTargetAttribute(Me, AttributeDescription.AssemblyVersionAttribute) Then
Dim verString = DirectCast(attrData.CommonConstructorArguments(0).Value, String)
Dim version As Version = Nothing
If Not VersionHelper.TryParseAssemblyVersion(verString, allowWildcard:=True, version:=version) Then
If Not VersionHelper.TryParseAssemblyVersion(verString, allowWildcard:=Not _compilation.IsEmitDeterministic, version:=version) Then
arguments.Diagnostics.Add(ERRID.ERR_InvalidVersionFormat, GetAssemblyAttributeFirstArgumentLocation(arguments.AttributeSyntaxOpt))
End If
arguments.GetOrCreateData(Of CommonAssemblyWellKnownAttributeData)().AssemblyVersionAttributeSetting = version
Expand Down
20 changes: 20 additions & 0 deletions src/Compilers/VisualBasic/Test/Emit/Emit/DeterministicTests.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports System.Threading
Expand All @@ -25,6 +26,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Emit
Return compilation.EmitToArray()
End Function

<Fact>
Public Sub BanVersionWildcards()
Dim source =
"<assembly: System.Reflection.AssemblyVersion(""10101.0.*"")>
Class C
Shared Sub Main()
End Sub
End Class"
Dim compilationDeterministic = CreateCompilationWithMscorlib({source}, assemblyName:="DeterminismTest",
parseOptions:=TestOptions.Regular.WithFeature("deterministic", "true"))
Dim compilationNonDeterministic = CreateCompilationWithMscorlib({source}, assemblyName:="DeterminismTest")

Dim resultDeterministic = compilationDeterministic.Emit(Stream.Null, Stream.Null)
Dim resultNonDeterministic = compilationNonDeterministic.Emit(Stream.Null, Stream.Null)

Assert.False(resultDeterministic.Success)
Assert.True(resultNonDeterministic.Success)
End Sub

<Fact>
Public Sub CompareAllBytesEmitted_Release()
Dim source =
Expand Down

0 comments on commit af3c674

Please sign in to comment.