2016-04-21 15:57:02 +03:00
|
|
|
// Copyright 2012-2013 Xamarin Inc. All rights reserved.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Mono.Cecil;
|
|
|
|
using Mono.Tuner;
|
|
|
|
using Xamarin.Linker;
|
|
|
|
|
|
|
|
namespace MonoTouch.Tuner {
|
|
|
|
|
2018-02-14 11:27:12 +03:00
|
|
|
public class MonoTouchSweepStep : CoreSweepStep {
|
2016-04-21 15:57:02 +03:00
|
|
|
|
2017-02-07 16:51:06 +03:00
|
|
|
public MonoTouchSweepStep (LinkerOptions options)
|
|
|
|
: base (options.LinkSymbols)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-27 18:06:27 +03:00
|
|
|
protected override void SweepAssemblyDefinition (AssemblyDefinition assembly)
|
2016-04-21 15:57:02 +03:00
|
|
|
{
|
2018-07-27 18:06:27 +03:00
|
|
|
base.SweepAssemblyDefinition (assembly);
|
2016-04-21 15:57:02 +03:00
|
|
|
|
|
|
|
if (assembly.HasCustomAttributes)
|
|
|
|
SweepAttributes (assembly.CustomAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SweepAttributes (IList<CustomAttribute> attributes)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < attributes.Count; i++) {
|
|
|
|
var ca = attributes [i];
|
|
|
|
|
|
|
|
// we do not have to keep IVT to assemblies that are not part of the application
|
|
|
|
if (!ca.AttributeType.Is ("System.Runtime.CompilerServices", "InternalsVisibleToAttribute"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// validating the public key and the public key token would be time consuming
|
|
|
|
// worse case (no match) is that we keep the attribute while it's not needed
|
|
|
|
var fqn = (ca.ConstructorArguments [0].Value as string);
|
2018-10-03 22:00:59 +03:00
|
|
|
int comma = fqn.IndexOf (',');
|
|
|
|
if (comma != -1)
|
|
|
|
fqn = fqn.Substring (0, comma);
|
2016-04-21 15:57:02 +03:00
|
|
|
|
|
|
|
bool need_ivt = false;
|
|
|
|
foreach (var assembly in Context.GetAssemblies ()) {
|
|
|
|
if (assembly.Name.Name == fqn) {
|
|
|
|
need_ivt = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!need_ivt)
|
|
|
|
attributes.RemoveAt (i--);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 11:06:46 +03:00
|
|
|
}
|