Skip to content

Commit

Permalink
Merge pull request #51532 from jaredpar/rebuild-vb
Browse files Browse the repository at this point in the history
Rebuild MS.CA.VisualBasic
  • Loading branch information
msftbot[bot] authored Feb 27, 2021
2 parents c5dbbd4 + dc2ad01 commit fdc482c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
1 change: 1 addition & 0 deletions eng/test-rebuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ try {
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis.Scripting`"" +
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis.Scripting.TestUtilities`"" +
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis.TestSourceGenerator`"" +
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis.VisualBasic`"" +
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis.Workspaces`"" +
" --assembliesPath `"$ArtifactsDir/obj/PrepareTests`"" +
" --assembliesPath `"$ArtifactsDir/obj/RunTests`"" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End If

If Options.ParseOptions IsNot Nothing Then
Dim preprocessorStrings = Options.ParseOptions.PreprocessorSymbols.Select(Function(p)
If (p.Value Is Nothing) Then
Return p.Key
End If

Return p.Key + "=" + p.Value.ToString()
End Function)
Dim preprocessorStrings = Options.ParseOptions.PreprocessorSymbols.Select(
Function(p) As String
If TypeOf p.Value Is String Then
Return p.Key + "=""" + p.Value.ToString() + """"
ElseIf p.Value Is Nothing Then
Return p.Key
Else
Return p.Key + "=" + p.Value.ToString()
End If
End Function)
WriteValue(builder, CompilationOptionNames.Define, String.Join(",", preprocessorStrings))
End If
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Public Class VisualBasicDeterministicBuildCompilationTests
"define",
originalOptions.ParseOptions.PreprocessorSymbols,
isDefault:=Function(v) v.IsEmpty,
toString:=Function(v) String.Join(",", v.Select(Function(p) If(p.Value IsNot Nothing, $"{p.Key}={p.Value}", p.Key))))
toString:=Function(v) String.Join(",", v.Select(Function(p) If(p.Value IsNot Nothing, $"{p.Key}=""{p.Value}""", p.Key))))
End Sub

Private Sub TestDeterministicCompilationVB(syntaxTrees As SyntaxTree(), compilationOptions As VisualBasicCompilationOptions, emitOptions As EmitOptions, ParamArray metadataReferences() As TestMetadataReferenceInfo)
Expand Down
53 changes: 38 additions & 15 deletions src/Tools/BuildValidator/BuildConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.Extensions.Logging;
using Roslyn.Utilities;
using CS = Microsoft.CodeAnalysis.CSharp;
using VB = Microsoft.CodeAnalysis.VisualBasic;

Expand Down Expand Up @@ -65,14 +66,30 @@ public BuildConstructor(LocalReferenceResolver referenceResolver, LocalSourceRes

if (pdbCompilationOptions.TryGetUniqueOption("language", out var language))
{
var diagnosticBag = DiagnosticBag.GetInstance();
var compilation = language switch
{
LanguageNames.CSharp => CreateCSharpCompilation(fileName, compilationOptionsReader, sources, metadataReferences),
LanguageNames.VisualBasic => CreateVisualBasicCompilation(fileName, compilationOptionsReader, sources, metadataReferences),
LanguageNames.VisualBasic => CreateVisualBasicCompilation(fileName, compilationOptionsReader, sources, metadataReferences, diagnosticBag),
_ => throw new InvalidDataException($"{language} is not a known language")
};

return compilation;
var diagnostics = diagnosticBag.ToReadOnlyAndFree();
var hadError = false;
foreach (var diagnostic in diagnostics)
{
if (diagnostic.Severity == DiagnosticSeverity.Error)
{
_logger.LogError(diagnostic.ToString());
hadError = true;
}
else
{
_logger.LogWarning(diagnostic.ToString());
}
}

return hadError ? null : compilation;
}

throw new InvalidDataException("Did not find language in compilation options");
Expand Down Expand Up @@ -158,6 +175,7 @@ private Compilation CreateCSharpCompilation(

var langVersionString = pdbCompilationOptions.GetUniqueOption("language-version");
var optimization = pdbCompilationOptions.GetUniqueOption("optimization");

// TODO: Check portability policy if needed
// pdbCompilationOptions.TryGetValue("portability-policy", out var portabilityPolicyString);
pdbCompilationOptions.TryGetUniqueOption(_logger, "define", out var define);
Expand Down Expand Up @@ -236,23 +254,23 @@ private Compilation CreateVisualBasicCompilation(
string fileName,
CompilationOptionsReader optionsReader,
ImmutableArray<ResolvedSource> sources,
ImmutableArray<MetadataReference> metadataReferences)
ImmutableArray<MetadataReference> metadataReferences,
DiagnosticBag diagnosticBag)
{
var compilationOptions = CreateVisualBasicCompilationOptions(optionsReader, fileName);
var compilationOptions = CreateVisualBasicCompilationOptions(optionsReader, fileName, diagnosticBag);
return VisualBasicCompilation.Create(
Path.GetFileNameWithoutExtension(fileName),
syntaxTrees: sources.Select(s => VisualBasicSyntaxTree.ParseText(s.SourceText, options: compilationOptions.ParseOptions, path: s.DisplayPath)).ToImmutableArray(),
syntaxTrees: sources.Select(s => VisualBasicSyntaxTree.ParseText(s.SourceText, options: compilationOptions.ParseOptions, path: s.SourceFileInfo.SourceFilePath)).ToImmutableArray(),
references: metadataReferences,
options: compilationOptions);
}

private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions(CompilationOptionsReader optionsReader, string fileName)
private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions(CompilationOptionsReader optionsReader, string fileName, DiagnosticBag diagnosticBag)
{
var pdbCompilationOptions = optionsReader.GetMetadataCompilationOptions();

var langVersionString = pdbCompilationOptions.GetUniqueOption(CompilationOptionNames.LanguageVersion);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Optimization, out var optimization);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.Define, out var define);
pdbCompilationOptions.TryGetUniqueOption(CompilationOptionNames.GlobalNamespaces, out var globalNamespacesString);

IEnumerable<GlobalImport>? globalImports = null;
Expand All @@ -264,15 +282,20 @@ private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions
VB.LanguageVersion langVersion = default;
VB.LanguageVersionFacts.TryParse(langVersionString, ref langVersion);

var preprocessorSymbols = string.IsNullOrEmpty(define)
? Array.Empty<KeyValuePair<string, object>>()
: define.Split(',')
.Select(s => s.Split('='))
.Select(a => new KeyValuePair<string, object>(a[0], a[1]))
.ToArray();
IReadOnlyDictionary<string, object>? preprocessorSymbols = null;
if (OptionToString(CompilationOptionNames.Define) is string defineString)
{
preprocessorSymbols = VisualBasicCommandLineParser.ParseConditionalCompilationSymbols(defineString, out var diagnostics);
if (diagnostics is object)
{
diagnosticBag.AddRange(diagnostics);
}
}

var parseOptions = VisualBasicParseOptions.Default.WithLanguageVersion(langVersion)
.WithPreprocessorSymbols(preprocessorSymbols);
var parseOptions = VisualBasicParseOptions
.Default
.WithLanguageVersion(langVersion)
.WithPreprocessorSymbols(preprocessorSymbols.ToImmutableArrayOrEmpty());

var (optimizationLevel, plus) = GetOptimizationLevel(optimization);
var isChecked = OptionToBool(CompilationOptionNames.Checked) ?? true;
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/BuildValidator/BuildValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/BuildValidator/CompilationDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void writeEmbeddedFileInfo()
if (info.EmbeddedCompressedHash is { } hash)
{
var hashString = BitConverter.ToString(hash).Replace("-", "");
writer.WriteLine($@"\t""{info.SourceFilePath}"" - {hashString}");
writer.WriteLine($@"\t""{Path.GetFileName(info.SourceFilePath)}"" - {hashString}");
}
}
}
Expand Down

0 comments on commit fdc482c

Please sign in to comment.