Skip to content

Commit 160c059

Browse files
committed
Merge branch 'main' into dev/grendel/clr-host
* main: [illink] consolidate & remove hardcoded assembly names (#9662) Bump to NuGet/NuGet.Client@aa7eb998 (#9682) [Microsoft.Android.Sdk.Analysis] fix global types (#9680)
2 parents b91865d + 7aed4e3 commit 160c059

30 files changed

+90
-503
lines changed

src/Microsoft.Android.Sdk.Analysis/Analyzers/CustomApplicationAnalyzer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,20 @@ private static void AnalyzeClass (SyntaxNodeAnalysisContext context)
5252
var parameters = constructor.ParameterList.Parameters;
5353
if (parameters.Count != 2)
5454
continue;
55-
if (parameters [0].Type.ToString () != "IntPtr")
55+
var type = parameters [0].Type switch {
56+
IdentifierNameSyntax identifierNameSyntax => identifierNameSyntax.Identifier.Text,
57+
QualifiedNameSyntax qualifiedNameSyntax => qualifiedNameSyntax.Right.Identifier.Text,
58+
_ => parameters [0].Type.ToString ()
59+
};
60+
if (type != "IntPtr" && type != "nint")
5661
continue;
5762
var ns = Utilities.GetNamespaceForParameterType (parameters [1], context.SemanticModel);
58-
var type = parameters [1].Type.ToString();
59-
var isJniHandle = (ns == "Android.Runtime") && (type == "JniHandleOwnership") || (type == "Android.Runtime.JniHandleOwnership");
63+
type = parameters [1].Type switch {
64+
IdentifierNameSyntax identifierNameSyntax => identifierNameSyntax.Identifier.Text,
65+
QualifiedNameSyntax qualifiedNameSyntax => qualifiedNameSyntax.Right.Identifier.Text,
66+
_ => parameters [1].Type.ToString ()
67+
};
68+
var isJniHandle = (ns == "Android.Runtime") && (type == "JniHandleOwnership");
6069
if (!isJniHandle)
6170
continue;
6271
foundActivationConstructor = true;

src/Microsoft.Android.Sdk.Analysis/Tests/DNAA0001Tests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ public async Task DNAA0001DoesNotShow ()
1515
}
1616

