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

[illink] refactor code sharing between ILLink and MSBuild tasks #9688

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ProjectReference Include="..\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj" ReferenceOutputAssembly="False" />

<!--Include shared linker sources-->
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\External\Linker\BaseMarkHandler.cs" Link="External\BaseMarkHandler.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\AddKeepAlivesStep.cs" Link="MonoDroid.Tuner\AddKeepAlivesStep.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\AndroidLinkConfiguration.cs" Link="MonoDroid.Tuner\AndroidLinkConfiguration.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\Extensions.cs" Link="MonoDroid.Tuner\Extensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Tracer Tracer {
get { return _context.Tracer; }
}

public MarkingHelpers MarkingHelpers => _context.MarkingHelpers;
public void Initialize (LinkContext context) => _context = context;

public void Process (LinkContext context)
{
Expand Down Expand Up @@ -79,5 +79,19 @@ protected virtual void EndProcess ()
protected virtual void ProcessAssembly (AssemblyDefinition assembly)
{
}

public virtual void LogMessage (string message)
{
Context.LogMessage (message);
}

public virtual void LogError (int code, string message)
{
#if ILLINK
Context.LogMessage (MessageContainer.CreateCustomErrorMessage (message, code, origin: new MessageOrigin ()));
#else // !ILLINK
Context.LogError ($"XA{code}", message);
#endif // !ILLINK
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Steps
{

/// <summary>
/// This API supports the product infrastructure and is not intended to be used directly from your code.
/// Extensibility point for custom logic that run during MarkStep, for marked members.
/// </summary>
public interface IMarkHandler
{
/// <summary>
/// Initialize is called at the beginning of MarkStep. This should be
/// used to perform global setup, and register callbacks through the
/// MarkContext.Register* methods) to be called when pieces of IL are marked.
/// </summary>
void Initialize (LinkContext context, MarkContext markContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Mono.Cecil;

namespace Mono.Linker.Steps
{
/// <summary>
/// Context which can be used to register actions to call during MarkStep
/// when various members are marked.
/// </summary>
public abstract class MarkContext
{
/// <summary>
/// Register a callback that will be invoked once for each marked assembly.
/// </summary>
public abstract void RegisterMarkAssemblyAction (Action<AssemblyDefinition> action);

/// <summary>
/// Register a callback that will be invoked once for each marked type.
/// </summary>
public abstract void RegisterMarkTypeAction (Action<TypeDefinition> action);

/// <summary>
/// Register a callback that will be invoked once for each marked method.
/// </summary>
public abstract void RegisterMarkMethodAction (Action<MethodDefinition> action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public partial class AnnotationStore {
protected readonly HashSet<CustomAttribute> marked_attributes = new HashSet<CustomAttribute> ();
readonly HashSet<TypeDefinition> marked_types_with_cctor = new HashSet<TypeDefinition> ();
protected readonly HashSet<TypeDefinition> marked_instantiated = new HashSet<TypeDefinition> ();
protected readonly HashSet<MethodDefinition> indirectly_called = new HashSet<MethodDefinition>();


public AnnotationStore (LinkContext context) => this.context = context;
Expand Down Expand Up @@ -167,24 +166,6 @@ public bool IsMarked (CustomAttribute attribute)
return marked_attributes.Contains (attribute);
}

public void MarkIndirectlyCalledMethod (MethodDefinition method)
{
if (!context.AddReflectionAnnotations)
return;

indirectly_called.Add (method);
}

public bool HasMarkedAnyIndirectlyCalledMethods ()
{
return indirectly_called.Count != 0;
}

public bool IsIndirectlyCalled (MethodDefinition method)
{
return indirectly_called.Contains (method);
}

public void MarkInstantiated (TypeDefinition type)
{
marked_instantiated.Add (type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Android.Sdk.ILLink;
using Mono.Cecil;
using Mono.Linker.Steps;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading