Skip to content

Commit f3c8cd0

Browse files
committed
Merge branch 'main' into dev/grendel/blobs-in-lib
* main: [Xamarin.Android.Build.Tasks] remove `$(AndroidSupportedAbis)` from `build.props` (#8717) [Xamarin.Android.Build.Tasks] BannedApiAnalyzers for Resolve() (#8715)
2 parents 879604c + 5472eec commit f3c8cd0

39 files changed

+183
-209
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
M:Mono.Cecil.FieldReference.Resolve();Use IMetadataResolver.Resolve() instead, so future calls can be cached
2+
M:Mono.Cecil.MethodReference.Resolve();Use IMetadataResolver.Resolve() instead, so future calls can be cached.
3+
M:Mono.Cecil.TypeReference.Resolve();Use IMetadataResolver.Resolve() instead, so future calls can be cached.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<WarningsAsErrors>RS0030</WarningsAsErrors>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" PrivateAssets="All" />
7+
<AdditionalFiles Include="$(MSBuildThisFileDirectory)BannedSymbols.txt" />
8+
</ItemGroup>
9+
</Project>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public void ProcessType (TypeDefinition type)
2323
{
2424
// If this isn't a JLO or IJavaObject implementer,
2525
// then we don't need to MarkJavaObjects
26-
if (!type.ImplementsIJavaObject ())
26+
if (!type.ImplementsIJavaObject (cache))
2727
return;
2828

2929
PreserveJavaObjectImplementation (type);
3030

31-
if (IsImplementor (type))
31+
if (IsImplementor (type, cache))
3232
PreserveImplementor (type);
3333

3434
// If a user overrode a method, we need to preserve it,
@@ -195,7 +195,7 @@ void PreserveInterfaces (TypeDefinition type)
195195

196196
foreach (var iface in type.Interfaces) {
197197
var td = iface.InterfaceType.Resolve ();
198-
if (!td.ImplementsIJavaPeerable ())
198+
if (!td.ImplementsIJavaPeerable (cache))
199199
continue;
200200
Annotations.Mark (td);
201201
}
@@ -302,9 +302,9 @@ void PreserveConstructors (TypeDefinition type, TypeDefinition helper)
302302
PreserveMethod (type, ctor);
303303
}
304304

305-
static bool IsImplementor (TypeDefinition type)
305+
static bool IsImplementor (TypeDefinition type, IMetadataResolver cache)
306306
{
307-
return type.Name.EndsWith ("Implementor", StringComparison.Ordinal) && type.Inherits ("Java.Lang.Object");
307+
return type.Name.EndsWith ("Implementor", StringComparison.Ordinal) && type.Inherits ("Java.Lang.Object", cache);
308308
}
309309

310310
static bool IsUserType (TypeDefinition type)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void ProcessType (TypeDefinition type)
3737
{
3838
if (!IsActiveFor (type.Module.Assembly))
3939
return;
40-
if (!type.Inherits ("Android.App.Application"))
40+
if (!type.Inherits ("Android.App.Application", cache))
4141
return;
4242

4343
ProcessAttributeProvider (type);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override void Initialize (LinkContext context, MarkContext markContext)
2323

2424
public void ProcessType (TypeDefinition type)
2525
{
26-
if (type.IsJavaException ())
26+
if (type.IsJavaException (cache))
2727
PreserveJavaException (type);
2828
}
2929

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void ProcessType (TypeDefinition type)
2929
return;
3030

3131
// Mono.Android interfaces will always inherit IJavaObject
32-
if (!type.ImplementsIJavaObject ())
32+
if (!type.ImplementsIJavaObject (cache))
3333
return;
3434

3535
foreach (MethodReference method in type.Methods)

src/Xamarin.Android.Build.Tasks/Linker/External/Linker/OverrideInformation.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,5 @@ public bool IsOverrideOfInterfaceMember
2525
return Base.DeclaringType.IsInterface;
2626
}
2727
}
28-
29-
public TypeDefinition InterfaceType
30-
{
31-
get
32-
{
33-
if (!IsOverrideOfInterfaceMember)
34-
return null;
35-
36-
if (MatchingInterfaceImplementation != null)
37-
return MatchingInterfaceImplementation.InterfaceType.Resolve ();
38-
39-
return Base.DeclaringType;
40-
}
41-
}
4228
}
43-
}
29+
}

src/Xamarin.Android.Build.Tasks/Linker/External/Mono.Tuner/CecilRocks.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -453,67 +453,5 @@ public static ParameterDefinition GetParameter (this MethodBody self, int index)
453453

