Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -1,6 +1,6 @@
@if not defined _echo @echo off
REM build.cmd will bootstrap the cli and ultimately call "dotnet build"
REM build.cmd will bootstrap the cli and ultimately call "dotnet pack"
@call %~dp0dotnet.cmd build %~dp0linker.sln %*
@call %~dp0dotnet.cmd pack %~dp0integration\ILLink.Tasks\ILLink.Tasks.csproj %*
@exit /b %ERRORLEVEL%

View File

@@ -0,0 +1,24 @@
using System;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Cecil;
namespace ILLink.CustomSteps
{
public class ClearInitLocalsStep : BaseStep
{
protected override void ProcessAssembly(AssemblyDefinition assembly)
{
foreach (ModuleDefinition module in assembly.Modules) {
foreach (TypeDefinition type in module.Types) {
foreach (MethodDefinition method in type.Methods) {
if (method.Body != null) {
method.Body.InitLocals = false;
}
}
}
}
}
}
}

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<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>
<AssemblyName>ILLink.CustomSteps</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<ProjectGuid>{275C1D10-168A-4AC4-8F3E-AD969F580B9C}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Compile Include="ClearInitLocals.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\linker\Mono.Linker.csproj">
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' ">Configuration=illink_Debug</SetConfiguration>
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' ">Configuration=illink_Release</SetConfiguration>
<Project>{DD28E2B1-057B-4B4D-A04D-B2EBD9E76E46}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\cecil\Mono.Cecil.csproj">
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' ">Configuration=netstandard_Debug</SetConfiguration>
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Debug' And '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_Debug</SetConfiguration>
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' ">Configuration=netstandard_Release</SetConfiguration>
<SetConfiguration Condition=" '$(Configuration)' == 'illink_Release' And '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_Release</SetConfiguration>
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
</ProjectReference>
</ItemGroup>
<!-- The reference to the linker will cause Mono.Cecil.Pdb to be
built in the wrong configuration unless we apply this
workaround. -->
<Target Name="SetCecilConfiguration"
AfterTargets="AssignProjectConfiguration">
<ItemGroup>
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' And '$(Configuration)' == 'illink_Debug' ">Configuration=net_4_0_Debug</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' And '$(Configuration)' == 'illink_Debug' ">Configuration=netstandard_Debug</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' And '$(Configuration)' == 'illink_Release' ">Configuration=net_4_0_Release</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' And '$(Configuration)' == 'illink_Release' ">Configuration=netstandard_Release</SetConfiguration>
</ProjectReferenceWithConfiguration>
</ItemGroup>
</Target>
</Project>

View File

@@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
namespace ILLink.Tasks
{
public class ComputeRemovedAssemblies : Task
{
/// <summary>
/// The paths to the inputs to the linker.
/// </summary>
[Required]
public ITaskItem[] InputAssemblies { get; set; }
/// <summary>
/// The paths to the linked assemblies.
/// </summary>
[Required]
public ITaskItem[] KeptAssemblies { get; set; }
/// <summary>
/// The set of assemblies in the inputs that weren't kept by
/// the linker. These items include the full metadata from
/// the input assemblies, and only the filenames of the
/// inputs are used to determine which assemblies were
/// removed.
/// </summary>
[Output]
public ITaskItem[] RemovedAssemblies { get; set; }
public override bool Execute()
{
var keptAssemblyNames = new HashSet<string> (
KeptAssemblies.Select(i => Path.GetFileName(i.ItemSpec))
);
RemovedAssemblies = InputAssemblies.Where(i =>
!keptAssemblyNames.Contains(Path.GetFileName(i.ItemSpec))
).ToArray();
return true;
}
}
}

View File

