Skip to content

Commit 8724a59

Browse files
author
Julien Couvreur
committed
Simplify logic (no need for short SHAs)
1 parent 1fac3d9 commit 8724a59

File tree

4 files changed

+4
-51
lines changed

4 files changed

+4
-51
lines changed

src/Compilers/CSharp/Portable/Parser/DirectiveParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private DirectiveTriviaSyntax ParseErrorOrWarningDirective(SyntaxToken hash, Syn
332332
{
333333
if (errorText.Equals("version", StringComparison.Ordinal))
334334
{
335-
string version = CommonCompiler.GetProductVersionWithFullHash(typeof(CSharpCompiler));
335+
string version = CommonCompiler.GetProductVersion(typeof(CSharpCompiler));
336336
string assemblyPath = CommonCompiler.GetAssemblyLocation(typeof(CSharpCompiler));
337337
var specified = this.Options.SpecifiedLanguageVersion;
338338
var effective = specified.MapSpecifiedToEffectiveVersion();

src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7052,19 +7052,6 @@ private static string ReplaceCommitHash(string s)
70527052
return Regex.Replace(s, "(\\((<developer build>|[a-fA-F0-9]{8})\\))", "(HASH)");
70537053
}
70547054

7055-
[Fact]
7056-
public void ExtractShortCommitHash()
7057-
{
7058-
Assert.Null(CommonCompiler.ExtractShortCommitHash(null));
7059-
Assert.Equal("", CommonCompiler.ExtractShortCommitHash(""));
7060-
Assert.Equal("<", CommonCompiler.ExtractShortCommitHash("<"));
7061-
Assert.Equal("<developer build>", CommonCompiler.ExtractShortCommitHash("<developer build>"));
7062-
Assert.Equal("1", CommonCompiler.ExtractShortCommitHash("1"));
7063-
Assert.Equal("1234567", CommonCompiler.ExtractShortCommitHash("1234567"));
7064-
Assert.Equal("12345678", CommonCompiler.ExtractShortCommitHash("12345678"));
7065-
Assert.Equal("12345678", CommonCompiler.ExtractShortCommitHash("123456789"));
7066-
}
7067-
70687055
private void CheckOutputFileName(string source1, string source2, string inputName1, string inputName2, string[] commandLineArguments, string expectedOutputName)
70697056
{
70707057
var dir = Temp.CreateDirectory();

src/Compilers/CSharp/Test/Syntax/LexicalAndXml/PreprocessorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4657,7 +4657,7 @@ public void NullableExcludedUnrecognizedSetting()
46574657

46584658
private static string GetExpectedVersion()
46594659
{
4660-
return CommonCompiler.GetProductVersionWithFullHash(typeof(CSharpCompiler));
4660+
return CommonCompiler.GetProductVersion(typeof(CSharpCompiler));
46614661
}
46624662

46634663
private static string GetExpectedAssemblyPath()

src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -157,46 +157,12 @@ internal string GetCompilerVersion()
157157
}
158158

159159
internal static string GetProductVersion(Type type)
160-
{
161-
string? assemblyVersion = GetInformationalVersionWithoutHash(type);
162-
string? hash = GetShortCommitHash(type);
163-
return $"{assemblyVersion} ({hash})";
164-
}
165-
166-
[return: NotNullIfNotNull(nameof(hash))]
167-
internal static string? ExtractShortCommitHash(string? hash)
168-
{
169-
// leave "<developer build>" alone, but truncate SHA to 8 characters
170-
if (hash != null && hash.Length >= 8 && hash[0] != '<')
171-
{
172-
return hash.Substring(0, 8);
173-
}
174-
175-
return hash;
176-
}
177-
178-
private static string? GetInformationalVersionWithoutHash(Type type)
179160
{
180161
// The attribute stores a SemVer2-formatted string: `A.B.C(-...)?(+...)?`
181162
// We remove the section after the + (if any is present)
182-
return type.Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0];
183-
}
184-
185-
private static string? GetShortCommitHash(Type type)
186-
{
187-
var hash = type.Assembly.GetCustomAttribute<CommitHashAttribute>()?.Hash;
188-
return ExtractShortCommitHash(hash);
189-
}
163+
string? assemblyVersion = type.Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0];
190164

191-
private static string? GetFullCommitHash(Type type)
192-
{
193-
return type.Assembly.GetCustomAttribute<CommitHashAttribute>()?.Hash;
194-
}
195-
196-
internal static string GetProductVersionWithFullHash(Type type)
197-
{
198-
string? assemblyVersion = GetInformationalVersionWithoutHash(type);
199-
string? hash = GetFullCommitHash(type);
165+
string? hash = type.Assembly.GetCustomAttribute<CommitHashAttribute>()?.Hash;
200166
return $"{assemblyVersion} ({hash})";
201167
}
202168

0 commit comments

Comments
 (0)