[io-layer] add URLs for some ximian bug numbers in sockets.cs
[mono.git] / mcs / tools / tuner / Mono.Tuner / CustomizeActions.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.IO;
5 using System.Linq;
6
7 using Mono.Linker;
8 using Mono.Linker.Steps;
9
10 using Mono.Cecil;
11 using Mono.Cecil.Cil;
12
13 namespace Mono.Tuner {
14
15         public class CustomizeActions : BaseStep {
16
17                 readonly bool link_sdk_only;
18                 readonly HashSet<string> skipped_assemblies;
19
20                 public CustomizeActions (bool link_sdk_only, IEnumerable<string> skipped_assemblies)
21                 {
22                         this.link_sdk_only = link_sdk_only;
23                         this.skipped_assemblies = new HashSet<string> (skipped_assemblies);
24                 }
25
26                 protected override void ProcessAssembly (AssemblyDefinition assembly)
27                 {
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);
31                                 return;
32                         }
33                         ProcessUserAssembly (assembly);
34                 }
35
36                 protected virtual bool IsPreservedAttribute (CustomAttribute attribute)
37                 {
38                         return (attribute.AttributeType.Name == "PreserveAttribute");
39                 }
40
41                 protected virtual bool IsLinkerSafeAttribute (CustomAttribute attribute)
42                 {
43                         return (attribute.AttributeType.Name == "LinkerSafeAttribute");
44                 }
45
46                 protected virtual bool IsSkipped (AssemblyDefinition assembly)
47                 {
48                         if (assembly.HasCustomAttributes) {
49                                 foreach (var ca in assembly.CustomAttributes) {
50                                         if (IsPreservedAttribute (ca))
51                                                 return true;
52                                 }
53                         }
54                         return skipped_assemblies.Contains (assembly.Name.Name);
55                 }
56
57                 protected virtual bool IsLinked (AssemblyDefinition assembly)
58                 {
59                         // LinkAll
60                         if (!link_sdk_only)
61                                 return true;
62                         // Link SDK : applies to BCL/SDK and product assembly (e.g. monotouch.dll)
63                         if (Profile.IsSdkAssembly (assembly))
64                                 return true;
65                         if (Profile.IsProductAssembly (assembly))
66                             return true;
67                         // the assembly can be marked with [LinkAssembly]
68                         if (assembly.HasCustomAttributes) {
69                                 foreach (var ca in assembly.CustomAttributes) {
70                                         if (IsLinkerSafeAttribute (ca))
71                                                 return true;
72                                 }
73                         }
74                         return false;
75                 }
76
77                 protected void ProcessUserAssembly (AssemblyDefinition assembly)
78                 {
79                         ResolveFromAssemblyStep.ProcessLibrary (Context, assembly);
80                 }
81         }
82 }