@@ -1,115 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.IO;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
namespace ILLink.Tasks
{
/// <summary>
/// This class exists as a workaround. It strips the publish
/// dependency file of assemblies excluded from the publish
/// output by the linker. Ideally we would pass appropriate
/// parameters to the task that generates the deps file in
/// the first place, instead of rewriting it. We may be
/// ablee to do this once
/// https://github.com/dotnet/sdk/pull/1052 is merged.
/// </summary>
public class DepsJsonLinker : Task
{
[Required]
public ITaskItem InputDepsFilePath { get; set; }
[Required]
public ITaskItem OutputDepsFilePath { get; set; }
[Required]
public ITaskItem[] ManagedPublishAssemblies { get; set; }
[Required]
public ITaskItem[] KeptAssemblies { get; set; }
public override bool Execute()
{
string inputFile = InputDepsFilePath.ItemSpec;
string outputFile = OutputDepsFilePath.ItemSpec;
string[] keptAssemblies = KeptAssemblies.Select(a => a.ItemSpec).ToArray();
string[] allAssemblies = ManagedPublishAssemblies.Select(a => a.ItemSpec).ToArray();
string[] removedAssemblies = allAssemblies.Except(keptAssemblies).ToArray();
var removedAssembliesSet = new HashSet<string> (removedAssemblies, StringComparer.InvariantCultureIgnoreCase);
JObject o = JObject.Parse (File.ReadAllText (inputFile));
JObject targets = (JObject)o["targets"];
// Remove targets
foreach (JProperty target in targets.Children()) {
JEnumerable<JToken> children = target.Value.Children ();
for (int i = 0; i < children.Count(); ++i) {
//foreach (JProperty subtarget in target.Value.Children()) {
var subtarget = (JProperty) children.ElementAt (i);
string name = subtarget.Name.Substring (0, subtarget.Name.IndexOf ('/'));
if (removedAssembliesSet.Contains (name + ".dll")) {
subtarget.Remove ();
i--;
continue;
}
// Remove dependencies
var dependencies = subtarget.Value["dependencies"];
if (dependencies != null) {
for (int j = 0; j < dependencies.Count (); ++j) {
var dependency = ((JProperty)dependencies.ElementAt (j));
if (removedAssembliesSet.Contains (dependency.Name + ".dll")) {
dependency.Remove ();
j--;
continue;
}
}
}
// Remove runtimes
var runtimes = subtarget.Value["runtime"];
if (runtimes != null) {
for (int j = 0; j < runtimes.Count (); ++j) {
var runtime = ((JProperty)runtimes.ElementAt (j));
string runtimeFileName = runtime.Name.Substring (runtime.Name.LastIndexOf ('/') + 1);
if (removedAssembliesSet.Contains (runtimeFileName)) {
runtime.Remove ();
j--;
continue;
}
}
}
}
}
// Remove libraries
JObject libraries = (JObject)o["libraries"];
JEnumerable<JToken> libraryChildren = libraries.Children ();
for (int i = 0; i < libraryChildren.Count (); ++i) {
var library = (JProperty)libraryChildren.ElementAt (i);
string name = library.Name.Substring (0, library.Name.IndexOf ('/'));
if (removedAssembliesSet.Contains (name + ".dll")) {
library.Remove ();
i--;
continue;
}
}
File.WriteAllText (outputFile, o.ToString ());
return true;
}
}
}

View File

