2 using System.Collections;
3 using System.Collections.Generic;
8 using Mono.Linker.Steps;
13 namespace Mono.Tuner {
15 public class CustomizeActions : BaseStep {
17 readonly bool link_sdk_only;
18 readonly HashSet<string> skipped_assemblies;
20 public CustomizeActions (bool link_sdk_only, IEnumerable<string> skipped_assemblies)
22 this.link_sdk_only = link_sdk_only;
23 this.skipped_assemblies = new HashSet<string> (skipped_assemblies);
26 protected override void ProcessAssembly (AssemblyDefinition assembly)
28 if (!IsSkipped (assembly) && IsLinked (assembly)) {
29 if (!Annotations.HasAction (assembly)) // stray assembly not picked up when resolving references
30 Annotations.SetAction (assembly, AssemblyAction.Link);
33 ProcessUserAssembly (assembly);
36 protected virtual bool IsPreservedAttribute (CustomAttribute attribute)
38 // [assembly: Preserve (type)] does not preserve all the code in the assembly, in fact it might
39 // not preserve anything in _this_ assembly, but something in a separate assembly (reference)
40 if (attribute.HasConstructorArguments)
42 return (attribute.AttributeType.Name == "PreserveAttribute");
45 protected virtual bool IsLinkerSafeAttribute (CustomAttribute attribute)
47 return (attribute.AttributeType.Name == "LinkerSafeAttribute");
50 const ModuleAttributes Supported = ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit |
51 ModuleAttributes.Preferred32Bit | ModuleAttributes.StrongNameSigned;
53 protected virtual bool IsSkipped (AssemblyDefinition assembly)
55 // Cecil can't save back mixed-mode assemblies - so we can't link them
56 if ((assembly.MainModule.Attributes & ~Supported) != 0)
59 if (assembly.HasCustomAttributes) {
60 foreach (var ca in assembly.CustomAttributes) {
61 if (IsPreservedAttribute (ca))
65 return skipped_assemblies.Contains (assembly.Name.Name);
68 protected virtual bool IsLinked (AssemblyDefinition assembly)
73 // Link SDK : applies to BCL/SDK and product assembly (e.g. monotouch.dll)
74 if (Profile.IsSdkAssembly (assembly))
76 if (Profile.IsProductAssembly (assembly))
78 // the assembly can be marked with [LinkAssembly]
79 if (assembly.HasCustomAttributes) {
80 foreach (var ca in assembly.CustomAttributes) {
81 if (IsLinkerSafeAttribute (ca))
88 protected void ProcessUserAssembly (AssemblyDefinition assembly)
90 ResolveFromAssemblyStep.ProcessLibrary (Context, assembly);