1717
[Test]
18-
[TestCase ("JniHandleOwnership")]
19-
[TestCase ("Android.Runtime.JniHandleOwnership")]
20-
public async Task DNAA0001DoesNotShowForExistingCode (string type)
18+
[TestCase ("IntPtr", "JniHandleOwnership")]
19+
[TestCase ("nint", "Android.Runtime.JniHandleOwnership")]
20+
[TestCase ("global::System.IntPtr", "global::Android.Runtime.JniHandleOwnership")]
21+
[TestCase ("System.IntPtr", "AR.JniHandleOwnership")]
22+
public async Task DNAA0001DoesNotShowForExistingCode (string handle, string type)
2123
{
2224
var test = $@"
2325
using System;
2426
using Android.App;
2527
using Android.Runtime;
28+
using AR = Android.Runtime;
2629
namespace ConsoleApplication1
2730
{{
2831
public class Foo : Application
2932
{{
30-
public Foo(IntPtr javaReference, {type} transfer) : base(javaReference, transfer)
33+
public Foo({handle} javaReference, {type} transfer) : base(javaReference, transfer)
3134
{{
3235
}}
3336
}}

src/Microsoft.Android.Sdk.Analysis/Utilities/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal static string GetNamespaceForParameterType (ParameterSyntax parameterSy
4545
}
4646

4747
// Get the symbol for the type of the parameter
48-
var typeSymbol = semanticModel.GetSymbolInfo (parameterSyntax.Type).Symbol as ITypeSymbol;
48+
var typeSymbol = semanticModel.GetTypeInfo (parameterSyntax.Type).Type;
4949

5050
if (typeSymbol == null) {
5151
return null; // Unable to resolve the symbol

src/Microsoft.Android.Sdk.ILLink/ApplyPreserveAttribute.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5-
5+
using Mono.Cecil;
66
using Mono.Linker;
77
using Mono.Linker.Steps;
8-
9-
using Mono.Cecil;
8+
using Xamarin.Android.Tasks;
109

1110
namespace Microsoft.Android.Sdk.ILLink
1211
{
@@ -25,7 +24,7 @@ public override SubStepTargets Targets {
2524

2625
public override bool IsActiveFor (AssemblyDefinition assembly)
2726
{
28-
return !Profile.IsSdkAssembly (assembly) && Annotations.GetAction (assembly) == AssemblyAction.Link;
27+
return !MonoAndroidHelper.IsFrameworkAssembly (assembly) && Annotations.GetAction (assembly) == AssemblyAction.Link;
2928
}
3029

3130
public override void ProcessType (TypeDefinition type)

src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Mono.Linker.Steps;
77
using Java.Interop.Tools.Cecil;
88
using Xamarin.Android.Tasks;
9-
using Profile = Microsoft.Android.Sdk.ILLink.Profile;
109

1110
namespace MonoDroid.Tuner {
1211

@@ -27,9 +26,7 @@ public override void Initialize (LinkContext context, MarkContext markContext)
2726

2827
bool IsActiveFor (AssemblyDefinition assembly)
2928
{
30-
if (Profile.IsSdkAssembly (assembly))
31-
return false;
32-
if (Profile.IsProductAssembly (assembly))
29+
if (MonoAndroidHelper.IsFrameworkAssembly (assembly))
3330
return false;
3431

3532
return assembly.MainModule.HasTypeReference ("System.Net.Http.HttpMessageHandler") ||
@@ -397,7 +394,7 @@ static bool IsImplementor (TypeDefinition type, IMetadataResolver cache)
397394

398395
static bool IsUserType (TypeDefinition type)
399396
{
400-
return !MonoAndroidHelper.IsFrameworkAssembly (type.Module.Assembly.Name.Name + ".dll");
397+
return !MonoAndroidHelper.IsFrameworkAssembly (type.Module.Assembly);
401398
}
402399

403400
void PreserveImplementor (TypeDefinition type)

src/Microsoft.Android.Sdk.ILLink/Microsoft.Android.Sdk.ILLink.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<PackageReference Include="Microsoft.NET.ILLink" Version="$(MicrosoftNETILLinkTasksPackageVersion)" />
1212
<ProjectReference Include="..\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj" ReferenceOutputAssembly="False" />
1313

14-
<Compile Include="..\Xamarin.Android.Build.Tasks\obj\$(Configuration)\Profile.g.cs" Link="Profile.g.cs" />
15-
1614
<!--Include shared linker sources-->
1715
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\AddKeepAlivesStep.cs" Link="MonoDroid.Tuner\AddKeepAlivesStep.cs" />
1816
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\AndroidLinkConfiguration.cs" Link="MonoDroid.Tuner\AndroidLinkConfiguration.cs" />
@@ -21,8 +19,6 @@
2119
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\FixLegacyResourceDesignerStep.cs" Link="MonoDroid.Tuner\FixLegacyResourceDesignerStep.cs" />
2220
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\LinkDesignerBase.cs" Link="MonoDroid.Tuner\LinkDesignerBase.cs" />
2321
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\RemoveResourceDesignerStep.cs" Link="MonoDroid.Tuner\RemoveResourceDesignerStep.cs" />
24-
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\MonoDroidProfile.cs" Link="MonoDroid.Tuner\MonoDroidProfile.cs" />
25-
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\Mobile.Tuner\MobileProfile.cs" Link="Mobile.Tuner\MobileProfile.cs" />
2622

2723
<!--Other .NET for Android / Java.Interop files-->
2824
<Compile Include="..\..\external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil\CustomAttributeProviderRocks.cs" Link="Java.Interop\CustomAttributeProviderRocks.cs" />

src/Microsoft.Android.Sdk.ILLink/PreserveApplications.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections;
33
using System.Linq;
4-
4+
using Mono.Cecil;
55
using Mono.Linker;
66
using Mono.Linker.Steps;
7-
87
using Mono.Tuner;
9-
using Mobile.Tuner;
10-
11-
using Mono.Cecil;
8+
using Xamarin.Android.Tasks;
129

1310
namespace MonoDroid.Tuner {
1411

src/Microsoft.Android.Sdk.ILLink/PreserveExportedTypes.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5-
5+
using Microsoft.Android.Sdk.ILLink;
6+
using Mono.Cecil;
67
using Mono.Linker;
78
using Mono.Linker.Steps;
8-
9-
using Mono.Cecil;
10-
using Microsoft.Android.Sdk.ILLink;
9+
using Xamarin.Android.Tasks;
1110

1211
namespace Mono.Tuner {
1312

@@ -24,7 +23,11 @@ public override SubStepTargets Targets {
2423

2524
public override bool IsActiveFor (AssemblyDefinition assembly)
2625
{
27-
return !Profile.IsSdkAssembly (assembly);
26+
if (MonoAndroidHelper.IsFrameworkAssembly (assembly))
27+
return false;
28+
29+
return assembly.MainModule.HasTypeReference ("Java.Interop.ExportAttribute") ||
30+
assembly.MainModule.HasTypeReference ("Java.Interop.ExportFieldAttribute");
2831
}
2932

3033
public override void ProcessField (FieldDefinition field)

src/Microsoft.Android.Sdk.ILLink/PreserveJavaExceptions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections;
33
using System.Linq;
4-
4+
using Mono.Cecil;
55
using Mono.Linker;
66
using Mono.Linker.Steps;
7-
87
using Mono.Tuner;
9-
using Mobile.Tuner;
10-
11-
using Mono.Cecil;
8+
using Xamarin.Android.Tasks;
129

1310
namespace MonoDroid.Tuner {
1411

src/Microsoft.Android.Sdk.ILLink/Profile.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)