Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
2330b4be
R
runtime
项目概览
dotNET Platform
/
runtime
12 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2330b4be
编写于
3月 01, 2022
作者:
J
Jeremy Koritzinsky
提交者:
GitHub
3月 01, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make DllImportGenerator emit a GeneratedCodeAttribute on our stubs (#65868)
上级
defd20c1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
5 deletion
+78
-5
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml
...ivate.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml
+3
-0
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
...opServices/gen/DllImportGenerator/DllImportStubContext.cs
+22
-5
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
...vices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
+2
-0
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
...llImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
+51
-0
未找到文件。
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml
浏览文件 @
2330b4be
...
...
@@ -268,6 +268,9 @@
<type
fullname=
"System.Runtime.InteropServices.GeneratedDllImportAttribute"
>
<attribute
internal=
"RemoveAttributeInstances"
/>
</type>
<type
fullname=
"System.CodeDom.Compiler.GeneratedCodeAttribute"
>
<attribute
internal=
"RemoveAttributeInstances"
/>
</type>
<!-- The following attributes are generated by the compiler, so they could be in any assembly -->
...
...
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
浏览文件 @
2330b4be
...
...
@@ -42,6 +42,10 @@ public static bool AreCompilationSettingsEqual(StubEnvironment env1, StubEnviron
internal
sealed
class
DllImportStubContext
:
IEquatable
<
DllImportStubContext
>
{
private
static
readonly
string
GeneratorName
=
typeof
(
DllImportGenerator
).
Assembly
.
GetName
().
Name
;
private
static
readonly
string
GeneratorVersion
=
typeof
(
DllImportGenerator
).
Assembly
.
GetName
().
Version
.
ToString
();
// We don't need the warnings around not setting the various
// non-nullable fields/properties on this type in the constructor
// since we always use a property initializer.
...
...
@@ -123,18 +127,31 @@ public IEnumerable<ParameterSyntax> StubParameters
ImmutableArray
<
AttributeListSyntax
>.
Builder
additionalAttrs
=
ImmutableArray
.
CreateBuilder
<
AttributeListSyntax
>();
// Define additional attributes for the stub definition.
if
(
env
.
TargetFramework
!=
TargetFramework
.
Unknown
)
{
// Define additional attributes for the stub definition.
additionalAttrs
.
Add
(
AttributeList
(
SingletonSeparatedList
(
Attribute
(
ParseName
(
TypeNames
.
System_CodeDom_Compiler_GeneratedCodeAttribute
),
AttributeArgumentList
(
SeparatedList
(
new
[]
{
AttributeArgument
(
LiteralExpression
(
SyntaxKind
.
StringLiteralExpression
,
Literal
(
GeneratorName
))),
AttributeArgument
(
LiteralExpression
(
SyntaxKind
.
StringLiteralExpression
,
Literal
(
GeneratorVersion
)))
}))))));
}
if
(
env
.
TargetFrameworkVersion
>=
new
Version
(
5
,
0
)
&&
!
MethodIsSkipLocalsInit
(
env
,
method
))
{
additionalAttrs
.
Add
(
AttributeList
(
SeparatedList
(
new
[]
{
SingletonSeparatedList
(
// Adding the skip locals init indiscriminately since the source generator is
// targeted at non-blittable method signatures which typically will contain locals
// in the generated code.
Attribute
(
ParseName
(
TypeNames
.
System_Runtime_CompilerServices_SkipLocalsInitAttribute
))
})));
Attribute
(
ParseName
(
TypeNames
.
System_Runtime_CompilerServices_SkipLocalsInitAttribute
)))));
}
return
new
DllImportStubContext
()
...
...
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
浏览文件 @
2330b4be
...
...
@@ -67,5 +67,7 @@ public static string MarshalEx(InteropGenerationOptions options)
public
const
string
DefaultDllImportSearchPathsAttribute
=
"System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute"
;
public
const
string
DllImportSearchPath
=
"System.Runtime.InteropServices.DllImportSearchPath"
;
public
const
string
System_CodeDom_Compiler_GeneratedCodeAttribute
=
"System.CodeDom.Compiler.GeneratedCodeAttribute"
;
}
}
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
浏览文件 @
2330b4be
...
...
@@ -64,6 +64,57 @@ partial class C
Assert
.
DoesNotContain
(
stubMethod
.
GetAttributes
(),
attr
=>
attr
.
AttributeClass
!.
ToDisplayString
()
==
typeof
(
SkipLocalsInitAttribute
).
FullName
);
}
[
ConditionalFact
]
public
async
Task
GeneratedCodeAdded
()
{
string
source
=
@"
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly:DisableRuntimeMarshalling]
partial class C
{
[GeneratedDllImportAttribute(""DoesNotExist"")]
public static partial S Method();
}
[NativeMarshalling(typeof(Native))]
struct S
{
}
struct Native
{
public Native(S s) { }
public S ToManaged() { return default; }
}"
;
Compilation
comp
=
await
TestUtils
.
CreateCompilation
(
source
);
Compilation
newComp
=
TestUtils
.
RunGenerators
(
comp
,
out
_
,
new
Microsoft
.
Interop
.
DllImportGenerator
());
ITypeSymbol
c
=
newComp
.
GetTypeByMetadataName
(
"C"
)!;
IMethodSymbol
stubMethod
=
c
.
GetMembers
().
OfType
<
IMethodSymbol
>().
Single
(
m
=>
m
.
Name
==
"Method"
);
Assert
.
Contains
(
stubMethod
.
GetAttributes
(),
attr
=>
attr
.
AttributeClass
!.
ToDisplayString
()
==
typeof
(
System
.
CodeDom
.
Compiler
.
GeneratedCodeAttribute
).
FullName
);
}
[
ConditionalFact
]
public
async
Task
GeneratedCodeNotAddedOnForwardingStub
()
{
string
source
=
@"
using System.Runtime.InteropServices;
partial class C
{
[GeneratedDllImportAttribute(""DoesNotExist"")]
public static partial void Method();
}"
;
Compilation
comp
=
await
TestUtils
.
CreateCompilation
(
source
);
Compilation
newComp
=
TestUtils
.
RunGenerators
(
comp
,
out
_
,
new
Microsoft
.
Interop
.
DllImportGenerator
());
ITypeSymbol
c
=
newComp
.
GetTypeByMetadataName
(
"C"
)!;
IMethodSymbol
stubMethod
=
c
.
GetMembers
().
OfType
<
IMethodSymbol
>().
Single
(
m
=>
m
.
Name
==
"Method"
);
Assert
.
DoesNotContain
(
stubMethod
.
GetAttributes
(),
attr
=>
attr
.
AttributeClass
!.
ToDisplayString
()
==
typeof
(
System
.
CodeDom
.
Compiler
.
GeneratedCodeAttribute
).
FullName
);
}
public
static
IEnumerable
<
object
[
]>
GetDownlevelTargetFrameworks
()
{
yield
return
new
object
[]
{
TestTargetFramework
.
Net
,
true
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录