@@ -0,0 +1,108 @@
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.Reflection.PortableExecutable;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
namespace ILLink.Tasks
{
public class FindNativeDeps : Task
{
/// <summary>
/// The managed assemblies to scan for references to native
/// dependencies.
/// </summary>
[Required]
public ITaskItem[] ManagedAssemblyPaths { get; set; }
/// <summary>
/// The set of native dependencies to keep even if they
/// aren't found to be referenced by a managed assembly..
/// </summary>
public ITaskItem[] NativeDepsToKeep { get; set; }
/// <summary>
/// The paths to the available native dependencies. We
/// expect that all references found point to existing
/// native files.
/// </summary>
[Required]
public ITaskItem[] NativeDepsPaths { get; set; }
/// <summary>
/// The set of native dependencies to keep, including those
/// found in the analysis, and those explicitly marked keep
/// by NativeDepsToKeep. This includes metadata from the
/// input NativeDepsToKeep.
/// </summary>
[Output]
public ITaskItem[] KeptNativeDepsPaths { get; set; }
public override bool Execute()
{
var allNative = new Dictionary<string, ITaskItem> ();
foreach (var n in NativeDepsPaths)
{
var fileName = Path.GetFileName(n.ItemSpec);
if (!allNative.ContainsKey(fileName))
{
allNative.Add(fileName, n);
}
}
var keptNative = new List<ITaskItem> ();
var managedAssemblies = ManagedAssemblyPaths.Select (i => i.ItemSpec).ToArray();
foreach (string managedAssembly in managedAssemblies)
{
using (var peReader = new PEReader(new FileStream(managedAssembly, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
if (peReader.HasMetadata)
{
var reader = peReader.GetMetadataReader();
for (int i = 1, count = reader.GetTableRowCount(TableIndex.ModuleRef); i <= count; i++)
{
var moduleRef = reader.GetModuleReference(MetadataTokens.ModuleReferenceHandle(i));
var moduleName = reader.GetString(moduleRef.Name);
var moduleRefCandidates = new[] { moduleName, moduleName + ".dll", moduleName + ".so", moduleName + ".dylib" };
ITaskItem referencedNativeFile = null;
foreach (string moduleRefCandidate in moduleRefCandidates)
{
if (allNative.TryGetValue (moduleRefCandidate, out referencedNativeFile))
{
break;
}
}
if (referencedNativeFile != null)
{
keptNative.Add(referencedNativeFile);
}
else
{
// DLLImport that wasn't satisfied
Log.LogMessage(MessageImportance.High, "unsatisfied DLLImport: " + managedAssembly + " -> " + moduleName);
}
}
}
}
}
foreach (var n in NativeDepsToKeep)
{
ITaskItem nativeFile = null;
if (allNative.TryGetValue (n.ItemSpec, out nativeFile))
{
keptNative.Add(nativeFile);
}
}
KeptNativeDepsPaths = keptNative.ToArray();
return true;
}
}
}

View File

@@ -5,7 +5,8 @@
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<PackageOutputPath>../nupkgs</PackageOutputPath>
<BaseOutputPath>../bin/</BaseOutputPath>
<PackageOutputPath>$(BaseOutputPath)nupkgs</PackageOutputPath>
<!-- IsTool true causes the build output to be placed in the
package's tools folder. This allows projects to reference the
@@ -42,7 +43,8 @@
references from being marked as dependencies. -->
<!-- TODO: Remove the custom .nuspec once the P2P PrivateAssets
issue is fixed. -->
<NuspecFile>ILLink.Tasks.nuspec</NuspecFile>
<NuspecFileName>ILLink.Tasks.nuspec</NuspecFileName>
<NuspecFile>$(BaseOutputPath)$(NuspecFileName)</NuspecFile>
<NuspecProperties>id=$(AssemblyName);authors=$(AssemblyName);description=linker tasks;</NuspecProperties>
</PropertyGroup>
@@ -65,7 +67,7 @@
Instead, we use GenerateNuspecDependsOn. We could probably also
use BeforeTargets="GenerateNuspec". -->
<PropertyGroup>
<GenerateNuspecDependsOn>SetDynamicNuspecProperties;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
<GenerateNuspecDependsOn>SetDynamicNuspecProperties;BinPlacePackageDeps;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="SetDynamicNuspecProperties"
DependsOnTargets="LayoutPackage">
@@ -74,11 +76,21 @@
</PropertyGroup>
</Target>
<!-- This target is necessary because the .nuspec includes the full
path of the selected dlls in the package layout. We want the
assets to be included in the package without the bin prefix, so
we place the .nuspec and the included targets alongside the
publish directories in the bin directory. -->
<Target Name="BinPlacePackageDeps">
<Copy SourceFiles="$(NuspecFileName)" DestinationFolder="$(BaseOutputPath)" />
<Copy SourceFiles="ILLink.Tasks.targets" DestinationFolder="$(BaseOutputPath)" />
</Target>
<Target Name="LayoutPackage">
<ItemGroup>
<TFMsToPublish Include="$(TargetFrameworks)" />
<ProjectsToPublish Include="$(MSBuildProjectFile)">
<AdditionalProperties>TargetFramework=%(TFMsToPublish.Identity);PublishDir=%(TFMsToPublish.Identity)</AdditionalProperties>
<AdditionalProperties>TargetFramework=%(TFMsToPublish.Identity);PublishDir=$(BaseOutputPath)%(TFMsToPublish.Identity)</AdditionalProperties>
</ProjectsToPublish>
</ItemGroup>
<MSBuild Projects="@(ProjectsToPublish)" Targets="Publish" />
@@ -86,7 +98,6 @@
<ItemGroup>
<Compile Include="LinkTask.cs" />
<Compile Include="DepsJsonLinker.cs" />
<Compile Include="CompareSizes.cs" />
<Compile Include="ComputeManagedAssemblies.cs" />
<Compile Include="GetRuntimeLibraries.cs" />
@@ -94,6 +105,8 @@
<Compile Include="Utils.cs" />
<Compile Include="Microsoft.NET.Build.Tasks/LockFileCache.cs" />
<Compile Include="Microsoft.NET.Build.Tasks/BuildErrorException.cs" />
<Compile Include="FindNativeDeps.cs" />
<Compile Include="ComputeRemovedAssemblies.cs" />
</ItemGroup>
<!-- TODO: Uncomment this once we can avoid hard-coding this in a
@@ -167,6 +180,10 @@
<SetConfiguration>Configuration=illink_$(Configuration)</SetConfiguration>
</ProjectReference>
<ProjectReference Include="../../../cecil/Mono.Cecil.csproj" />
<ProjectReference Include="../ILLink.CustomSteps/ILLink.CustomSteps.csproj">
<SetConfiguration>Configuration=illink_$(Configuration)</SetConfiguration>
</ProjectReference>
</ItemGroup>
<!-- Workaround for the SetConfiguration issue described above. -->
@@ -174,7 +191,8 @@
AfterTargets="AssignProjectConfiguration">
<ItemGroup>
<ProjectReferenceWithConfiguration Condition=" '%(Filename)%(Extension)' == 'Mono.Cecil.csproj' Or '%(Filename)%(Extension)' == 'Mono.Cecil.Pdb.csproj' ">
<SetConfiguration>Configuration=netstandard_$(Configuration)</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'net46' ">Configuration=net_4_0_$(Configuration)</SetConfiguration>
<SetConfiguration Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">Configuration=netstandard_$(Configuration)</SetConfiguration>
</ProjectReferenceWithConfiguration>
</ItemGroup>
</Target>
@@ -194,5 +212,7 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.1012"
PrivateAssets="All" />
<PackageReference Include="NuGet.ProjectModel" Version="4.3.0-preview1-2500" />
<PackageReference Include="System.Reflection.Metadata" Version="1.3.0"
PrivateAssets="All" />
</ItemGroup>
</Project>

View File

@@ -48,10 +48,8 @@
<!-- Used to enable incremental build for the link target. -->
<PropertyGroup>
<_LinkSemaphore>$(IntermediateOutputPath)Link.semaphore</_LinkSemaphore>
<_LinkDepsSemaphore>$(IntermediateOutputPath)LinkDeps.semaphore</_LinkDepsSemaphore>
</PropertyGroup>
<!--
This target runs the linker during the publish pipeline. The
publish pipeline has a target called ComputeFilesToPublish,
@@ -76,12 +74,14 @@
ComputeFilesToPublish, but after all of its dependencies. -->
<Target Name="ComputeLinkedFilesToPublish"
BeforeTargets="ComputeFilesToPublish"
DependsOnTargets="_ComputeLinkedAssemblies"
DependsOnTargets="_ComputeLinkedAssemblies;_FindNativeDeps"
Condition=" '$(LinkDuringPublish)' == 'true' ">
<!-- Rewrite ResolvedAssembliesToPublish, which is an input to
ComputeFilesToPublish. -->
<ItemGroup>
<ResolvedAssembliesToPublish Remove="@(_ManagedResolvedAssembliesToPublish)" />
<ResolvedAssembliesToPublish Remove="@(_NativeResolvedDepsToPublish)" />
<ResolvedAssembliesToPublish Include="@(_NativeKeptDepsToPublish)" />
<ResolvedAssembliesToPublish Include="@(_LinkedResolvedAssemblies)" />
</ItemGroup>
@@ -141,7 +141,6 @@
</ItemGroup>
</Target>
<!-- This calls the linker. Inputs are the managed assemblies to
link, and root specifications. The semaphore enables msbuild to
skip linking during an incremental build, when the semaphore is
@@ -169,6 +168,37 @@
</Touch>
</Target>
<!-- FindNativeDeps scans the managed assemblies kept by the linker
to find references to native files. It outputs the found native
dependencies, and these are prevented from being published. -->
<UsingTask TaskName="FindNativeDeps" AssemblyFile="$(LinkTaskDllPath)" />
<Target Name="_FindNativeDeps"
DependsOnTargets="_ComputeLinkedAssemblies">
<ItemGroup>
<_NativeResolvedDepsToPublish Include="@(ResolvedAssembliesToPublish)" />
<_NativeResolvedDepsToPublish Remove="@(_ManagedResolvedAssembliesToPublish)" />
</ItemGroup>
<ItemGroup>
<_ManagedLinkedAssemblies Include="@(_LinkedResolvedAssemblies)" />
<_ManagedLinkedAssemblies Include="@(_LinkedIntermediateAssembly)" />
</ItemGroup>
<ItemGroup>
<_NativeDepsToAlwaysKeep Include="coreclr.dll;libcoreclr.dylib;libcoreclr.so" />
<_NativeDepsToAlwaysKeep Include="clrjit.dll;libclrjit.dylib;libclrjit.so" />
<_NativeDepsToAlwaysKeep Include="hostfxr.dll;libhostfxr.dylib;libhostfxr.so" />
<_NativeDepsToAlwaysKeep Include="hostpolicy.dll;libhostpolicy.dylib;libhostpolicy.so" />
</ItemGroup>
<FindNativeDeps ManagedAssemblyPaths="@(_ManagedLinkedAssemblies)"
NativeDepsPaths="@(_NativeResolvedDepsToPublish)"
NativeDepsToKeep="@(_NativeDepsToAlwaysKeep)">
<Output TaskParameter="KeptNativeDepsPaths" ItemName="_NativeKeptDepsToPublish" />
</FindNativeDeps>
</Target>
<!-- Computes the managed assemblies that are input to the
linker. Includes managed assemblies from
@@ -243,9 +273,10 @@
assembly, because we root it separately using an xml file,
which lets us explicitly root everything. -->
<ItemGroup>
<LinkerRootAssemblies Include="@(_ManagedResolvedAssembliesToPublish->'%(Filename)')" />
<LinkerRootAssemblies Remove="@(PlatformLibraries->'%(Filename)')" />
<LinkerRootAssemblies Include="System.Private.CoreLib" />
<_LinkerRootAssemblies Include="@(_ManagedResolvedAssembliesToPublish->'%(Filename)')" />
<_LinkerRootAssemblies Remove="@(PlatformLibraries->'%(Filename)')" />
<_LinkerRootAssemblies Include="System.Private.CoreLib" />
<LinkerRootAssemblies Include="@(_LinkerRootAssemblies)" />
</ItemGroup>
</Target>
@@ -286,38 +317,27 @@
RootDescriptorFilePath="$(_IntermediateRootDescriptorPath)" />
</Target>
<!-- Uses _PublishConflictPackageFiles, an input to the publish deps
file generation target, to exclude the removed managed
assemblies and native dependencies from the generated deps
file. -->
<UsingTask TaskName="ComputeRemovedAssemblies" AssemblyFile="$(LinkTaskDllPath)" />
<Target Name="_ExcludeRemovedFilesFromDepFileGeneration"
DependsOnTargets="_ComputeManagedResolvedAssembliesToPublish;_ComputeLinkedAssemblies;_FindNativeDeps;_HandlePublishFileConflicts"
BeforeTargets="GeneratePublishDependencyFile"
Condition=" '$(LinkDuringPublish)' == 'true' ">
<ComputeRemovedAssemblies InputAssemblies="@(_ManagedResolvedAssembliesToPublish)"
KeptAssemblies="@(_LinkedResolvedAssemblies)">
<Output TaskParameter="RemovedAssemblies" ItemName="_RemovedManagedAssemblies" />
</ComputeRemovedAssemblies>
<!-- This target needs to remove from the publish deps file those
assemblies that were excluded from the publish output by the
linker. Currently it does so by rewriting the publish
dependency file (as opposed to generating one without the
excluded assemblies in the first place).
TODO: update this to pass FilesToSkip to
GeneratePublishDependencyFile once
https://github.com/dotnet/sdk/pull/1052 is merged.
-->
<UsingTask TaskName="DepsJsonLinker" AssemblyFile="$(LinkTaskDllPath)" />
<Target Name="_GenerateLinkedPublishDependencyFile"
DependsOnTargets="_ComputeManagedAssembliesToLink;_ComputeLinkedAssemblies"
AfterTargets="GeneratePublishDependencyFile"
Condition=" '$(LinkDuringPublish)' == 'true' "
Inputs="@(_ManagedResolvedAssembliesToPublish);@(_LinkedResolvedAssemblies);$(PublishDepsFilePath)"
Outputs="$(_LinkDepsSemaphore)">
<!-- DepsJsonLinker expects inputs in the form of filename.dll. -->
<!-- We pass _ManagedResolvedAssembliesToPublish, which doesn't
contain any .ni files. This correctly prevents stripping of
the .ni files (which we want to continue publishing at the
moment). -->
<!-- This doesn't filter any assemblies from IntermediateAssembly,
which should currently always be rooted by default. -->
<DepsJsonLinker InputDepsFilePath="$(PublishDepsFilePath)"
OutputDepsFilePath="$(PublishDepsFilePath)"
ManagedPublishAssemblies="@(_ManagedResolvedAssembliesToPublish->'%(Filename)%(Extension)')"
KeptAssemblies="@(_LinkedResolvedAssemblies->'%(Filename)%(Extension)')" />
<Touch Files="$(_LinkDepsSemaphore)" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<ItemGroup>
<_RemovedNativeDeps Include="@(_NativeResolvedDepsToPublish)" />
<_RemovedNativeDeps Remove="@(_NativeKeptDepsToPublish)" />
<_PublishConflictPackageFiles Include="@(_RemovedManagedAssemblies)" />
<_PublishConflictPackageFiles Include="@(_RemovedNativeDeps)" />
</ItemGroup>
</Target>
</Project>

View File

@@ -36,6 +36,10 @@ namespace ILLink.Tests
AddLinkerReference(csproj);
BuildAndLink(csproj, null);
int ret = RunApp(csproj, out string commandOutput);
Assert.True(ret == 0);
Assert.True(commandOutput.Contains("Hello World!"));
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;
@@ -28,10 +29,20 @@ namespace ILLink.Tests
protected int Dotnet(string args, string workingDir, string additionalPath = null)
{
return RunCommand(context.DotnetToolPath, args, workingDir, additionalPath);
return RunCommand(context.DotnetToolPath, args, workingDir, additionalPath, out string commandOutput);
}
protected int RunCommand(string command, string args, string workingDir, string additionalPath = null)
protected int RunCommand(string command, string args, int timeout = 60000)
{
return RunCommand(command, args, null, null, out string commandOutput, timeout);
}
protected int RunCommand(string command, string args, string workingDir)
{
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)
{
output.WriteLine($"{command} {args}");
if (workingDir != null)
@@ -50,18 +61,37 @@ namespace ILLink.Tests
string path = psi.Environment["PATH"];
psi.Environment["PATH"] = path + ";" + additionalPath;
}
var process = new Process();
process.StartInfo = psi;
var process = new Process
{
StartInfo = psi,
StringBuilder processOutput = new StringBuilder();
DataReceivedEventHandler handler = (sender, e) => {
processOutput.Append(e.Data);
processOutput.AppendLine();
};
StringBuilder processError = new StringBuilder();
DataReceivedEventHandler ehandler = (sender, e) => {
processError.Append(e.Data);
processError.AppendLine();
};
process.OutputDataReceived += handler;
process.ErrorDataReceived += ehandler;
process.Start();
string capturedOutput = process.StandardOutput.ReadToEnd();
output.WriteLine(capturedOutput);
string capturedError = process.StandardError.ReadToEnd();
output.WriteLine(capturedError);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
if (!process.WaitForExit(timeout)) {
process.Kill();
}
// WaitForExit with timeout doesn't guarantee
// that the async output handlers have been
// called, so WaitForExit needs to be called
// afterwards.
process.WaitForExit();
string processOutputStr = processOutput.ToString();
string processErrorStr = processError.ToString();
output.WriteLine(processOutputStr);
output.WriteLine(processErrorStr);
commandOutput = processOutputStr;
return process.ExitCode;
}
@@ -92,12 +122,39 @@ namespace ILLink.Tests
}
ret = Dotnet(publishArgs, demoRoot);
if (ret != 0) {
output.WriteLine("publish failed");
output.WriteLine("publish failed, returning " + ret);
Assert.True(false);
return;
}
}
public int RunApp(string csproj, out string processOutput, int timeout = 60000)
{
string demoRoot = Path.GetDirectoryName(csproj);
string executablePath = Path.Combine(
demoRoot, "bin", context.Configuration, "netcoreapp2.0",
context.RuntimeIdentifier, "publish",
Path.GetFileNameWithoutExtension(csproj)
);
if (context.RuntimeIdentifier.Contains("win")) {
executablePath += ".exe";
}
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);
return ret;
}
protected void AddLinkerReference(string csproj)
{
var xdoc = XDocument.Load(csproj);

View File

@@ -4,17 +4,41 @@
<type fullname="System.Linq.Queryable" required="true" />
</assembly>
<!--- Called by System.Linq.Expressions.Expression:CreateLambda -->
<assembly fullname="System.Linq.Expressions">
<type fullname="System.Linq.Expressions.Expression`1" required="true" />
<!--- Called by System.Linq.Expressions.Expression:CreateLambda -->
<type fullname="System.Linq.Expressions.Expression`1" required="true" />
<!--- Called by System.Runtime.CompilerServices.CallSite`1.CreateCustomNoMatchDelegate and System.Runtime.CompilerServices.CallSite`1.CreateCustomUpdateDelegate-->
<type fullname="System.Runtime.CompilerServices.CallSiteOps" required="true" />
<type fullname="System.Dynamic.DynamicObject" >
<!--- Called by System.Dynamic.DynamicObject.MetaDynamic.BindBinaryOperation -->
<method name="TryBinaryOperation" required="true" />
</type>
</assembly>
<assembly fullname="System.ComponentModel.TypeConverter">
<!-- Called by System.RuntimeTypeHandle.CreateInstance -->
<type fullname="System.ComponentModel.StringConverter" required="true" >
<method name=".ctor" required="true" />
</type>
<type fullname="System.ComponentModel.BooleanConverter" required="true" >
<method name=".ctor" required="true" />
</type>
<type fullname="System.ComponentModel.CollectionConverter" >
<method name=".ctor" required="true" />
</type>
</assembly>
<assembly fullname="Microsoft.CSharp">
<type fullname="Microsoft.CSharp.RuntimeBinder.Binder" >
<!-- Called by AspNetCore._Views_Home_Index_cshtml.<ExecuteAsync>d__11.MoveNext() -->
<method name="Convert" required="true" />
</type>
</assembly>
<assembly fullname="System.Dynamic.Runtime">
<!--- Called by [System.Dynamic.Runtime]System.Runtime.CompilerServices.CallSite<>.CreateCustomNoMatchDelegate and [System.Dynamic.Runtime]System.Runtime.CompilerServices.CallSite<>.CreateCustomUpdateDelegate-->
<type fullname="System.Runtime.CompilerServices.CallSiteOps" required="true" />
<!--- Called by [System.Dynamic.Runtime]System.Runtime.CompilerServices.CallSiteBinder.Stitch -->
<type fullname="System.Runtime.CompilerServices.CallSite" required="true" />
<!--- Called by [System.Dynamic.Runtime]System.Runtime.CompilerServices.CallSiteBinder.Stitch -->
<type fullname="System.Runtime.CompilerServices.CallSite`1" required="true" />
</assembly>
<type fullname="System.Runtime.CompilerServices.CallSite`1" required="true">
<!--- Called by [System.Dynamic.Runtime]System.Runtime.CompilerServices.CallSiteBinder.Stitch -->
<method name="get_Update" required="true" />
</type>
</assembly>
</linker>

View File

@@ -33,6 +33,9 @@ namespace ILLink.Tests
AddLinkerReference(csproj);
BuildAndLink(csproj, rootFiles);
int ret = RunApp(csproj, out string commandOutput);
Assert.True(ret == 0);
}
// returns path to .csproj project file
@@ -48,7 +51,7 @@ namespace ILLink.Tests
Directory.Delete(repoName, true);
}
ret = RunCommand("git", $"clone {gitRepo}", null, null);
ret = RunCommand("git", $"clone {gitRepo}");
if (ret != 0) {
output.WriteLine("git failed");
Assert.True(false);
@@ -59,7 +62,7 @@ namespace ILLink.Tests
Assert.True(false);
}
ret = RunCommand("git", $"checkout {gitBranch}", demoRoot, null);
ret = RunCommand("git", $"checkout {gitBranch}", demoRoot);
if (ret != 0) {
output.WriteLine($"problem checking out branch {gitBranch}");
Assert.True(false);

View File

@@ -5,6 +5,6 @@
<!-- When the tests are run from the repo's test bin directory,
this NuGet.config should be read to find the local package
directory. -->
<add key="local linker packages" value="../nupkgs" />
<add key="local linker packages" value="../bin/nupkgs" />
</packageSources>
</configuration>

View File

@@ -54,7 +54,7 @@ namespace ILLink.Tests
public static TestContext CreateDefaultContext()
{
var packageName = "ILLink.Tasks";
var packageSource = "../../../../nupkgs";
var packageSource = "../../../../bin/nupkgs";
var tasksPackages = Directory.GetFiles(packageSource)
.Where(p => Path.GetExtension(p) == ".nupkg")
.Select(p => Path.GetFileNameWithoutExtension(p))

View File

@@ -58,6 +58,10 @@ namespace ILLink.Tests
AddLinkerReference(csproj);
BuildAndLink(csproj);
int ret = RunApp(csproj, out string commandOutput, 5000);
Assert.True(commandOutput.Contains("Application started. Press Ctrl+C to shut down."));
Assert.True(commandOutput.Contains("Now listening on: http://localhost:5000"));
}
}
}

