You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.88
Former-commit-id: 4b7216ffda08448e562271ce733688e761120fc5
This commit is contained in:
parent
7d05485754
commit
6123a772ed
2
external/linker/corebuild/.cliversion
vendored
2
external/linker/corebuild/.cliversion
vendored
@@ -1 +1 @@
|
||||
2.0.0-preview2-005905
|
||||
2.0.0
|
||||
|
||||
1
external/linker/corebuild/.toolversions
vendored
1
external/linker/corebuild/.toolversions
vendored
@@ -1 +0,0 @@
|
||||
|
||||
2
external/linker/corebuild/bootstrap.ps1
vendored
2
external/linker/corebuild/bootstrap.ps1
vendored
@@ -6,7 +6,7 @@ param
|
||||
[Parameter(Mandatory=$false)][string]$SharedFrameworkSymlinkPath = (Join-Path $ToolsLocalPath "dotnetcli\shared\Microsoft.NETCore.App\version"),
|
||||
[Parameter(Mandatory=$false)][string]$SharedFrameworkVersion = "<auto>",
|
||||
[Parameter(Mandatory=$false)][string]$Architecture = "<auto>",
|
||||
[Parameter(Mandatory=$false)][string]$DotNetInstallBranch = "rel/1.0.0",
|
||||
[Parameter(Mandatory=$false)][string]$DotNetInstallBranch = "release/2.0.0",
|
||||
[switch]$Force = $false
|
||||
)
|
||||
|
||||
|
||||
2
external/linker/corebuild/bootstrap.sh
vendored
2
external/linker/corebuild/bootstrap.sh
vendored
@@ -80,7 +80,7 @@ sharedFxVersion="<auto>"
|
||||
force=
|
||||
forcedCliLocalPath="<none>"
|
||||
architecture="<auto>"
|
||||
dotNetInstallBranch="rel/1.0.0"
|
||||
dotNetInstallBranch="release/2.0.0"
|
||||
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
|
||||
5
external/linker/corebuild/global.json
vendored
Normal file
5
external/linker/corebuild/global.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
|
||||
<DefineConstants>$(DefineConstants);FEATURE_ILLINK</DefineConstants>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<VersionPrefix>0.1.4-preview</VersionPrefix>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<BaseOutputPath>../bin/</BaseOutputPath>
|
||||
<PackageOutputPath>$(BaseOutputPath)nupkgs</PackageOutputPath>
|
||||
|
||||
@@ -29,10 +29,11 @@ namespace ILLink.Tests
|
||||
|
||||
protected int Dotnet(string args, string workingDir, string additionalPath = null)
|
||||
{
|
||||
return RunCommand(context.DotnetToolPath, args, workingDir, additionalPath, out string commandOutput);
|
||||
return RunCommand(Path.GetFullPath(context.DotnetToolPath), args,
|
||||
workingDir, additionalPath, out string commandOutput);
|
||||
}
|
||||
|
||||
protected int RunCommand(string command, string args, int timeout = 60000)
|
||||
protected int RunCommand(string command, string args, int timeout = Int32.MaxValue)
|
||||
{
|
||||
return RunCommand(command, args, null, null, out string commandOutput, timeout);
|
||||
}
|
||||
@@ -42,7 +43,7 @@ namespace ILLink.Tests
|
||||
return RunCommand(command, args, workingDir, null, out string commandOutput);
|
||||
}
|
||||
|
||||
protected int RunCommand(string command, string args, string workingDir, string additionalPath, out string commandOutput, int timeout = 60000)
|
||||
protected int RunCommand(string command, string args, string workingDir, string additionalPath, out string commandOutput, int timeout = Int32.MaxValue)
|
||||
{
|
||||
output.WriteLine($"{command} {args}");
|
||||
if (workingDir != null)
|
||||
@@ -64,6 +65,14 @@ namespace ILLink.Tests
|
||||
var process = new Process();
|
||||
process.StartInfo = psi;
|
||||
|
||||
// dotnet sets some environment variables that
|
||||
// may cause problems in the child process.
|
||||
psi.Environment.Remove("MSBuildExtensionsPath");
|
||||
psi.Environment.Remove("MSBuildLoadMicrosoftTargetsReadOnly");
|
||||
psi.Environment.Remove("MSBuildSDKsPath");
|
||||
psi.Environment.Remove("VbcToolExe");
|
||||
psi.Environment.Remove("CscToolExe");
|
||||
|
||||
StringBuilder processOutput = new StringBuilder();
|
||||
DataReceivedEventHandler handler = (sender, e) => {
|
||||
processOutput.Append(e.Data);
|
||||
@@ -80,6 +89,7 @@ namespace ILLink.Tests
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
if (!process.WaitForExit(timeout)) {
|
||||
output.WriteLine($"killing process after {timeout} ms");
|
||||
process.Kill();
|
||||
}
|
||||
// WaitForExit with timeout doesn't guarantee
|
||||
@@ -101,26 +111,25 @@ namespace ILLink.Tests
|
||||
/// linker task package.
|
||||
/// Optionally takes a list of root descriptor files.
|
||||
/// </summary>
|
||||
public void BuildAndLink(string csproj, List<string> rootFiles = null)
|
||||
public void BuildAndLink(string csproj, List<string> rootFiles = null, Dictionary<string, string> extraPublishArgs = null)
|
||||
{
|
||||
string rid = context.RuntimeIdentifier;
|
||||
string config = context.Configuration;
|
||||
string demoRoot = Path.GetDirectoryName(csproj);
|
||||
|
||||
int ret = Dotnet($"restore -r {rid}", demoRoot);
|
||||
if (ret != 0) {
|
||||
output.WriteLine("restore failed");
|
||||
Assert.True(false);
|
||||
return;
|
||||
}
|
||||
|
||||
string publishArgs = $"publish -r {rid} -c {config} /v:n /p:ShowLinkerSizeComparison=true";
|
||||
string rootFilesStr;
|
||||
if (rootFiles != null && rootFiles.Any()) {
|
||||
rootFilesStr = String.Join(";", rootFiles);
|
||||
publishArgs += $" /p:LinkerRootDescriptors={rootFilesStr}";
|
||||
}
|
||||
ret = Dotnet(publishArgs, demoRoot);
|
||||
if (extraPublishArgs != null) {
|
||||
foreach (var item in extraPublishArgs) {
|
||||
publishArgs += $" /p:{item.Key}={item.Value}";
|
||||
}
|
||||
}
|
||||
int ret = Dotnet(publishArgs, demoRoot);
|
||||
|
||||
if (ret != 0) {
|
||||
output.WriteLine("publish failed, returning " + ret);
|
||||
Assert.True(false);
|
||||
@@ -128,11 +137,13 @@ namespace ILLink.Tests
|
||||
}
|
||||
}
|
||||
|
||||
public int RunApp(string csproj, out string processOutput, int timeout = 60000)
|
||||
public int RunApp(string csproj, out string processOutput, int timeout = Int32.MaxValue)
|
||||
{
|
||||
string demoRoot = Path.GetDirectoryName(csproj);
|
||||
string executablePath = Path.Combine(
|
||||
demoRoot, "bin", context.Configuration, "netcoreapp2.0",
|
||||
// detect the target framework for which the app was published
|
||||
string tfmDir = Path.Combine(demoRoot, "bin", context.Configuration);
|
||||
string tfm = Directory.GetDirectories(tfmDir).Select(p => Path.GetFileName(p)).Single();
|
||||
string executablePath = Path.Combine(tfmDir, tfm,
|
||||
context.RuntimeIdentifier, "publish",
|
||||
Path.GetFileNameWithoutExtension(csproj)
|
||||
);
|
||||
@@ -141,17 +152,9 @@ namespace ILLink.Tests
|
||||
}
|
||||
Assert.True(File.Exists(executablePath));
|
||||
|
||||
// work around bug in prerelease .NET Core,
|
||||
// where the published host isn't executable
|
||||
int ret;
|
||||
if (!context.RuntimeIdentifier.Contains("win")) {
|
||||
ret = RunCommand("chmod", "+x " + executablePath, 1000);
|
||||
Assert.True(ret == 0);
|
||||
}
|
||||
|
||||
ret = RunCommand(executablePath, null,
|
||||
Directory.GetParent(executablePath).FullName,
|
||||
null, out processOutput, timeout);
|
||||
int ret = RunCommand(executablePath, null,
|
||||
Directory.GetParent(executablePath).FullName,
|
||||
null, out processOutput, timeout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace ILLink.Tests
|
||||
|
||||
private static List<string> rootFiles = new List<string> { "MusicStoreReflection.xml" };
|
||||
|
||||
private string netcoreappVersion;
|
||||
|
||||
[Fact]
|
||||
public void RunMusicStore()
|
||||
{
|
||||
@@ -32,10 +34,70 @@ namespace ILLink.Tests
|
||||
|
||||
AddLinkerReference(csproj);
|
||||
|
||||
BuildAndLink(csproj, rootFiles);
|
||||
Dictionary<string, string> extraPublishArgs = new Dictionary<string, string>();
|
||||
extraPublishArgs.Add("JITBENCH_FRAMEWORK_VERSION", netcoreappVersion);
|
||||
BuildAndLink(csproj, rootFiles, extraPublishArgs);
|
||||
}
|
||||
|
||||
int ret = RunApp(csproj, out string commandOutput);
|
||||
Assert.True(ret == 0);
|
||||
string ObtainSDK(string repoDir)
|
||||
{
|
||||
int ret;
|
||||
string dotnetDirName = ".dotnet";
|
||||
string dotnetInstall = Path.Combine(repoDir, "dotnet-install");
|
||||
if (context.RuntimeIdentifier.Contains("win")) {
|
||||
dotnetInstall += ".ps1";
|
||||
} else {
|
||||
dotnetInstall += ".sh";
|
||||
}
|
||||
if (!File.Exists(dotnetInstall)) {
|
||||
output.WriteLine($"missing dotnet-install script at {dotnetInstall}");
|
||||
Assert.True(false);
|
||||
}
|
||||
|
||||
if (context.RuntimeIdentifier.Contains("win")) {
|
||||
ret = RunCommand(dotnetInstall, $"-SharedRuntime -InstallDir {dotnetDirName} -Channel master -Architecture x64", repoDir);
|
||||
if (ret != 0) {
|
||||
output.WriteLine("failed to retrieve shared runtime");
|
||||
Assert.True(false);
|
||||
}
|
||||
ret = RunCommand(dotnetInstall, $"-InstallDir {dotnetDirName} -Channel master -Architecture x64", repoDir);
|
||||
if (ret != 0) {
|
||||
output.WriteLine("failed to retrieve sdk");
|
||||
Assert.True(false);
|
||||
}
|
||||
} else {
|
||||
ret = RunCommand(dotnetInstall, $"-sharedruntime -runtimeid {context.RuntimeIdentifier} -installdir {dotnetDirName} -channel master -architecture x64", repoDir);
|
||||
if (ret != 0) {
|
||||
output.WriteLine("failed to retrieve shared runtime");
|
||||
Assert.True(false);
|
||||
}
|
||||
ret = RunCommand(dotnetInstall, $"-installdir {dotnetDirName} -channel master -architecture x64", repoDir);
|
||||
if (ret != 0) {
|
||||
output.WriteLine("failed to retrieve sdk");
|
||||
Assert.True(false);
|
||||
}
|
||||
}
|
||||
|
||||
string dotnetDir = Path.Combine(repoDir, dotnetDirName);
|
||||
string dotnetToolName = Directory.GetFiles(dotnetDir)
|
||||
.Select(p => Path.GetFileName(p))
|
||||
.Where(p => p.Contains("dotnet"))
|
||||
.Single();
|
||||
string dotnetToolPath = Path.Combine(dotnetDir, dotnetToolName);
|
||||
if (!File.Exists(dotnetToolPath)) {
|
||||
output.WriteLine("repo-local dotnet tool does not exist.");
|
||||
Assert.True(false);
|
||||
}
|
||||
|
||||
string ncaDir = Path.Combine(dotnetDir, "shared", "Microsoft.NETCore.App");
|
||||
netcoreappVersion = Directory.GetDirectories(ncaDir)
|
||||
.Select(p => Path.GetFileName(p)).Max();
|
||||
if (String.IsNullOrEmpty(netcoreappVersion)) {
|
||||
output.WriteLine($"no netcoreapp version found in {ncaDir}");
|
||||
Assert.True(false);
|
||||
}
|
||||
|
||||
return dotnetToolPath;
|
||||
}
|
||||
|
||||
// returns path to .csproj project file
|
||||
@@ -44,7 +106,6 @@ namespace ILLink.Tests
|
||||
string gitRepo = "http://github.com/aspnet/JitBench";
|
||||
string repoName = "JitBench";
|
||||
string gitBranch = "dev";
|
||||
string demoRoot = Path.Combine("JitBench", Path.Combine("src", "MusicStore"));
|
||||
|
||||
int ret;
|
||||
if (Directory.Exists(repoName)) {
|
||||
@@ -57,6 +118,7 @@ namespace ILLink.Tests
|
||||
Assert.True(false);
|
||||
}
|
||||
|
||||
string demoRoot = Path.Combine("JitBench", Path.Combine("src", "MusicStore"));
|
||||
if (!Directory.Exists(demoRoot)) {
|
||||
output.WriteLine($"{demoRoot} does not exist");
|
||||
Assert.True(false);
|
||||
@@ -68,6 +130,11 @@ namespace ILLink.Tests
|
||||
Assert.True(false);
|
||||
}
|
||||
|
||||
// MusicStore targets .NET Core 2.1, so it must be built
|
||||
// using an SDK that can target 2.1. We obtain that SDK
|
||||
// here.
|
||||
context.DotnetToolPath = ObtainSDK(repoName);
|
||||
|
||||
string csproj = Path.Combine(demoRoot, "MusicStore.csproj");
|
||||
return csproj;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ILLink.Tests
|
||||
/// The path to the dotnet tool to use to run the
|
||||
/// integration tests.
|
||||
/// </summary>
|
||||
public string DotnetToolPath { get; private set; }
|
||||
public string DotnetToolPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The RID to use when restoring, building, and linking the
|
||||
@@ -87,6 +87,12 @@ namespace ILLink.Tests
|
||||
context.DotnetToolPath = dotnetToolPath;
|
||||
// This sets the RID to the RID of the currently-executing system.
|
||||
context.RuntimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
|
||||
// workaround: the osx.10.13-x64 RID doesn't exist yet.
|
||||
// see https://github.com/dotnet/core-setup/issues/3301
|
||||
if (context.RuntimeIdentifier == "osx.10.13-x64")
|
||||
{
|
||||
context.RuntimeIdentifier = "osx.10.12-x64";
|
||||
}
|
||||
// We want to build and link integration projects in the
|
||||
// release configuration.
|
||||
context.Configuration = "Release";
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
|
||||
<PackageReference Include="xunit" Version="2.3.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -96,9 +96,9 @@ namespace Mono.Linker.Steps {
|
||||
return false;
|
||||
}
|
||||
|
||||
static ResolveFromXmlStep GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)
|
||||
protected virtual IStep GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)
|
||||
{
|
||||
return new ResolveFromXmlStep (GetExternalDescriptor (resource), "resource " + resource.Name + " in " + assembly.FullName);
|
||||
return new ResolveFromXmlStep (GetExternalDescriptor (resource), resource.Name, assembly, "resource " + resource.Name + " in " + assembly.FullName);
|
||||
}
|
||||
|
||||
static ResolveFromXmlStep GetResolveStep (string descriptor)
|
||||
@@ -106,7 +106,7 @@ namespace Mono.Linker.Steps {
|
||||
return new ResolveFromXmlStep (GetDescriptor (descriptor), "descriptor " + descriptor + " from " + Assembly.GetExecutingAssembly ().FullName);
|
||||
}
|
||||
|
||||
static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
|
||||
protected static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
|
||||
{
|
||||
using (var sr = new StreamReader (resource.GetResourceStream ())) {
|
||||
return new XPathDocument (new StringReader (sr.ReadToEnd ()));
|
||||
|
||||
@@ -647,8 +647,7 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
if (type.HasInterfaces) {
|
||||
foreach (var iface in type.Interfaces) {
|
||||
MarkCustomAttributes (iface);
|
||||
MarkType (iface.InterfaceType);
|
||||
MarkInterfaceImplementation (type, iface);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1444,7 +1443,14 @@ namespace Mono.Linker.Steps {
|
||||
return true;
|
||||
case MethodAction.Parse:
|
||||
AssemblyDefinition assembly = ResolveAssembly (method.DeclaringType.Scope);
|
||||
return Annotations.GetAction (assembly) == AssemblyAction.Link;
|
||||
switch (Annotations.GetAction (assembly)) {
|
||||
case AssemblyAction.Link:
|
||||
case AssemblyAction.Copy:
|
||||
case AssemblyAction.CopyUsed:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1550,12 +1556,22 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
protected virtual void HandleUnresolvedType (TypeReference reference)
|
||||
{
|
||||
throw new ResolutionException (reference);
|
||||
if (!_context.IgnoreUnresolved) {
|
||||
throw new ResolutionException (reference);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleUnresolvedMethod (MethodReference reference)
|
||||
{
|
||||
throw new ResolutionException (reference);
|
||||
if (!_context.IgnoreUnresolved) {
|
||||
throw new ResolutionException (reference);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void MarkInterfaceImplementation (TypeDefinition type, InterfaceImplementation iface)
|
||||
{
|
||||
MarkCustomAttributes (iface);
|
||||
MarkType (iface.InterfaceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
XPathDocument _document;
|
||||
string _xmlDocumentLocation;
|
||||
string _resourceName;
|
||||
AssemblyDefinition _resourceAssembly;
|
||||
|
||||
public ResolveFromXmlStep (XPathDocument document, string xmlDocumentLocation = "<unspecified>")
|
||||
{
|
||||
@@ -66,18 +68,33 @@ namespace Mono.Linker.Steps {
|
||||
_xmlDocumentLocation = xmlDocumentLocation;
|
||||
}
|
||||
|
||||
public ResolveFromXmlStep (XPathDocument document, string resourceName, AssemblyDefinition resourceAssembly, string xmlDocumentLocation = "<unspecified>")
|
||||
: this (document, xmlDocumentLocation)
|
||||
{
|
||||
if (string.IsNullOrEmpty (resourceName))
|
||||
throw new ArgumentNullException (nameof (resourceName));
|
||||
|
||||
if (resourceAssembly == null)
|
||||
throw new ArgumentNullException (nameof (resourceAssembly));
|
||||
|
||||
_resourceName = resourceName;
|
||||
_resourceAssembly = resourceAssembly;
|
||||
}
|
||||
|
||||
protected override void Process ()
|
||||
{
|
||||
XPathNavigator nav = _document.CreateNavigator ();
|
||||
nav.MoveToFirstChild ();
|
||||
|
||||
// This step can be created with XML files that aren't necessarily
|
||||
// linker descriptor files. So bail if we don't have a <linker> element.
|
||||
if (nav.LocalName != "linker")
|
||||
if (!nav.MoveToChild("linker", _ns))
|
||||
return;
|
||||
|
||||
try {
|
||||
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
|
||||
|
||||
if (!string.IsNullOrEmpty (_resourceName))
|
||||
Context.Annotations.AddResourceToRemove (_resourceAssembly, _resourceName);
|
||||
} catch (Exception ex) {
|
||||
throw new XmlResolutionException (string.Format ("Failed to process XML description: {0}", _xmlDocumentLocation), ex);
|
||||
}
|
||||
|
||||
@@ -75,11 +75,23 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
void SweepAssembly (AssemblyDefinition assembly)
|
||||
{
|
||||
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
|
||||
switch (Annotations.GetAction (assembly)) {
|
||||
case AssemblyAction.Link:
|
||||
if (!IsMarkedAssembly (assembly)) {
|
||||
RemoveAssembly (assembly);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case AssemblyAction.CopyUsed:
|
||||
if (!IsMarkedAssembly (assembly)) {
|
||||
RemoveAssembly (assembly);
|
||||
} else {
|
||||
Annotations.SetAction (assembly, AssemblyAction.Copy);
|
||||
}
|
||||
return;
|
||||
|
||||
if (!IsMarkedAssembly (assembly)) {
|
||||
RemoveAssembly (assembly);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,6 +113,8 @@ namespace Mono.Linker.Steps {
|
||||
assembly.MainModule.Types.Clear ();
|
||||
foreach (TypeDefinition type in types)
|
||||
assembly.MainModule.Types.Add (type);
|
||||
|
||||
SweepResources (assembly);
|
||||
}
|
||||
|
||||
bool IsMarkedAssembly (AssemblyDefinition assembly)
|
||||
@@ -115,6 +129,23 @@ namespace Mono.Linker.Steps {
|
||||
SweepReferences (assembly);
|
||||
}
|
||||
|
||||
void SweepResources (AssemblyDefinition assembly)
|
||||
{
|
||||
var resourcesToRemove = Annotations.GetResourcesToRemove (assembly);
|
||||
if (resourcesToRemove != null) {
|
||||
var resources = assembly.MainModule.Resources;
|
||||
|
||||
for (int i = 0; i < resources.Count; i++) {
|
||||
var resource = resources [i] as EmbeddedResource;
|
||||
if (resource == null)
|
||||
continue;
|
||||
|
||||
if (resourcesToRemove.Contains (resource.Name))
|
||||
resources.RemoveAt (i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SweepReferences (AssemblyDefinition target)
|
||||
{
|
||||
foreach (var assembly in assemblies)
|
||||
@@ -147,8 +178,8 @@ namespace Mono.Linker.Steps {
|
||||
case 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);
|
||||
if (!Context.KeepTypeForwarderOnlyAssemblies) {
|
||||
Annotations.SetAction (assembly, AssemblyAction.Save);
|
||||
ResolveAllTypeReferences (assembly);
|
||||
}
|
||||
break;
|
||||
@@ -224,6 +255,9 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
if (type.HasNestedTypes)
|
||||
SweepNestedTypes (type);
|
||||
|
||||
if (type.HasInterfaces)
|
||||
SweepInterfaces (type);
|
||||
}
|
||||
|
||||
protected void SweepNestedTypes (TypeDefinition type)
|
||||
@@ -239,6 +273,17 @@ namespace Mono.Linker.Steps {
|
||||
}
|
||||
}
|
||||
|
||||
protected void SweepInterfaces (TypeDefinition type)
|
||||
{
|
||||
for (int i = type.Interfaces.Count - 1; i >= 0; i--) {
|
||||
var iface = type.Interfaces [i];
|
||||
if (Annotations.IsMarked (iface.InterfaceType.Resolve ()))
|
||||
continue;
|
||||
InterfaceRemoved (type, iface);
|
||||
type.Interfaces.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
|
||||
void SweepMethods (Collection<MethodDefinition> methods)
|
||||
{
|
||||
SweepCollection (methods);
|
||||
@@ -321,5 +366,9 @@ namespace Mono.Linker.Steps {
|
||||
protected virtual void ReferenceRemoved (AssemblyDefinition assembly, AssemblyNameReference reference)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void InterfaceRemoved (TypeDefinition type, InterfaceImplementation iface)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace Mono.Linker {
|
||||
readonly Dictionary<AssemblyDefinition, ISymbolReader> symbol_readers = new Dictionary<AssemblyDefinition, ISymbolReader> ();
|
||||
|
||||
readonly Dictionary<object, Dictionary<IMetadataTokenProvider, object>> custom_annotations = new Dictionary<object, Dictionary<IMetadataTokenProvider, object>> ();
|
||||
readonly Dictionary<AssemblyDefinition, HashSet<string>> resources_to_remove = new Dictionary<AssemblyDefinition, HashSet<string>> ();
|
||||
|
||||
Stack<object> dependency_stack;
|
||||
System.Xml.XmlWriter writer;
|
||||
@@ -180,6 +181,25 @@ namespace Mono.Linker {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public HashSet<string> GetResourcesToRemove (AssemblyDefinition assembly)
|
||||
{
|
||||
HashSet<string> resources;
|
||||
if (resources_to_remove.TryGetValue (assembly, out resources))
|
||||
return resources;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddResourceToRemove (AssemblyDefinition assembly, string name)
|
||||
{
|
||||
HashSet<string> resources;
|
||||
if (!resources_to_remove.TryGetValue (assembly, out resources)) {
|
||||
resources = resources_to_remove [assembly] = new HashSet<string> ();
|
||||
}
|
||||
|
||||
resources.Add (name);
|
||||
}
|
||||
|
||||
public void SetPublic (IMetadataTokenProvider provider)
|
||||
{
|
||||
public_api.Add (provider);
|
||||
|
||||
@@ -32,8 +32,12 @@ namespace Mono.Linker {
|
||||
// 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
|
||||
// The linker still analyzes the assemblies (to know what they require) but does not modify them.
|
||||
Copy,
|
||||
// Copy the existing files, assembly and symbols, into the output destination if and only if
|
||||
// anything from the assembly is used.
|
||||
// The linker still analyzes the assemblies (to know what they require) but does not modify them.
|
||||
CopyUsed,
|
||||
// Link the assembly
|
||||
Link,
|
||||
// Remove the assembly from the output
|
||||
|
||||
49
external/linker/linker/Mono.Linker/Driver.cs
vendored
49
external/linker/linker/Mono.Linker/Driver.cs
vendored
@@ -95,6 +95,11 @@ namespace Mono.Linker {
|
||||
if (token.Length < 3)
|
||||
Usage ("Option is too short");
|
||||
|
||||
if (token == "--skip-unresolved") {
|
||||
context.IgnoreUnresolved = bool.Parse (GetParam ());
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (token [2]) {
|
||||
case 'v':
|
||||
Version ();
|
||||
@@ -120,6 +125,9 @@ namespace Mono.Linker {
|
||||
case 'c':
|
||||
context.CoreAction = ParseAssemblyAction (GetParam ());
|
||||
break;
|
||||
case 'u':
|
||||
context.UserAction = ParseAssemblyAction (GetParam ());
|
||||
break;
|
||||
case 'p':
|
||||
AssemblyAction action = ParseAssemblyAction (GetParam ());
|
||||
context.Actions [GetParam ()] = action;
|
||||
@@ -275,6 +283,7 @@ namespace Mono.Linker {
|
||||
{
|
||||
LinkContext context = new LinkContext (pipeline);
|
||||
context.CoreAction = AssemblyAction.Skip;
|
||||
context.UserAction = AssemblyAction.Link;
|
||||
context.OutputDirectory = "output";
|
||||
return context;
|
||||
}
|
||||
@@ -290,25 +299,27 @@ namespace Mono.Linker {
|
||||
Console.WriteLine ("monolinker [options] -x|-a|-i file");
|
||||
#endif
|
||||
|
||||
Console.WriteLine (" --about About the {0}", _linker);
|
||||
Console.WriteLine (" --version Print the version number of the {0}", _linker);
|
||||
Console.WriteLine (" -out Specify the output directory, default to `output'");
|
||||
Console.WriteLine (" -c Action on the core assemblies, skip, copy or link, default to skip");
|
||||
Console.WriteLine (" -p Action per assembly");
|
||||
Console.WriteLine (" -s Add a new step to the pipeline.");
|
||||
Console.WriteLine (" -t Keep assemblies in which only type forwarders are referenced.");
|
||||
Console.WriteLine (" -d Add a directory where the linker will look for assemblies");
|
||||
Console.WriteLine (" -b Generate debug symbols for each linked module (true or false)");
|
||||
Console.WriteLine (" -g Generate a new unique guid for each linked module (true or false)");
|
||||
Console.WriteLine (" -v Keep memebers needed by debugger attributes (true or false)");
|
||||
Console.WriteLine (" -l List of i18n assemblies to copy to the output directory");
|
||||
Console.WriteLine (" separated with a comma: none,all,cjk,mideast,other,rare,west");
|
||||
Console.WriteLine (" default is all");
|
||||
Console.WriteLine (" -x Link from an XML descriptor");
|
||||
Console.WriteLine (" -a Link from a list of assemblies");
|
||||
Console.WriteLine (" -r Link from a list of assemblies using roots visible outside of the assembly");
|
||||
Console.WriteLine (" -i Link from an mono-api-info descriptor");
|
||||
Console.WriteLine (" -z Include default preservations (true or false), default to true");
|
||||
Console.WriteLine (" --about About the {0}", _linker);
|
||||
Console.WriteLine (" --version Print the version number of the {0}", _linker);
|
||||
Console.WriteLine (" --skip-unresolved Ignore unresolved types and methods (true or false)");
|
||||
Console.WriteLine (" -out Specify the output directory, default to `output'");
|
||||
Console.WriteLine (" -c Action on the core assemblies, skip, copy, copyused or link, default to skip");
|
||||
Console.WriteLine (" -u Action on the user assemblies, skip, copy, copyused or link, default to link");
|
||||
Console.WriteLine (" -p Action per assembly");
|
||||
Console.WriteLine (" -s Add a new step to the pipeline.");
|
||||
Console.WriteLine (" -t Keep assemblies in which only type forwarders are referenced.");
|
||||
Console.WriteLine (" -d Add a directory where the linker will look for assemblies");
|
||||
Console.WriteLine (" -b Generate debug symbols for each linked module (true or false)");
|
||||
Console.WriteLine (" -g Generate a new unique guid for each linked module (true or false)");
|
||||
Console.WriteLine (" -v Keep memebers needed by debugger attributes (true or false)");
|
||||
Console.WriteLine (" -l List of i18n assemblies to copy to the output directory");
|
||||
Console.WriteLine (" separated with a comma: none,all,cjk,mideast,other,rare,west");
|
||||
Console.WriteLine (" default is all");
|
||||
Console.WriteLine (" -x Link from an XML descriptor");
|
||||
Console.WriteLine (" -a Link from a list of assemblies");
|
||||
Console.WriteLine (" -r Link from a list of assemblies using roots visible outside of the assembly");
|
||||
Console.WriteLine (" -i Link from an mono-api-info descriptor");
|
||||
Console.WriteLine (" -z Include default preservations (true or false), default to true");
|
||||
Console.WriteLine ("");
|
||||
|
||||
Environment.Exit (1);
|
||||
|
||||
@@ -38,12 +38,14 @@ namespace Mono.Linker {
|
||||
|
||||
Pipeline _pipeline;
|
||||
AssemblyAction _coreAction;
|
||||
AssemblyAction _userAction;
|
||||
Dictionary<string, AssemblyAction> _actions;
|
||||
string _outputDirectory;
|
||||
readonly Dictionary<string, string> _parameters;
|
||||
bool _linkSymbols;
|
||||
bool _keepTypeForwarderOnlyAssemblies;
|
||||
bool _keepMembersForDebuggerAttributes;
|
||||
bool _ignoreUnresolved;
|
||||
|
||||
AssemblyResolver _resolver;
|
||||
|
||||
@@ -71,6 +73,11 @@ namespace Mono.Linker {
|
||||
set { _coreAction = value; }
|
||||
}
|
||||
|
||||
public AssemblyAction UserAction {
|
||||
get { return _userAction; }
|
||||
set { _userAction = value; }
|
||||
}
|
||||
|
||||
public bool LinkSymbols {
|
||||
get { return _linkSymbols; }
|
||||
set { _linkSymbols = value; }
|
||||
@@ -88,6 +95,12 @@ namespace Mono.Linker {
|
||||
set { _keepMembersForDebuggerAttributes = value; }
|
||||
}
|
||||
|
||||
public bool IgnoreUnresolved
|
||||
{
|
||||
get { return _ignoreUnresolved; }
|
||||
set { _ignoreUnresolved = value; }
|
||||
}
|
||||
|
||||
public System.Collections.IDictionary Actions {
|
||||
get { return _actions; }
|
||||
}
|
||||
@@ -247,7 +260,7 @@ namespace Mono.Linker {
|
||||
} else if (IsCore (name)) {
|
||||
action = _coreAction;
|
||||
} else {
|
||||
action = AssemblyAction.Link;
|
||||
action = _userAction;
|
||||
}
|
||||
|
||||
_annotations.SetAction (assembly, action);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Linker.Tests.Cases.Expectations.Assertions {
|
||||
/// <summary>
|
||||
/// Verifies that a resource exists in the test case assembly
|
||||
/// </summary>
|
||||
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
|
||||
public class KeptResourceAttribute : KeptAttribute {
|
||||
public KeptResourceAttribute (string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty (name))
|
||||
throw new ArgumentException ("Value cannot be null or empty.", nameof (name));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user