Browse Source

[linker] Add AssemblyAction.Save to enable the linker to re-write an assembly without actually linking it. Useful to remove references to PCL assemblies that are not really used (e.g. when only type forwarders are needed) [#13488]

Sebastien Pouliot 12 years ago
parent
commit
2ab52ceae2

+ 1 - 0
mcs/tools/linker/Mono.Linker.Steps/OutputStep.cs

@@ -61,6 +61,7 @@ namespace Mono.Linker.Steps {
 			CopyConfigFileIfNeeded (assembly, directory);
 
 			switch (Annotations.GetAction (assembly)) {
+			case AssemblyAction.Save:
 			case AssemblyAction.Link:
 				assembly.Write (GetAssemblyFileName (assembly, directory), SaveSymbols (assembly));
 				break;

+ 7 - 0
mcs/tools/linker/Mono.Linker.Steps/SweepStep.cs

@@ -100,6 +100,13 @@ namespace Mono.Linker.Steps {
 					continue;
 
 				references.RemoveAt (i);
+				// Removing the reference does not mean it will be saved back to disk!
+				// That depends on the AssemblyAction set for the `assembly`
+				if (Annotations.GetAction (assembly) == AssemblyAction.Copy) {
+					// Copy means even if "unlinked" we still want that assembly to be saved back 
+					// to disk (OutputStep) without the (removed) reference
+					Annotations.SetAction (assembly, AssemblyAction.Save);
+				}
 				return;
 			}
 		}

+ 9 - 0
mcs/tools/linker/Mono.Linker/AssemblyAction.cs

@@ -29,9 +29,18 @@
 namespace Mono.Linker {
 
 	public enum AssemblyAction {
+		// Ignore the assembly
 		Skip,
+		// Copy the existing files, assembly and symbols, into the output destination. E.g. .dll and .mdb
+		// The linker still analyze the assemblies (to know what they require) but does not modify them
 		Copy,
+		// Link the assembly
 		Link,
+		// Remove the assembly from the output
 		Delete,
+		// Save the assembly/symbols in memory without linking it. 
+		// E.g. useful to remove unneeded assembly references (as done in SweepStep), 
+		//  resolving [TypeForwardedTo] attributes (like PCL) to their final location
+		Save
 	}
 }