View File

@@ -1,4 +1,3 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
@@ -9,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "..\cecil\Mono
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "..\cecil\symbols\pdb\Mono.Cecil.Pdb.csproj", "{63E6915C-7EA4-4D76-AB28-0D7191EEA626}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILLink.CustomSteps", "integration\ILLink.CustomSteps\ILLink.CustomSteps.csproj", "{275C1D10-168A-4AC4-8F3E-AD969F580B9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -58,5 +59,23 @@ Global
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Release|x64.Build.0 = netstandard_Release|x64
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Release|x86.ActiveCfg = netstandard_Release|x86
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.Release|x86.Build.0 = netstandard_Release|x86
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|Any CPU.ActiveCfg = illink_Debug|Any CPU
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|Any CPU.Build.0 = illink_Debug|Any CPU
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|x64.ActiveCfg = illink_Debug|x64
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|x64.Build.0 = illink_Debug|x64
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|x86.ActiveCfg = illink_Debug|x86
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Debug|x86.Build.0 = illink_Debug|x86
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|Any CPU.ActiveCfg = illink_Release|Any CPU
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|Any CPU.Build.0 = illink_Release|Any CPU
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|x64.ActiveCfg = illink_Release|x64
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|x64.Build.0 = illink_Release|x64
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|x86.ActiveCfg = illink_Release|x86
{275C1D10-168A-4AC4-8F3E-AD969F580B9C}.Release|x86.Build.0 = illink_Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E43A3901-42B0-48CA-BB36-5CD40A99A6EE}
EndGlobalSection
EndGlobal

View File

@@ -3,5 +3,5 @@
REM restore.sh will bootstrap the cli and ultimately call "dotnet
REM restore". Dependencies of the linker will get restored as well.
@call %~dp0dotnet.cmd restore %~dp0linker.sln %*
@call %~dp0dotnet.cmd restore %~dp0integration\linker.sln %*
@exit /b %ERRORLEVEL%

View File

@@ -4,4 +4,4 @@
# restore". Dependencies of the linker will get restored as well.
working_tree_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$working_tree_root/dotnet.sh restore $working_tree_root/linker.sln $@
$working_tree_root/dotnet.sh restore $working_tree_root/integration/linker.sln $@