Skip to content

Commit

Permalink
Fix order of custom steps (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbomer authored Jun 4, 2021
1 parent a3f68c6 commit 21df7db
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected int SetupContext (ILogger customLogger = null)

var body_substituter_steps = new Stack<string> ();
var xml_custom_attribute_steps = new Stack<string> ();
var custom_steps = new Stack<string> ();
var custom_steps = new List<string> ();
var set_optimizations = new List<(CodeOptimizations, string, bool)> ();
bool dumpDependencies = false;
string dependenciesFileName = null;
Expand Down Expand Up @@ -298,7 +298,7 @@ protected int SetupContext (ILogger customLogger = null)
continue;
}
case "--custom-step":
if (!GetStringParam (token, l => custom_steps.Push (l)))
if (!GetStringParam (token, l => custom_steps.Add (l)))
return -1;

continue;
Expand Down
67 changes: 67 additions & 0 deletions test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,73 @@ public void TestCustomStepsWithBeforeAndAfterSteps ()
Assert.Throws<ArgumentException> (() => task.CreateDriver ());
}

[Fact]
public void TestCustomStepOrdering ()
{
var customSteps = new ITaskItem[] {
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep" },
{ "BeforeStep", "MarkStep" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep2" },
{ "BeforeStep", "MarkStep" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep3" },
{ "AfterStep", "MarkStep" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep4" },
{ "AfterStep", "MarkStep" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep5" },
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockCustomStep6" },
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockMarkHandler" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockMarkHandler2" },
{ "BeforeStep", "MockMarkHandler" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockMarkHandler3" },
{ "AfterStep", "MockMarkHandler2" }
}),
new TaskItem (Assembly.GetExecutingAssembly ().Location, new Dictionary<string, string> {
{ "Type", "ILLink.Tasks.Tests.MockMarkHandler4" }
}),
};
var task = new MockTask () {
CustomSteps = customSteps
};
using (var driver = task.CreateDriver ()) {
var actualSteps = driver.Context.Pipeline.GetSteps ().Select (s => s.GetType ().Name).ToList ();
Assert.Equal (new List<string> {
"MockCustomStep",
"MockCustomStep2",
"MarkStep",
"MockCustomStep4",
"MockCustomStep3",
}, actualSteps.Skip (actualSteps.IndexOf ("MarkStep") - 2).Take (5).ToList ());
Assert.Equal (new List<string> {
"MockCustomStep5",
"MockCustomStep6"
}, actualSteps.TakeLast (2).ToList ());
var actualMarkHandlers = driver.Context.Pipeline.MarkHandlers.Select (h => h.GetType ().Name).ToList ();
Assert.Equal (new List<string> {
"MockMarkHandler2",
"MockMarkHandler3",
"MockMarkHandler",
"MockMarkHandler4"
}, actualMarkHandlers.TakeLast (4).ToList ());
}
}

[Fact]
public void TestCustomStepsMissingType ()
{
Expand Down
21 changes: 21 additions & 0 deletions test/ILLink.Tasks.Tests/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,25 @@ public class MockCustomStep : IStep
public void Process (LinkContext context) { }
}

public class MockCustomStep2 : MockCustomStep { }

public class MockCustomStep3 : MockCustomStep { }

public class MockCustomStep4 : MockCustomStep { }

public class MockCustomStep5 : MockCustomStep { }

public class MockCustomStep6 : MockCustomStep { }

public class MockMarkHandler : IMarkHandler
{
public void Initialize (LinkContext context, MarkContext markContext) { }
}

public class MockMarkHandler2 : MockMarkHandler { }

public class MockMarkHandler3 : MockMarkHandler { }

public class MockMarkHandler4 : MockMarkHandler { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Mono.Linker.Tests.Cases.Extensibility
{
[SetupCompileBefore ("SharedCustomSteps.dll", new[] { "Dependencies/CustomStepsWithSharedState.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })]
[SetupLinkerArgument ("--custom-step", "SharedStateHandler2,SharedCustomSteps.dll")]
[SetupLinkerArgument ("--custom-step", "SharedStateHandler1,SharedCustomSteps.dll")]
[SetupLinkerArgument ("--custom-step", "SharedStateHandler2,SharedCustomSteps.dll")]
public class CustomStepsCanShareState
{
public static void Main ()
Expand Down

0 comments on commit 21df7db

Please sign in to comment.