Skip to content

Commit

Permalink
Simplify the workaround
Browse files Browse the repository at this point in the history
This also gets rid of typo in previous commit, which caused problems
in XF test.
  • Loading branch information
radekdoulik committed Feb 25, 2021
1 parent 98751e4 commit add54f8
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/Microsoft.Android.Sdk.ILLink/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ List<IStep> Steps {
}
}

static MethodInfo getReferencedAssembliesMethod = typeof (LinkContext).GetMethod ("GetReferencedAssemblies", BindingFlags.Public | BindingFlags.Instance);

protected override void Process ()
{
string tfmPaths;
Expand All @@ -44,9 +46,12 @@ protected override void Process ()
subSteps2.Add (new PreserveRegistrations (cache));
subSteps2.Add (new PreserveJavaInterfaces ());

ProcessDispatcher (subSteps1);
ProcessDispatcher (subSteps1);
ProcessStep (new FixAbstractMethodsStep (cache));
InsertAfter (new FixAbstractMethodsStep (cache), "SetupStep");
InsertAfter (subSteps2, "SetupStep");
InsertAfter (subSteps1, "SetupStep");

// temporary workaround: this call forces illink to process all the assemblies
getReferencedAssembliesMethod.Invoke (Context, null);

string proguardPath;
if (Context.TryGetCustomData ("ProguardConfiguration", out proguardPath))
Expand All @@ -59,26 +64,6 @@ protected override void Process ()
InsertAfter (new StripEmbeddedLibraries (), "CleanStep");
}

static Type dispatcherType = typeof (SubStepsDispatcher);
static MethodInfo initMethod = dispatcherType.GetMethod ("InitializeSubSteps", BindingFlags.NonPublic | BindingFlags.Instance);
static MethodInfo browseMethod = dispatcherType.GetMethod ("BrowseAssemblies", BindingFlags.NonPublic | BindingFlags.Instance);
static MethodInfo getReferencedAssembliesMethod = typeof (LinkContext).GetMethod ("GetReferencedAssemblies", BindingFlags.Public | BindingFlags.Instance);
static MethodInfo processAssemblyMethod = typeof (BaseStep).GetMethod ("ProcessAssembly", BindingFlags.NonPublic | BindingFlags.Instance);

void ProcessStep (BaseStep step)
{
typeof (BaseStep).GetField ("_context", BindingFlags.Instance | BindingFlags.NonPublic).SetValue (step, Context);

foreach (var assembly in (IEnumerable<AssemblyDefinition>) getReferencedAssembliesMethod.Invoke (Context, null))
processAssemblyMethod.Invoke (step, new object [] { assembly });
}

void ProcessDispatcher (SubStepDispatcher dispatcher)
{
initMethod.Invoke (dispatcher, new object [] { Context });
browseMethod.Invoke (dispatcher, new object [] { getReferencedAssembliesMethod.Invoke (Context, null) });
}

void InsertAfter (IStep step, string stepName)
{
for (int i = 0; i < Steps.Count;) {
Expand Down

0 comments on commit add54f8

Please sign in to comment.