-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Rebuild csc #51345
Changes from all commits
12a4808
7497d36
00ed64e
652a528
2535225
60647bf
b236c5b
ef2e9b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
param( | ||
[string]$configuration = "Debug", | ||
[switch]$ci = $false, | ||
[switch]$noBuild = $false, | ||
[switch]$help) | ||
|
||
Set-StrictMode -version 2.0 | ||
|
@@ -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" | ||
} | ||
|
||
|
@@ -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`"" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
" --referencesPath `"$dotnetInstallDir/packs/Microsoft.NETCore.App.Ref`"") | ||
Exec-Console "$ArtifactsDir/bin/BuildValidator/$configuration/net472/BuildValidator.exe" $rebuildArgs | ||
|
||
exit 0 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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") | ||
}; | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"); | ||
} | ||
} | ||
} | ||
|
@@ -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(); | ||
|
@@ -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, | ||
|
@@ -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") | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What motivated this change?
There was a problem hiding this comment.
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.