Skip to content
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
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5460,7 +5460,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.</value>
</data>
<data name="ERR_CompilerAndLanguageVersion" xml:space="preserve">
<value>Compiler version: '{0}'. Language version: {1}.</value>
<value>Compiler version: '{0}'. Language version: {1}. Compiler path: '{2}'.</value>
</data>
<data name="IDS_FeatureAsyncMain" xml:space="preserve">
<value>async main</value>
Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Parser/DirectiveParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,14 @@ private DirectiveTriviaSyntax ParseErrorOrWarningDirective(SyntaxToken hash, Syn
if (errorText.Equals("version", StringComparison.Ordinal))
{
string version = CommonCompiler.GetProductVersion(typeof(CSharpCompiler));
string assemblyPath = CommonCompiler.GetAssemblyLocation(typeof(CSharpCompiler));
var specified = this.Options.SpecifiedLanguageVersion;
var effective = specified.MapSpecifiedToEffectiveVersion();

var displayLanguageVersion = specified == effective ? specified.ToDisplayString() : $"{specified.ToDisplayString()} ({effective.ToDisplayString()})";

eod = this.AddError(eod, triviaOffset, triviaWidth, ErrorCode.ERR_CompilerAndLanguageVersion, version,
displayLanguageVersion);
displayLanguageVersion, assemblyPath);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7052,19 +7052,6 @@ private static string ReplaceCommitHash(string s)
return Regex.Replace(s, "(\\((<developer build>|[a-fA-F0-9]{8})\\))", "(HASH)");
}

[Fact]
public void ExtractShortCommitHash()
{
Assert.Null(CommonCompiler.ExtractShortCommitHash(null));
Assert.Equal("", CommonCompiler.ExtractShortCommitHash(""));
Assert.Equal("<", CommonCompiler.ExtractShortCommitHash("<"));
Assert.Equal("<developer build>", CommonCompiler.ExtractShortCommitHash("<developer build>"));
Assert.Equal("1", CommonCompiler.ExtractShortCommitHash("1"));
Assert.Equal("1234567", CommonCompiler.ExtractShortCommitHash("1234567"));
Assert.Equal("12345678", CommonCompiler.ExtractShortCommitHash("12345678"));
Assert.Equal("12345678", CommonCompiler.ExtractShortCommitHash("123456789"));
}

private void CheckOutputFileName(string source1, string source2, string inputName1, string inputName2, string[] commandLineArguments, string expectedOutputName)
{
var dir = Temp.CreateDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3242,9 +3242,9 @@ public void TestErrorWithVersion(LanguageVersion version, string expectedLanguag
// (1,8): error CS1029: #error: 'version'
// #error version
Diagnostic(ErrorCode.ERR_ErrorDirective, "version").WithArguments("version").WithLocation(1, 8),
// (1,8): error CS8304: Compiler version: '42.42.42.42424 (<developer build>)'. Language version: <expectedLanguageVersion>.
// (1,8): error CS8304: Compiler version: '42.42.42.42424 (<developer build>)'. Language version: <expectedLanguageVersion>. Compiler path: '<path>'.
// #error version
Diagnostic(ErrorCode.ERR_CompilerAndLanguageVersion, "version").WithArguments(GetExpectedVersion(), expectedLanguageVersion).WithLocation(1, 8)
Diagnostic(ErrorCode.ERR_CompilerAndLanguageVersion, "version").WithArguments(GetExpectedVersion(), expectedLanguageVersion, GetExpectedAssemblyPath()).WithLocation(1, 8)
);
}

Expand Down Expand Up @@ -4659,5 +4659,10 @@ private static string GetExpectedVersion()
{
return CommonCompiler.GetProductVersion(typeof(CSharpCompiler));
}

private static string GetExpectedAssemblyPath()
{
return CommonCompiler.GetAssemblyLocation(typeof(CSharpCompiler));
}
}
}
20 changes: 4 additions & 16 deletions src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,21 @@ internal string GetCompilerVersion()
internal static string GetProductVersion(Type type)
{
string? assemblyVersion = GetInformationalVersionWithoutHash(type);
string? hash = GetShortCommitHash(type);
string? hash = type.Assembly.GetCustomAttribute<CommitHashAttribute>()?.Hash;
return $"{assemblyVersion} ({hash})";
}

[return: NotNullIfNotNull(nameof(hash))]
internal static string? ExtractShortCommitHash(string? hash)
{
// leave "<developer build>" alone, but truncate SHA to 8 characters
if (hash != null && hash.Length >= 8 && hash[0] != '<')
{
return hash.Substring(0, 8);
}

return hash;
}

private static string? GetInformationalVersionWithoutHash(Type type)
{
// The attribute stores a SemVer2-formatted string: `A.B.C(-...)?(+...)?`
// We remove the section after the + (if any is present)
return type.Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0];
}

private static string? GetShortCommitHash(Type type)
internal static string GetAssemblyLocation(Type type)
{
var hash = type.Assembly.GetCustomAttribute<CommitHashAttribute>()?.Hash;
return ExtractShortCommitHash(hash);
var location = type.Assembly.Location;
return string.IsNullOrEmpty(location) ? "<unknown>" : location;
}

/// <summary>
Expand Down
Loading