454454
return parameters [index];
455455
}
456-
457-
public static bool Implements (this TypeReference self, string interfaceName)
458-
{
459-
if (interfaceName == null)
460-
throw new ArgumentNullException ("interfaceName");
461-
if (self == null)
462-
return false;
463-
464-
TypeDefinition type = self.Resolve ();
465-
if (type == null)
466-
return false; // not enough information available
467-
468-
// special case, check if we implement ourselves
469-
if (type.IsInterface && (type.FullName == interfaceName))
470-
return true;
471-
472-
return Implements (type, interfaceName, (interfaceName.IndexOf ('`') >= 0));
473-
}
474-
475-
public static bool Implements (TypeDefinition type, string interfaceName, bool generic)
476-
{
477-
while (type != null) {
478-
// does the type implements it itself
479-
if (type.HasInterfaces) {
480-
foreach (var iface in type.Interfaces) {
481-
string fullname = (generic) ? iface.InterfaceType.GetElementType ().FullName : iface.InterfaceType.FullName;
482-
if (fullname == interfaceName)
483-
return true;
484-
//if not, then maybe one of its parent interfaces does
485-
if (Implements (iface.InterfaceType.Resolve (), interfaceName, generic))
486-
return true;
487-
}
488-
}
489-
490-
type = type.BaseType != null ? type.BaseType.Resolve () : null;
491-
}
492-
return false;
493-
}
494-
495-
public static bool Inherits (this TypeReference self, string @namespace, string name)
496-
{
497-
if (@namespace == null)
498-
throw new ArgumentNullException ("namespace");
499-
if (name == null)
500-
throw new ArgumentNullException ("name");
501-
if (self == null)
502-
return false;
503-
504-
TypeReference current = self.Resolve ();
505-
while (current != null) {
506-
if (current.Is (@namespace, name))
507-
return true;
508-
if (current.Is ("System", "Object"))
509-
return false;
510-
511-
TypeDefinition td = current.Resolve ();
512-
if (td == null)
513-
return false; // could not resolve type
514-
current = td.BaseType;
515-
}
516-
return false;
517-
}
518456
}
519457
}

src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Extensions.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@ static class Extensions {
2020
const string IJavaPeerable = "Java.Interop.IJavaPeerable";
2121
const string JavaThrowable = "Java.Lang.Throwable";
2222

23-
public static bool IsJavaObject (this TypeDefinition type)
23+
public static bool IsJavaObject (this TypeDefinition type, IMetadataResolver resolver)
2424
{
25-
return type.Inherits (JavaObject);
25+
return type.Inherits (JavaObject, resolver);
2626
}
2727

28-
public static bool IsJavaException (this TypeDefinition type)
28+
public static bool IsJavaException (this TypeDefinition type, IMetadataResolver resolver)
2929
{
30-
return type.Inherits (JavaThrowable);
30+
return type.Inherits (JavaThrowable, resolver);
3131
}
3232

33-
public static bool ImplementsIJavaObject (this TypeDefinition type)
33+
public static bool ImplementsIJavaObject (this TypeDefinition type, IMetadataResolver resolver)
3434
{
35-
return type.Implements (IJavaObject);
35+
return type.Implements (IJavaObject, resolver);
3636
}
3737

38-
public static bool ImplementsIJavaPeerable (this TypeDefinition type)
38+
public static bool ImplementsIJavaPeerable (this TypeDefinition type, IMetadataResolver resolver)
3939
{
40-
return type.Implements (IJavaPeerable);
40+
return type.Implements (IJavaPeerable, resolver);
4141
}
4242

43-
public static object GetSettableValue (this CustomAttributeArgument arg)
43+
public static object GetSettableValue (this CustomAttributeArgument arg, IMetadataResolver cache)
4444
{
4545
TypeReference tr = arg.Value as TypeReference;
46-
TypeDefinition td = tr != null ? tr.Resolve () : null;
46+
TypeDefinition td = tr != null ? cache.Resolve (tr) : null;
4747
return td != null ? td.FullName + "," + td.Module.Assembly.FullName : arg.Value;
4848
}
4949

@@ -119,25 +119,25 @@ public static TypeDefinition GetType (AssemblyDefinition assembly, string typeNa
119119
return assembly.MainModule.GetType (typeName);
120120
}
121121

122-
public static bool Implements (this TypeReference self, string interfaceName)
122+
public static bool Implements (this TypeReference self, string interfaceName, IMetadataResolver resolver)
123123
{
124124
if (interfaceName == null)
125125
throw new ArgumentNullException ("interfaceName");
126126
if (self == null)
127127
return false;
128128

129-
TypeDefinition type = self.Resolve ();
129+
TypeDefinition type = resolver.Resolve (self);
130130
if (type == null)
131131
return false; // not enough information available
132132

133133
// special case, check if we implement ourselves
134134
if (type.IsInterface && (type.FullName == interfaceName))
135135
return true;
136136

137-
return Implements (type, interfaceName, (interfaceName.IndexOf ('`') >= 0));
137+
return Implements (type, interfaceName, (interfaceName.IndexOf ('`') >= 0), resolver);
138138
}
139139

140-
public static bool Implements (TypeDefinition type, string interfaceName, bool generic)
140+
public static bool Implements (TypeDefinition type, string interfaceName, bool generic, IMetadataResolver resolver)
141141
{
142142
while (type != null) {
143143
// does the type implements it itself
@@ -148,32 +148,36 @@ public static bool Implements (TypeDefinition type, string interfaceName, bool g
148148
if (fullname == interfaceName)
149149
return true;
150150
//if not, then maybe one of its parent interfaces does
151-
if (Implements (iface.Resolve (), interfaceName, generic))
151+
if (Implements (resolver.Resolve (iface), interfaceName, generic, resolver))
152152
return true;
153153
}
154154
}
155155

156-
type = type.BaseType != null ? type.BaseType.Resolve () : null;
156+
if (type.BaseType != null) {
157+
type = resolver.Resolve (type.BaseType);
158+
} else {
159+
type = null;
160+
}
157161
}
158162
return false;
159163
}
160164

