Skip to content
Prev Previous commit
Next Next commit
Auto-format source code
  • Loading branch information
GitHub Actions Autoformatter committed Mar 13, 2025
commit c2a2f31fe1ee72a7b059bd69cfd8e891a2e0edf4
12 changes: 6 additions & 6 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

namespace Xamarin.MacDev.Tasks {
public class PrepareAssemblies : XamarinTask {
#region Inputs
#region Inputs
[Required]
public ITaskItem[] InputAssemblies { get; set; } = [];
public ITaskItem [] InputAssemblies { get; set; } = [];

public string OutputDirectory { get; set; } = "";
#endregion
#endregion

#region Outputs
#region Outputs
[Output]
public ITaskItem[] OutputAssemblies { get; set; } = [];
#endregion
public ITaskItem [] OutputAssemblies { get; set; } = [];
#endregion

Dictionary<AssemblyPreparerInfo, ITaskItem> map = new ();

Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-preparer/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

global using Xamarin;
global using Xamarin.Tests;
global using Xamarin.Utils;
global using Xamarin.Utils;
73 changes: 36 additions & 37 deletions tests/assembly-preparer/PreserveBlockCodeHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Mono.Cecil.Rocks;
using Mono.Cecil.Rocks;

namespace AssemblyPreparerTests;

public class PreserveBlockCodeHandlerTests
{
[Test]
[TestCase (ApplePlatform.MacCatalyst)]
public void First (ApplePlatform platform)
{
var code = @"
public class PreserveBlockCodeHandlerTests {
[Test]
[TestCase (ApplePlatform.MacCatalyst)]
public void First (ApplePlatform platform)
{
var code = @"
using System;
using ObjCRuntime;
namespace ObjCRuntime;
Expand All @@ -25,8 +24,8 @@ static internal void Invoke (IntPtr block, int magic_number)
public delegate void DInnerBlock (IntPtr block, int magic_number);
}
}";
var csproj = $@"

var csproj = $@"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-{platform.AsString ().ToLower ()}</TargetFramework>
Expand All @@ -36,32 +35,32 @@ static internal void Invoke (IntPtr block, int magic_number)
</Project>
";

var tmpdir = Cache.CreateTemporaryDirectory ();
File.WriteAllText (Path.Combine (tmpdir, "Test.cs"), code);
var csprojPath = Path.Combine (tmpdir, "Test.csproj");
File.WriteAllText (csprojPath, csproj);
DotNet.AssertBuild (csprojPath);
var assemblyDir = Path.Combine (tmpdir, "bin", "Debug");
var assemblies = new List<string> ();
assemblies.Add (Path.Combine (assemblyDir, "Test.dll"));
assemblies.Add (Path.Combine (Configuration.DotNetBclDir, "System.Runtime.dll"));
var infos = assemblies.Select (v => new AssemblyPreparerInfo (v, Path.Combine (assemblyDir, "out", Path.GetFileName (v)))).ToArray ();
var preparer = new AssemblyPreparer (infos, platform);
Assert.That (preparer.Prepare (out var exceptions), Is.True, "Prepare");
Assert.That (exceptions, Is.Empty, "Exceptions");
var tmpdir = Cache.CreateTemporaryDirectory ();
File.WriteAllText (Path.Combine (tmpdir, "Test.cs"), code);
var csprojPath = Path.Combine (tmpdir, "Test.csproj");
File.WriteAllText (csprojPath, csproj);
DotNet.AssertBuild (csprojPath);
var assemblyDir = Path.Combine (tmpdir, "bin", "Debug");

var assemblies = new List<string> ();
assemblies.Add (Path.Combine (assemblyDir, "Test.dll"));
assemblies.Add (Path.Combine (Configuration.DotNetBclDir, "System.Runtime.dll"));
var infos = assemblies.Select (v => new AssemblyPreparerInfo (v, Path.Combine (assemblyDir, "out", Path.GetFileName (v)))).ToArray ();
var preparer = new AssemblyPreparer (infos, platform);
Assert.That (preparer.Prepare (out var exceptions), Is.True, "Prepare");
Assert.That (exceptions, Is.Empty, "Exceptions");

var outputPath = Path.Combine (assemblyDir, "out", "Test.dll");
var assemblyDefinition = AssemblyDefinition.ReadAssembly (outputPath);
var type = assemblyDefinition.MainModule.Types.Single (v => v.Name == "Trampolines").NestedTypes.Single (v => v.Name == "SDInnerBlock");
var cctor = type.GetStaticConstructor ();
var attribs = cctor.CustomAttributes?.OrderBy (v => string.Join (", ", v.ConstructorArguments.Select (v => v.Value?.ToString()))).ToArray ();
Assert.That (attribs, Is.Not.Null, "Attributes");
Assert.That (attribs.Count, Is.EqualTo (2), "Attribute count");
Assert.That (attribs.All (v => v.AttributeType.Name == "DynamicDependencyAttribute"), Is.True, "Attribute name");
Assert.That ((string) attribs[0].ConstructorArguments[0].Value, Is.EqualTo ("Handler"), "First attribute's first argument");
Assert.That ((string) attribs[1].ConstructorArguments[0].Value, Is.EqualTo ("Invoke(System.IntPtr,System.Int32)"), "Second attribute's first argument");
Assert.That (((TypeDefinition) attribs[0].ConstructorArguments[1].Value).FullName, Is.EqualTo ("ObjCRuntime.Trampolines/SDInnerBlock"), "First attribute's second argument");
Assert.That (((TypeDefinition) attribs[1].ConstructorArguments[1].Value).FullName, Is.EqualTo ("ObjCRuntime.Trampolines/SDInnerBlock"), "Second attribute's second argument");
}
var outputPath = Path.Combine (assemblyDir, "out", "Test.dll");
var assemblyDefinition = AssemblyDefinition.ReadAssembly (outputPath);
var type = assemblyDefinition.MainModule.Types.Single (v => v.Name == "Trampolines").NestedTypes.Single (v => v.Name == "SDInnerBlock");
var cctor = type.GetStaticConstructor ();
var attribs = cctor.CustomAttributes?.OrderBy (v => string.Join (", ", v.ConstructorArguments.Select (v => v.Value?.ToString ()))).ToArray ();
Assert.That (attribs, Is.Not.Null, "Attributes");
Assert.That (attribs.Count, Is.EqualTo (2), "Attribute count");
Assert.That (attribs.All (v => v.AttributeType.Name == "DynamicDependencyAttribute"), Is.True, "Attribute name");
Assert.That ((string) attribs [0].ConstructorArguments [0].Value, Is.EqualTo ("Handler"), "First attribute's first argument");
Assert.That ((string) attribs [1].ConstructorArguments [0].Value, Is.EqualTo ("Invoke(System.IntPtr,System.Int32)"), "Second attribute's first argument");
Assert.That (((TypeDefinition) attribs [0].ConstructorArguments [1].Value).FullName, Is.EqualTo ("ObjCRuntime.Trampolines/SDInnerBlock"), "First attribute's second argument");
Assert.That (((TypeDefinition) attribs [1].ConstructorArguments [1].Value).FullName, Is.EqualTo ("ObjCRuntime.Trampolines/SDInnerBlock"), "Second attribute's second argument");
}
}
8 changes: 4 additions & 4 deletions tools/assembly-preparer/AssemblyPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace Xamarin.Build;
public class AssemblyPreparer : IDisposable {
LinkerConfiguration configuration = new LinkerConfiguration ();

public AssemblyPreparerInfo[] Assemblies { get; set; }
public AssemblyPreparerInfo [] Assemblies { get; set; }

public AssemblyPreparer (AssemblyPreparerInfo[] assemblies, string platform)
public AssemblyPreparer (AssemblyPreparerInfo [] assemblies, string platform)
#if NET
: this (assemblies, Enum.Parse<ApplePlatform> (platform, true))
#else
Expand All @@ -24,14 +24,14 @@ public AssemblyPreparer (AssemblyPreparerInfo[] assemblies, string platform)
{
}

public AssemblyPreparer (AssemblyPreparerInfo[] assemblies, ApplePlatform platform)
public AssemblyPreparer (AssemblyPreparerInfo [] assemblies, ApplePlatform platform)
{
Assemblies = assemblies;
configuration.Platform = platform;
}

public bool Prepare (out List<Exception> exceptions)
{
{
exceptions = new List<Exception> ();

var markHandlers = new IMarkHandler [] {
Expand Down
4 changes: 2 additions & 2 deletions tools/assembly-preparer/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global using System;

namespace Xamarin.Tuner {}
namespace Mono.Linker.Steps {}
namespace Xamarin.Tuner { }
namespace Mono.Linker.Steps { }
37 changes: 18 additions & 19 deletions tools/assembly-preparer/Scaffolding/AnnotationStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

namespace Mono.Linker;

public class AnnotationStore
{
public AssemblyAction GetAction (AssemblyDefinition assembly)
{
throw new NotImplementedException ();
}
public void SetAction (AssemblyDefinition assembly, AssemblyAction action)
{
throw new NotImplementedException ();
}
public class AnnotationStore {
public AssemblyAction GetAction (AssemblyDefinition assembly)
{
throw new NotImplementedException ();
}
public void SetAction (AssemblyDefinition assembly, AssemblyAction action)
{
throw new NotImplementedException ();
}

public void Mark (TypeDefinition type)
{
throw new NotImplementedException ();
}
public void Mark (ExportedType type)
{
throw new NotImplementedException ();
}
}
public void Mark (TypeDefinition type)
{
throw new NotImplementedException ();
}
public void Mark (ExportedType type)
{
throw new NotImplementedException ();
}
}
14 changes: 7 additions & 7 deletions tools/assembly-preparer/Scaffolding/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Xamarin.Bundler;

public class Application {
public ApplePlatform Platform { get => throw new NotImplementedException (); }
public string ProductName => "assembly-preparer";
public void LoadSymbols ()
{
throw new NotImplementedException ();
}
}
public ApplePlatform Platform { get => throw new NotImplementedException (); }
public string ProductName => "assembly-preparer";
public void LoadSymbols ()
{
throw new NotImplementedException ();
}
}
9 changes: 4 additions & 5 deletions tools/assembly-preparer/Scaffolding/AssemblyAction.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Mono.Linker;

public enum AssemblyAction
{
Copy,
Link,
Save,
public enum AssemblyAction {
Copy,
Link,
Save,
}
8 changes: 4 additions & 4 deletions tools/assembly-preparer/Scaffolding/DerivedLinkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Xamarin.Tuner;
using Xamarin.Bundler;

public class DerivedLinkContext : LinkContext {
public DerivedLinkContext (LinkerConfiguration configuration) : base (configuration)
{
}
}
public DerivedLinkContext (LinkerConfiguration configuration) : base (configuration)
{
}
}
5 changes: 2 additions & 3 deletions tools/assembly-preparer/Scaffolding/Driver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Xamarin.Bundler;

public static class Driver
{
public const string CorlibName = "System.Private.CoreLib";
public static class Driver {
public const string CorlibName = "System.Private.CoreLib";
}
25 changes: 12 additions & 13 deletions tools/assembly-preparer/Scaffolding/IMarkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ namespace Mono.Linker;

using Mono.Cecil;

public interface IMarkHandler
{
void Initialize (LinkContext context, MarkContext markContext);
// void Initialize (LinkContext context, MarkContext markContext);
// void ProcessAssembly (AssemblyDefinition assembly);
// void ProcessType (TypeDefinition type);
// void ProcessField (FieldDefinition field);
// void ProcessMethod (MethodDefinition method);
// void ProcessParameter (ParameterDefinition parameter);
// void ProcessProperty (PropertyDefinition property);
// void ProcessEvent (EventDefinition eventDef);

}
public interface IMarkHandler {
void Initialize (LinkContext context, MarkContext markContext);
// void Initialize (LinkContext context, MarkContext markContext);
// void ProcessAssembly (AssemblyDefinition assembly);
// void ProcessType (TypeDefinition type);
// void ProcessField (FieldDefinition field);
// void ProcessMethod (MethodDefinition method);
// void ProcessParameter (ParameterDefinition parameter);
// void ProcessProperty (PropertyDefinition property);
// void ProcessEvent (EventDefinition eventDef);

}
18 changes: 9 additions & 9 deletions tools/assembly-preparer/Scaffolding/LinkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Mono.Linker;

public class LinkContext {
public AnnotationStore Annotations { get => throw new NotImplementedException (); }
public AnnotationStore Annotations { get => throw new NotImplementedException (); }

public List<AssemblyDefinition> Assemblies = new List<AssemblyDefinition> ();
public AssemblyDefinition[] GetAssemblies () { return Assemblies.ToArray (); }
public List<AssemblyDefinition> Assemblies = new List<AssemblyDefinition> ();
public AssemblyDefinition [] GetAssemblies () { return Assemblies.ToArray (); }

public LinkerConfiguration Configuration { get; private set; }
public LinkerConfiguration Configuration { get; private set; }

public LinkContext (LinkerConfiguration configuration)
{
Configuration = configuration;
}
}
public LinkContext (LinkerConfiguration configuration)
{
Configuration = configuration;
}
}
5 changes: 3 additions & 2 deletions tools/assembly-preparer/Scaffolding/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public DerivedLinkContext DerivedLinkContext {
}
public DerivedLinkContext Context { get => DerivedLinkContext; }
public Profile Profile { get => throw new NotImplementedException (); }
public AssemblyDefinition[] Assemblies { get => Context.GetAssemblies (); }
public AssemblyDefinition [] Assemblies { get => Context.GetAssemblies (); }

public ApplePlatform Platform { get; set; }
public string PlatformAssembly { get {
public string PlatformAssembly {
get {
return $"Microsoft.{Platform.AsString ()}";
}
}
Expand Down
52 changes: 26 additions & 26 deletions tools/assembly-preparer/Scaffolding/MarkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ namespace Mono.Linker;
using Mono.Cecil;

public class MarkContext {
List<Action<TypeDefinition>> markTypeActions = new List<Action<TypeDefinition>> ();
List<Action<TypeDefinition>> markTypeActions = new List<Action<TypeDefinition>> ();

// takes care of nested types as well
public void MarkType (TypeDefinition type)
{
foreach (var action in markTypeActions) {
action (type);
}
// takes care of nested types as well
public void MarkType (TypeDefinition type)
{
foreach (var action in markTypeActions) {
action (type);
}

if (type.HasNestedTypes) {
foreach (var nested in type.NestedTypes) {
MarkType (nested);
}
}
}
if (type.HasNestedTypes) {
foreach (var nested in type.NestedTypes) {
MarkType (nested);
}
}
}

public void RegisterMarkAssemblyAction (Action<AssemblyDefinition> action)
{
throw new NotImplementedException ();
}
public void RegisterMarkAssemblyAction (Action<AssemblyDefinition> action)
{
throw new NotImplementedException ();
}

public void RegisterMarkTypeAction (Action<TypeDefinition> action)
{
markTypeActions.Add (action);
}
public void RegisterMarkTypeAction (Action<TypeDefinition> action)
{
markTypeActions.Add (action);
}

public void RegisterMarkMethodAction (Action<MethodDefinition> action)
{
throw new NotImplementedException ();
}
}
public void RegisterMarkMethodAction (Action<MethodDefinition> action)
{
throw new NotImplementedException ();
}
}
4 changes: 2 additions & 2 deletions tools/assembly-preparer/Scaffolding/Profile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mono.Linker;

public class Profile {
}

}
Loading