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

Rebuild csc #51345

Merged
merged 8 commits into from
Feb 23, 2021
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
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/artifacts/bin/BuildValidator/Debug/netcoreapp3.1/BuildValidator.dll",
"args": [
"--assembliesPath", "./artifacts/obj/RunTests",
"--assembliesPath", "./artifacts/obj/csc/Debug/netcoreapp3.1",
"--referencesPath", "./artifacts/bin",
"--referencesPath", "C:/Program Files/dotnet/packs/Microsoft.AspNetCore.App.Ref",
"--referencesPath", "C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Ref",
"--debugPath", "./artifacts/BuildValidator",
"--sourcePath", "."
],
Expand Down
11 changes: 3 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ jobs:

- job: Correctness_Rebuild
pool:
vmImage: windows-2019
name: NetCorePublic-Pool
queue: BuildPool.Windows.10.Amd64.Open
Copy link
Member

Choose a reason for hiding this comment

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

What motivated this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this pool is faster.

timeoutInMinutes: 90
steps:
- template: eng/pipelines/checkout-windows-task.yml
Expand All @@ -226,13 +227,7 @@ jobs:
filePath: eng/build.ps1
arguments: -configuration Debug -prepareMachine -ci -restore -binaryLog

- task: PowerShell@2
displayName: Build
inputs:
filePath: eng/build.ps1
arguments: -configuration Debug -prepareMachine -ci -build -bootstrap -publish -binaryLog -skipDocumentation

- script: .\artifacts\bin\BuildValidator\Debug\net472\BuildValidator.exe --assembliesPath .\artifacts\obj\Microsoft.CodeAnalysis --debugPath .\artifacts\BuildValidator --sourcePath .
- powershell: .\eng\test-rebuild.ps1 -ci
displayName: Run BuildValidator

- task: PublishBuildArtifacts@1
Expand Down
5 changes: 2 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@
<MicrosoftDiaSymReaderNativeVersion>16.9.0-beta1.21055.5</MicrosoftDiaSymReaderNativeVersion>
<MicrosoftDiaSymReaderPortablePdbVersion>1.5.0</MicrosoftDiaSymReaderPortablePdbVersion>
<MicrosoftDotNetVersionToolsVersion>3.0.0-preview1-03617-02</MicrosoftDotNetVersionToolsVersion>
<MicrosoftExtensionsDependencyInjectionVersion>2.1.1</MicrosoftExtensionsDependencyInjectionVersion>
<MicrosoftExtensionsLoggingVersion>2.1.1</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsLoggingConsoleVersion>2.1.1</MicrosoftExtensionsLoggingConsoleVersion>
<MicrosoftExtensionsLoggingVersion>5.0.0</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsLoggingConsoleVersion>5.0.0</MicrosoftExtensionsLoggingConsoleVersion>
<MicrosoftIdentityModelClientsActiveDirectoryVersion>3.13.8</MicrosoftIdentityModelClientsActiveDirectoryVersion>
<MicrosoftInternalPerformanceCodeMarkersDesignTimeVersion>15.8.27812-alpha</MicrosoftInternalPerformanceCodeMarkersDesignTimeVersion>
<MicrosoftInternalVisualStudioShellInterop140DesignTimeVersion>14.3.25407-alpha</MicrosoftInternalVisualStudioShellInterop140DesignTimeVersion>
Expand Down
2 changes: 1 addition & 1 deletion eng/build-utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function Make-BootstrapBuild([switch]$force32 = $false) {

Run-MSBuild $projectPath "/restore /t:Pack /p:RoslynEnforceCodeStyle=false /p:RunAnalyzersDuringBuild=false /p:DotNetUseShippingVersions=true /p:InitialDefineConstants=BOOTSTRAP /p:PackageOutputPath=`"$dir`" /p:EnableNgenOptimization=false /p:PublishWindowsPdb=false $force32Flag" -logFileName "Bootstrap" -configuration $bootstrapConfiguration -runAnalyzers
$packageFile = Get-ChildItem -Path $dir -Filter "$packageName.*.nupkg"
Unzip (Join-Path $dir $packageFile) $dir
Unzip (Join-Path $dir $packageFile.Name) $dir
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change makes the script work on both Windows PowerShell and PowerShell Core.


Write-Host "Cleaning Bootstrap compiler artifacts"
Run-MSBuild $projectPath "/t:Clean" -logFileName "BootstrapClean"
Expand Down
20 changes: 17 additions & 3 deletions eng/test-rebuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
param(
[string]$configuration = "Debug",
[switch]$ci = $false,
[switch]$noBuild = $false,
[switch]$help)

Set-StrictMode -version 2.0
Expand All @@ -15,6 +16,7 @@ function Print-Usage() {
Write-Host "Usage: test-rebuild.ps1"
Write-Host " -configuration Build configuration ('Debug' or 'Release')"
Write-Host " -ci Set when running on CI server"
Write-Host " -noBuild If set, skips running a bootstrap build before running the rebuild"
Write-Host " -help Print help and exit"
}

Expand All @@ -27,9 +29,21 @@ try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
Push-Location $RepoRoot

Write-Host "Building Roslyn"
Exec-Console (Join-Path $PSScriptRoot "build.ps1") "-restore -build -ci:$ci -configuration:$configuration -pack -binaryLog"
Exec-Console "artifacts\bin\BuildValidator\$configuration\net472\BuildValidator.exe" "--assembliesPath '$ArtifactsDir/obj/Microsoft.CodeAnalysis'"
if (-not $noBuild) {
Write-Host "Building Roslyn"
Exec-Block { & (Join-Path $PSScriptRoot "build.ps1") -build -bootstrap -ci:$ci -configuration:$configuration -pack -binaryLog }
}

$dotnetInstallDir = (InitializeDotNetCli -install:$true)
$rebuildArgs = ("--verbose" +
" --assembliesPath `"$ArtifactsDir/obj/Microsoft.CodeAnalysis/$configuration`"" +
" --assembliesPath $ArtifactsDir/obj/csc/$configuration/netcoreapp3.1" +
" --debugPath `"$ArtifactsDir/BuildValidator`"" +
" --sourcePath `"$RepoRoot`"" +
" --referencesPath `"$ArtifactsDir/bin`"" +
" --referencesPath `"$dotnetInstallDir/packs/Microsoft.AspNetCore.App.Ref`"" +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracting these folders out to command line arguments was necessary to build on Helix agents where dotnet is typically not found under C:\Program Files\dotnet.

" --referencesPath `"$dotnetInstallDir/packs/Microsoft.NETCore.App.Ref`"")
Exec-Console "$ArtifactsDir/bin/BuildValidator/$configuration/net472/BuildValidator.exe" $rebuildArgs

exit 0
}
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/csc/csc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ServerGarbageCollection>true</ServerGarbageCollection>
<UseAppHost>false</UseAppHost>
<GenerateMicrosoftCodeAnalysisCommitHashAttribute>true</GenerateMicrosoftCodeAnalysisCommitHashAttribute>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\Core\Portable\Microsoft.CodeAnalysis.csproj" />
Expand Down
33 changes: 17 additions & 16 deletions src/Tools/BuildValidator/BuildConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BuildConstructor(LocalReferenceResolver referenceResolver, LocalSourceRes
_logger = logger;
}

public Compilation CreateCompilation(CompilationOptionsReader compilationOptionsReader, string name)
public Compilation CreateCompilation(CompilationOptionsReader compilationOptionsReader, string fileName)
{
var pdbCompilationOptions = compilationOptionsReader.GetMetadataCompilationOptions();
if (pdbCompilationOptions.Length == 0)
Expand All @@ -62,8 +62,8 @@ public Compilation CreateCompilation(CompilationOptionsReader compilationOptions
{
var compilation = language switch
{
LanguageNames.CSharp => CreateCSharpCompilation(name, compilationOptionsReader, sources, metadataReferences),
LanguageNames.VisualBasic => CreateVisualBasicCompilation(name, compilationOptionsReader, sources, metadataReferences),
LanguageNames.CSharp => CreateCSharpCompilation(fileName, compilationOptionsReader, sources, metadataReferences),
LanguageNames.VisualBasic => CreateVisualBasicCompilation(fileName, compilationOptionsReader, sources, metadataReferences),
_ => throw new InvalidDataException($"{language} is not a known language")
};

Expand All @@ -88,7 +88,10 @@ void logResolvedSources()
{
var sourceFileInfo = resolvedSource.SourceFileInfo;
var hash = BitConverter.ToString(sourceFileInfo.Hash).Replace("-", "");
_logger.LogInformation($@"""{resolvedSource.DisplayPath}"" - {sourceFileInfo.HashAlgorithm} - {hash}");
var embeddedCompressedHash = sourceFileInfo.EmbeddedCompressedHash is { } compressedHash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed to verify that compression of embedded sources was producing equivalent results in the rebuild.

? ("[uncompressed]" + BitConverter.ToString(compressedHash).Replace("-", ""))
: null;
_logger.LogInformation($@"""{resolvedSource.DisplayPath}"" - {sourceFileInfo.HashAlgorithm} - {hash} - {embeddedCompressedHash}");
}
}
}
Expand Down Expand Up @@ -129,20 +132,20 @@ private ImmutableArray<ResolvedSource> ResolveSources(

#region CSharp
private Compilation CreateCSharpCompilation(
string assemblyName,
string fileName,
CompilationOptionsReader optionsReader,
ImmutableArray<ResolvedSource> sources,
ImmutableArray<MetadataReference> metadataReferences)
{
var (compilationOptions, parseOptions) = CreateCSharpCompilationOptions(optionsReader, assemblyName);
var (compilationOptions, parseOptions) = CreateCSharpCompilationOptions(optionsReader, fileName);
return CSharpCompilation.Create(
assemblyName,
Path.GetFileNameWithoutExtension(fileName),
syntaxTrees: sources.Select(s => CSharpSyntaxTree.ParseText(s.SourceText, options: parseOptions, path: s.SourceFileInfo.SourceFilePath)).ToImmutableArray(),
references: metadataReferences,
options: compilationOptions);
}

private (CSharpCompilationOptions, CSharpParseOptions) CreateCSharpCompilationOptions(CompilationOptionsReader optionsReader, string assemblyName)
private (CSharpCompilationOptions, CSharpParseOptions) CreateCSharpCompilationOptions(CompilationOptionsReader optionsReader, string fileName)
{
using var scope = _logger.BeginScope("Options");
var pdbCompilationOptions = optionsReader.GetMetadataCompilationOptions();
Expand Down Expand Up @@ -175,9 +178,7 @@ private Compilation CreateCSharpCompilation(
optionsReader.GetOutputKind(),
reportSuppressedDiagnostics: false,

// TODO: can't rely on the implicity moduleName here. In the case of .NET Core EXE the output name will
// end with .dll but the inferred name will be .exe
moduleName: assemblyName + ".dll",
moduleName: fileName,
mainTypeName: optionsReader.GetMainTypeName(),
scriptClassName: null,
usings: null,
Expand Down Expand Up @@ -213,10 +214,10 @@ private Compilation CreateCSharpCompilation(
return (compilationOptions, parseOptions);
}

private static (OptimizationLevel, bool) GetOptimizationLevel(string optimizationLevel)
private static (OptimizationLevel, bool) GetOptimizationLevel(string? optimizationLevel)
=> optimizationLevel switch
{
"debug" => (OptimizationLevel.Debug, false),
null or "debug" => (OptimizationLevel.Debug, false),
"debug-plus" => (OptimizationLevel.Debug, true),
"release" => (OptimizationLevel.Release, false),
_ => throw new InvalidDataException($"Optimization \"{optimizationLevel}\" level not recognized")
Expand All @@ -226,14 +227,14 @@ private static (OptimizationLevel, bool) GetOptimizationLevel(string optimizatio

#region Visual Basic
private Compilation CreateVisualBasicCompilation(
string assemblyName,
string fileName,
CompilationOptionsReader optionsReader,
ImmutableArray<ResolvedSource> sources,
ImmutableArray<MetadataReference> metadataReferences)
{
var compilationOptions = CreateVisualBasicCompilationOptions(optionsReader);
return VisualBasicCompilation.Create(
assemblyName,
Path.GetFileNameWithoutExtension(fileName),
syntaxTrees: sources.Select(s => VisualBasicSyntaxTree.ParseText(s.SourceText, options: compilationOptions.ParseOptions, path: s.DisplayPath)).ToImmutableArray(),
references: metadataReferences,
options: compilationOptions);
Expand All @@ -244,7 +245,7 @@ private static VisualBasicCompilationOptions CreateVisualBasicCompilationOptions
var pdbCompilationOptions = optionsReader.GetMetadataCompilationOptions();

var langVersionString = pdbCompilationOptions.GetUniqueOption("language-version");
var optimization = pdbCompilationOptions.GetUniqueOption("optimization");
pdbCompilationOptions.TryGetUniqueOption("optimization", out var optimization);
pdbCompilationOptions.TryGetUniqueOption("define", out var define);
pdbCompilationOptions.TryGetUniqueOption("strict", out var strict);
pdbCompilationOptions.TryGetUniqueOption("checked", out var checkedString);
Expand Down
1 change: 1 addition & 0 deletions src/Tools/BuildValidator/BuildValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="Microsoft.Metadata.Visualizer" Version="$(MicrosoftMetadataVisualizerVersion)" />
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" Version="$(MicrosoftDiaSymReaderConverterXmlVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
</ItemGroup>
Expand Down
Loading