提交 cad06f2b 编写于 作者: T TomasMatousek

Implements CR feedback for EmitOptions change: rename EmitOptions.OutputName...

Implements CR feedback for EmitOptions change: rename EmitOptions.OutputName to OutputNameOverride and adds TolerateErrors and IncludePrivateMembers.  (changeset 1348868)
上级 755ffcd0
......@@ -1044,7 +1044,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
metadataOnly: false,
debugInformationFormat: DebugInformationFormat.Pdb,
pdbFilePath: null, // to be determined later
outputName: null, // to be determined later
outputNameOverride: null, // to be determined later
baseAddress: baseAddress,
highEntropyVirtualAddressSpace: highEntropyVA,
fileAlignment: fileAlignment,
......
......@@ -2424,7 +2424,7 @@ internal override FunctionId EmitFunctionId
// Use a temporary bag so we don't have to refilter pre-existing diagnostics.
DiagnosticBag xmlDiagnostics = DiagnosticBag.GetInstance();
string assemblyName = FileNameUtilities.ChangeExtension(moduleBeingBuilt.EmitOptions.OutputName, extension: null);
string assemblyName = FileNameUtilities.ChangeExtension(moduleBeingBuilt.EmitOptions.OutputNameOverride, extension: null);
DocumentationCommentCompiler.WriteDocumentationCommentXml(this, assemblyName, xmlDocStream, xmlDiagnostics, cancellationToken);
if (!FilterAndAppendAndFreeDiagnostics(diagnostics, ref xmlDiagnostics))
......
......@@ -50,7 +50,7 @@ internal abstract class PEAssemblyBuilderBase : PEModuleBuilder, Cci.IAssembly
this.sourceAssembly = sourceAssembly;
this.additionalTypes = additionalTypes.NullToEmpty();
this.metadataName = (emitOptions.OutputName == null) ? sourceAssembly.MetadataName : FileNameUtilities.ChangeExtension(emitOptions.OutputName, extension: null);
this.metadataName = (emitOptions.OutputNameOverride == null) ? sourceAssembly.MetadataName : FileNameUtilities.ChangeExtension(emitOptions.OutputNameOverride, extension: null);
AssemblyOrModuleSymbolToModuleRefMap.Add(sourceAssembly, this);
}
......
......@@ -66,7 +66,7 @@ public override NoPia.EmbeddedTypesManager EmbeddedTypesManagerOpt
metadataName = specifiedName != Microsoft.CodeAnalysis.Compilation.UnspecifiedModuleAssemblyName ?
specifiedName :
emitOptions.OutputName ?? specifiedName;
emitOptions.OutputNameOverride ?? specifiedName;
AssemblyOrModuleSymbolToModuleRefMap.Add(sourceModule, this);
......
......@@ -1589,7 +1589,7 @@ public void EmitAssemblyWithGivenName()
Assert.Equal(nameWithExtension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: nameWithExtension)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: nameWithExtension)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1620,7 +1620,7 @@ public void EmitModuleWithDifferentName()
Assert.Equal(name + extension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: outputName + extension)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: outputName + extension)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1650,7 +1650,7 @@ public void EmitAssemblyWithDifferentName1()
Assert.Equal(name + extension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: nameOverride + extension)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: nameOverride + extension)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1681,7 +1681,7 @@ public void EmitAssemblyWithDifferentName2()
Assert.Equal(name + extension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: nameOverride)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: nameOverride)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1712,7 +1712,7 @@ public void EmitAssemblyWithDifferentName3()
Assert.Equal(name + extension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: nameOverride + extension)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: nameOverride + extension)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1743,7 +1743,7 @@ public void EmitAssemblyWithDifferentName4()
Assert.Equal(name + extension, module.Name);
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputName: nameOverride)).Success);
Assert.True(compilation.Emit(stream, options: new EmitOptions(outputNameOverride: nameOverride)).Success);
using (ModuleMetadata metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable()))
{
......@@ -1794,7 +1794,7 @@ public void IllegalNameOverride()
var compilation = CreateCompilationWithMscorlib("class A { }", options: TestOptions.ReleaseDll);
compilation.VerifyDiagnostics();
var result = compilation.Emit(new MemoryStream(), options: new EmitOptions(outputName: "x\0x"));
var result = compilation.Emit(new MemoryStream(), options: new EmitOptions(outputNameOverride: "x\0x"));
result.Diagnostics.Verify(
// error CS2041: Invalid output name: Name contains invalid characters.
Diagnostic(ErrorCode.ERR_InvalidOutputName).WithArguments("Name contains invalid characters."));
......
......@@ -134,7 +134,7 @@ public void EmitToMemoryStreams()
Assert.True(result.Success);
result = comp.Emit(output, options: EmitOptions.Default.WithHighEntropyVirtualAddressSpace(true));
Assert.True(result.Success);
result = comp.Emit(output, options: EmitOptions.Default.WithOutputName("foo"));
result = comp.Emit(output, options: EmitOptions.Default.WithOutputNameOverride("foo"));
Assert.True(result.Success);
result = comp.Emit(output, options: EmitOptions.Default.WithPdbFilePath("foo.pdb"));
Assert.True(result.Success);
......@@ -151,7 +151,7 @@ public void EmitOptionsDiagnostics()
var options = new EmitOptions(
debugInformationFormat: (DebugInformationFormat)(-1),
outputName: " ",
outputNameOverride: " ",
fileAlignment: 513,
subsystemVersion: SubsystemVersion.Create(1000000, -1000000));
......
......@@ -49,8 +49,10 @@ public void WithXxx()
TestProperty((old, value) => old.WithSubsystemVersion(value), opt => opt.SubsystemVersion, SubsystemVersion.Windows2000);
TestProperty((old, value) => old.WithRuntimeMetadataVersion(value), opt => opt.RuntimeMetadataVersion, "v12345");
TestProperty((old, value) => old.WithPdbFilePath(value), opt => opt.PdbFilePath, @"c:\temp\a.pdb");
TestProperty((old, value) => old.WithOutputName(value), opt => opt.OutputName, @"x.dll");
TestProperty((old, value) => old.WithOutputNameOverride(value), opt => opt.OutputNameOverride, @"x.dll");
TestProperty((old, value) => old.WithDebugInformationFormat(value), opt => opt.DebugInformationFormat, (DebugInformationFormat)2);
TestProperty((old, value) => old.WithTolerateErrors(value), opt => opt.TolerateErrors, true);
TestProperty((old, value) => old.WithIncludePrivateMembers(value), opt => opt.IncludePrivateMembers, true);
}
/// <summary>
......@@ -70,9 +72,11 @@ public void TestFieldsForEqualsAndGetHashCode()
"HighEntropyVirtualAddressSpace",
"BaseAddress",
"DebugInformationFormat",
"OutputName",
"OutputNameOverride",
"PdbFilePath",
"RuntimeMetadataVersion");
"RuntimeMetadataVersion",
"TolerateErrors",
"IncludePrivateMembers");
}
}
}
......@@ -394,7 +394,7 @@ public virtual int Run(TextWriter consoleOutput, CancellationToken cancellationT
// NOTE: Unlike the PDB path, the XML doc path is not embedded in the assembly, so we don't need to pass it to emit.
var emitOptions = Arguments.EmitOptions.
WithOutputName(outputName).
WithOutputNameOverride(outputName).
WithPdbFilePath(finalPdbFilePath);
emitResult = compilation.Emit(output, pdb, xml, win32Res, Arguments.ManifestResources, emitOptions, cancellationToken);
......
......@@ -13,20 +13,23 @@ public sealed class EmitOptions : IEquatable<EmitOptions>
internal static readonly EmitOptions Default = new EmitOptions();
/// <summary>
/// True to emit a reference assembly, false to emit a regular assembly.
/// True to emit an assembly excluding executable code such as method bodies.
/// </summary>
public bool EmitMetadataOnly { get; private set; }
// <summary>
// Tolerate errors, producing a PE stream and a success result even in the presence of (some) errors.
// </summary>
// public bool TolerateErrors { get; private set; }
/// <summary>
/// Tolerate errors, producing a PE stream and a success result even in the presence of (some) errors.
/// </summary>
public bool TolerateErrors { get; private set; }
// <summary>
// If not set and <see cref="OutputMetadataOnly"/> is true, exclude (some) private members from the generated assembly when they do not
// affect the language semantics of the resulting assembly. Has no effect when <see cref="OutputMetadataOnly"/> is false.
// </summary>
// public bool IncludePrivateMembers { get; private set; }
/// <summary>
/// Unless set (private) members that don't affect the language semantics of the resulting assembly will be excluded
/// when emitting with <see cref="EmitMetadataOnly"/> on.
/// </summary>
/// <remarks>
/// Has no effect when <see cref="EmitMetadataOnly"/> is false.
/// </remarks>
public bool IncludePrivateMembers { get; private set; }
/// <summary>
/// Subsystem version
......@@ -42,6 +45,9 @@ public sealed class EmitOptions : IEquatable<EmitOptions>
/// </remarks>
public int FileAlignment { get; private set; }
/// <summary>
/// True to enable high entropy virtual address space for the output binary.
/// </summary>
public bool HighEntropyVirtualAddressSpace { get; private set; }
/// <summary>
......@@ -55,20 +61,23 @@ public sealed class EmitOptions : IEquatable<EmitOptions>
public DebugInformationFormat DebugInformationFormat { get; private set; }
/// <summary>
/// Name of the compilation: file name and extension. Null to use the compilation name.
/// Assembly name override - file name and extension. If not specified the the compilation name is used.
/// </summary>
/// <remarks>
/// By default the name of the output assembly is <see cref="Compilation.AssemblyName"/>. Only in rare cases it is necessary
/// to override the name.
///
/// CAUTION: If this is set to a (non-null) value other than the existing compilation output name, then internals-visible-to
/// and assembly references may not work as expected. In particular, things that were visible at bind time, based on the
/// name of the compilation, may not be visible at runtime and vice-versa.
/// </remarks>
public string OutputName { get; private set; }
public string OutputNameOverride { get; private set; }
/// <summary>
/// The name of the PDB file embedded in the PE image.
/// The name of the PDB file to be embedded in the PE image, or null to use the default.
/// </summary>
/// <remarks>
/// If not specified, the file name of the source module with an extension changed to "pdb" is used.
/// If not specified the file name of the source module with an extension changed to "pdb" is used.
/// </remarks>
public string PdbFilePath { get; private set; }
......@@ -81,34 +90,40 @@ public sealed class EmitOptions : IEquatable<EmitOptions>
bool metadataOnly = false,
DebugInformationFormat debugInformationFormat = 0,
string pdbFilePath = null,
string outputName = null,
string outputNameOverride = null,
int fileAlignment = 0,
ulong baseAddress = 0,
bool highEntropyVirtualAddressSpace = false,
SubsystemVersion subsystemVersion = default(SubsystemVersion),
string runtimeMetadataVersion = null)
string runtimeMetadataVersion = null,
bool tolerateErrors = false,
bool includePrivateMembers = false)
{
this.EmitMetadataOnly = metadataOnly;
this.DebugInformationFormat = (debugInformationFormat == 0) ? DebugInformationFormat.Pdb : debugInformationFormat;
this.PdbFilePath = pdbFilePath;
this.OutputName = outputName;
this.OutputNameOverride = outputNameOverride;
this.FileAlignment = fileAlignment;
this.BaseAddress = baseAddress;
this.HighEntropyVirtualAddressSpace = highEntropyVirtualAddressSpace;
this.SubsystemVersion = subsystemVersion;
this.RuntimeMetadataVersion = runtimeMetadataVersion;
this.TolerateErrors = tolerateErrors;
this.IncludePrivateMembers = includePrivateMembers;
}
private EmitOptions(EmitOptions other) : this(
other.EmitMetadataOnly,
other.DebugInformationFormat,
other.PdbFilePath,
other.OutputName,
other.OutputNameOverride,
other.FileAlignment,
other.BaseAddress,
other.HighEntropyVirtualAddressSpace,
other.SubsystemVersion,
other.RuntimeMetadataVersion)
other.RuntimeMetadataVersion,
other.TolerateErrors,
other.IncludePrivateMembers)
{
}
......@@ -132,8 +147,10 @@ public bool Equals(EmitOptions other)
this.SubsystemVersion.Equals(other.SubsystemVersion) &&
this.DebugInformationFormat == other.DebugInformationFormat &&
this.PdbFilePath == other.PdbFilePath &&
this.OutputName == other.OutputName &&
this.RuntimeMetadataVersion == other.RuntimeMetadataVersion;
this.OutputNameOverride == other.OutputNameOverride &&
this.RuntimeMetadataVersion == other.RuntimeMetadataVersion &&
this.TolerateErrors == other.TolerateErrors &&
this.IncludePrivateMembers == other.IncludePrivateMembers;
}
public override int GetHashCode()
......@@ -145,8 +162,10 @@ public override int GetHashCode()
Hash.Combine(this.SubsystemVersion.GetHashCode(),
Hash.Combine((int)this.DebugInformationFormat,
Hash.Combine(this.PdbFilePath,
Hash.Combine(this.OutputName,
Hash.Combine(this.RuntimeMetadataVersion, 0)))))))));
Hash.Combine(this.OutputNameOverride,
Hash.Combine(this.RuntimeMetadataVersion,
Hash.Combine(this.TolerateErrors,
Hash.Combine(this.IncludePrivateMembers, 0)))))))))));
}
public static bool operator ==(EmitOptions left, EmitOptions right)
......@@ -166,9 +185,9 @@ internal void ValidateOptions(DiagnosticBag diagnostics, CommonMessageProvider m
diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidDebugInformationFormat, Location.None, (int)DebugInformationFormat));
}
if (OutputName != null)
if (OutputNameOverride != null)
{
Exception error = MetadataHelpers.CheckAssemblyOrModuleName(OutputName, argumentName: null);
Exception error = MetadataHelpers.CheckAssemblyOrModuleName(OutputNameOverride, argumentName: null);
if (error != null)
{
diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidOutputName, Location.None, error.Message));
......@@ -222,14 +241,14 @@ public EmitOptions WithPdbFilePath(string path)
return new EmitOptions(this) { PdbFilePath = path };
}
public EmitOptions WithOutputName(string outputName)
public EmitOptions WithOutputNameOverride(string outputName)
{
if (this.OutputName == outputName)
if (this.OutputNameOverride == outputName)
{
return this;
}
return new EmitOptions(this) { OutputName = outputName };
return new EmitOptions(this) { OutputNameOverride = outputName };
}
public EmitOptions WithDebugInformationFormat(DebugInformationFormat format)
......@@ -295,5 +314,25 @@ public EmitOptions WithRuntimeMetadataVersion(string version)
return new EmitOptions(this) { RuntimeMetadataVersion = version };
}
public EmitOptions WithTolerateErrors(bool value)
{
if (TolerateErrors == value)
{
return this;
}
return new EmitOptions(this) { TolerateErrors = value };
}
public EmitOptions WithIncludePrivateMembers(bool value)
{
if (IncludePrivateMembers == value)
{
return this;
}
return new EmitOptions(this) { IncludePrivateMembers = value };
}
}
}
......@@ -1127,7 +1127,7 @@ lVbRuntimePlus:
metadataOnly:=False,
debugInformationFormat:=DebugInformationFormat.Pdb,
pdbFilePath:=Nothing, ' to be determined later
outputName:=Nothing, ' to be determined later
outputNameOverride:=Nothing, ' to be determined later
fileAlignment:=fileAlignment,
baseAddress:=baseAddress,
highEntropyVirtualAddressSpace:=highEntropyVA,
......
......@@ -2220,7 +2220,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
cancellationToken)
Dim assemblyName = FileNameUtilities.ChangeExtension(moduleBeingBuilt.EmitOptions.OutputName, extension:=Nothing)
Dim assemblyName = FileNameUtilities.ChangeExtension(moduleBeingBuilt.EmitOptions.OutputNameOverride, extension:=Nothing)
DocumentationCommentCompiler.WriteDocumentationCommentXml(Me, assemblyName, xmlDocStream, methodBodyDiagnosticBag, cancellationToken)
Me.ReportUnusedImports(Nothing, methodBodyDiagnosticBag, cancellationToken)
......
......@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Me.m_SourceAssembly = sourceAssembly
Me.m_AdditionalTypes = additionalTypes.NullToEmpty()
Me.m_MetadataName = If(emitOptions.OutputName Is Nothing, sourceAssembly.MetadataName, FileNameUtilities.ChangeExtension(emitOptions.OutputName, extension:=Nothing))
Me.m_MetadataName = If(emitOptions.OutputNameOverride Is Nothing, sourceAssembly.MetadataName, FileNameUtilities.ChangeExtension(emitOptions.OutputNameOverride, extension:=Nothing))
m_AssemblyOrModuleSymbolToModuleRefMap.Add(sourceAssembly, Me)
End Sub
......
......@@ -47,7 +47,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
m_MetadataName = If(specifiedName <> Microsoft.CodeAnalysis.Compilation.UnspecifiedModuleAssemblyName,
specifiedName,
If(emitOptions.OutputName, specifiedName))
If(emitOptions.OutputNameOverride, specifiedName))
m_AssemblyOrModuleSymbolToModuleRefMap.Add(sourceModule, Me)
......
......@@ -1743,7 +1743,7 @@ end namespace
Dim sourceAssembly = DirectCast(assembly, SourceAssemblySymbol)
Dim compilation = sourceAssembly.DeclaringCompilation
Dim emitOptions = New emitOptions(outputName:=sourceAssembly.Name)
Dim emitOptions = New emitOptions(outputNameOverride:=sourceAssembly.Name)
Dim cciModule = DirectCast(
New PEAssemblyBuilder(sourceAssembly, emitOptions, OutputKind.DynamicallyLinkedLibrary, GetDefaultModulePropertiesForSerialization(), SpecializedCollections.EmptyEnumerable(Of ResourceDescription), Nothing),
......@@ -1859,7 +1859,7 @@ End Class
Assert.Equal(name & extension, [module].Name)
Dim stream As New MemoryStream()
Assert.True(compilation.Emit(stream, options:=New EmitOptions(outputName:=nameOverride & extension)).Success)
Assert.True(compilation.Emit(stream, options:=New EmitOptions(outputNameOverride:=nameOverride & extension)).Success)
Using metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable())
Dim metadataReader = metadata.Module.GetMetadataReader()
......@@ -1895,7 +1895,7 @@ End Class
Assert.Equal(name & extension, [module].Name)
Dim stream As New MemoryStream()
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputName:=nameOverride & extension)).Success)
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputNameOverride:=nameOverride & extension)).Success)
Using metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable())
Dim metadataReader = metadata.Module.GetMetadataReader()
......@@ -1932,7 +1932,7 @@ End Class
Assert.Equal(name & extension, [module].Name)
Dim stream As New MemoryStream()
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputName:=nameOverride)).Success)
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputNameOverride:=nameOverride)).Success)
Using metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable())
Dim metadataReader = metadata.Module.GetMetadataReader()
......@@ -1969,7 +1969,7 @@ End Class
Assert.Equal(name & extension, [module].Name)
Dim stream As New MemoryStream()
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputName:=nameOverride & extension)).Success)
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputNameOverride:=nameOverride & extension)).Success)
Using metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable())
Dim metadataReader = metadata.Module.GetMetadataReader()
......@@ -2006,7 +2006,7 @@ End Class
Assert.Equal(name & extension, [module].Name)
Dim stream As New MemoryStream()
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputName:=nameOverride)).Success)
Assert.True(compilation.Emit(stream, , options:=New EmitOptions(outputNameOverride:=nameOverride)).Success)
Using metadata = ModuleMetadata.CreateFromImage(stream.ToImmutable())
Dim metadataReader = metadata.Module.GetMetadataReader()
......@@ -2031,7 +2031,7 @@ End Class
Dim compilation = CreateCompilationWithMscorlibAndVBRuntime(source, TestOptions.ReleaseDll)
compilation.VerifyDiagnostics()
Dim result = compilation.Emit(New MemoryStream(), options:=New EmitOptions(outputName:=" "))
Dim result = compilation.Emit(New MemoryStream(), options:=New EmitOptions(outputNameOverride:=" "))
End Sub
<WorkItem(545084, "DevDiv"), WorkItem(529492, "DevDiv")>
......
......@@ -225,7 +225,7 @@ End Namespace
Dim options = New EmitOptions(
debugInformationFormat:=CType(-1, DebugInformationFormat),
outputName:=" ",
outputNameOverride:=" ",
fileAlignment:=513,
subsystemVersion:=SubsystemVersion.Create(1000000, -1000000))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册