161-
public static bool Inherits (this TypeReference self, string className)
165+
public static bool Inherits (this TypeReference self, string className, IMetadataResolver resolver)
162166
{
163167
if (className == null)
164168
throw new ArgumentNullException ("className");
165169
if (self == null)
166170
return false;
167171

168-
TypeReference current = self.Resolve ();
172+
TypeReference current = resolver.Resolve (self);
169173
while (current != null) {
170174
string fullname = current.FullName;
171175
if (fullname == className)
172176
return true;
173177
if (fullname == "System.Object")
174178
return false;
175179

176-
TypeDefinition td = current.Resolve ();
180+
TypeDefinition td = resolver.Resolve (current);
177181
if (td == null)
178182
return false; // could not resolve type
179183
current = td.BaseType;
@@ -285,7 +289,7 @@ public static bool TryGetBaseOrInterfaceRegisterMember (this MethodDefinition me
285289
if (iface.InterfaceType.IsGenericInstance)
286290
continue;
287291

288-
var itype = iface.InterfaceType.Resolve ();
292+
var itype = resolver.Resolve (iface.InterfaceType);
289293
if (itype == null || !itype.HasMethods)
290294
continue;
291295

src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class FixLegacyResourceDesignerStep : LinkDesignerBase
2626
internal const string DesignerAssemblyName = "_Microsoft.Android.Resource.Designer";
2727
internal const string DesignerAssemblyNamespace = "_Microsoft.Android.Resource.Designer";
2828

29+
#if !ILLINK
30+
public FixLegacyResourceDesignerStep (IMetadataResolver cache) : base (cache) { }
31+
#endif
32+
2933
bool designerLoaded = false;
3034
AssemblyDefinition designerAssembly = null;
3135
TypeDefinition designerType = null;
@@ -93,7 +97,7 @@ internal override bool ProcessAssemblyDesigner (AssemblyDefinition assembly)
9397

9498
LogMessage ($" Adding reference {designerAssembly.Name.Name}.");
9599
assembly.MainModule.AssemblyReferences.Add (designerAssembly.Name);
96-
var importedDesignerType = assembly.MainModule.ImportReference (designerType.Resolve ());
100+
var importedDesignerType = assembly.MainModule.ImportReference (Cache.Resolve (designerType));
97101

98102
LogMessage ($" FixupAssemblyTypes {assembly.Name.Name}.");
99103
// now replace all ldsfld with a call to the property get_ method.
@@ -150,7 +154,7 @@ string GetFixupKey (Instruction instruction, string designerFullName)
150154
(fieldRef.DeclaringType?.ToString()?.Contains (".Resource/") ?? false)) {
151155
var canResolve = false;
152156
try {
153-
var resolved = fieldRef.Resolve ();
157+
var resolved = Cache.Resolve (fieldRef);
154158
canResolve = resolved != null;
155159
} catch (Exception) {
156160
}

0 commit comments

Comments
 (0)