Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of custom steps #2082

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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