|
@@ -1,12 +1,10 @@
|
|
|
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
-// Sourced from https://github.com/dotnet/core-setup/tree/be8d8e3486b2bf598ed69d39b1629a24caaba45e/tools-local/tasks, needs to be kept in sync
|
|
|
|
|
|
|
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
-using System.Security.Cryptography;
|
|
|
|
|
using Microsoft.Build.Framework;
|
|
using Microsoft.Build.Framework;
|
|
|
using Microsoft.Build.Utilities;
|
|
using Microsoft.Build.Utilities;
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
using Microsoft.Extensions.DependencyModel;
|
|
@@ -28,21 +26,22 @@ namespace RepoTasks
|
|
|
public string OutputPath { get; set; }
|
|
public string OutputPath { get; set; }
|
|
|
|
|
|
|
|
[Required]
|
|
[Required]
|
|
|
- public string FrameworkName { get; set; }
|
|
|
|
|
|
|
+ public string TargetFramework { get; set; }
|
|
|
|
|
|
|
|
- // When generating the .deps.json file, these files are used to replace "project" libraries with "packages".
|
|
|
|
|
- public ITaskItem[] ResolvedPackageProjectReferences { get; set; }
|
|
|
|
|
|
|
+ [Required]
|
|
|
|
|
+ public string FrameworkName { get; set; }
|
|
|
|
|
|
|
|
- public string[] PackagesToRemove { get; set; }
|
|
|
|
|
|
|
+ [Required]
|
|
|
|
|
+ public string FrameworkVersion { get; set; }
|
|
|
|
|
|
|
|
[Required]
|
|
[Required]
|
|
|
- public string Runtime { get; set; }
|
|
|
|
|
|
|
+ public string BaseRuntimeIdentifier { get; set; }
|
|
|
|
|
|
|
|
public override bool Execute()
|
|
public override bool Execute()
|
|
|
{
|
|
{
|
|
|
ExecuteCore();
|
|
ExecuteCore();
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ return !Log.HasLoggedErrors;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void ExecuteCore()
|
|
private void ExecuteCore()
|
|
@@ -61,23 +60,69 @@ namespace RepoTasks
|
|
|
|
|
|
|
|
var manager = new RuntimeGraphManager();
|
|
var manager = new RuntimeGraphManager();
|
|
|
var graph = manager.Collect(lockFile);
|
|
var graph = manager.Collect(lockFile);
|
|
|
- var expandedGraph = manager.Expand(graph, Runtime);
|
|
|
|
|
-
|
|
|
|
|
- // Remove the runtime entry for the project which generates the original deps.json. For example, there is no Microsoft.AspNetCore.App.dll.
|
|
|
|
|
- var trimmedRuntimeLibraries = RuntimeReference.RemoveSharedFxRuntimeEntry(context.RuntimeLibraries, FrameworkName);
|
|
|
|
|
|
|
+ var expandedGraph = manager.Expand(graph, BaseRuntimeIdentifier);
|
|
|
|
|
|
|
|
- trimmedRuntimeLibraries = ResolveProjectsAsPackages(ResolvedPackageProjectReferences, trimmedRuntimeLibraries);
|
|
|
|
|
|
|
+ var runtimeFiles = new List<RuntimeFile>();
|
|
|
|
|
+ var nativeFiles = new List<RuntimeFile>();
|
|
|
|
|
+ var resourceAssemblies = new List<ResourceAssembly>();
|
|
|
|
|
|
|
|
- if (PackagesToRemove != null && PackagesToRemove.Any())
|
|
|
|
|
|
|
+ foreach (var library in context.RuntimeLibraries)
|
|
|
{
|
|
{
|
|
|
- trimmedRuntimeLibraries = RuntimeReference.RemoveReferences(trimmedRuntimeLibraries, PackagesToRemove);
|
|
|
|
|
|
|
+ foreach (var file in library.RuntimeAssemblyGroups.SelectMany(g => g.RuntimeFiles))
|
|
|
|
|
+ {
|
|
|
|
|
+ var path = $"runtimes/{context.Target.Runtime}/lib/{TargetFramework}/{Path.GetFileName(file.Path)}";
|
|
|
|
|
+ runtimeFiles.Add(
|
|
|
|
|
+ new RuntimeFile(
|
|
|
|
|
+ path,
|
|
|
|
|
+ file.AssemblyVersion,
|
|
|
|
|
+ file.FileVersion));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach (var file in library.NativeLibraryGroups.SelectMany(g => g.RuntimeFiles))
|
|
|
|
|
+ {
|
|
|
|
|
+ var path = $"runtimes/{context.Target.Runtime}/native/{Path.GetFileName(file.Path)}";
|
|
|
|
|
+ nativeFiles.Add(
|
|
|
|
|
+ new RuntimeFile(
|
|
|
|
|
+ path,
|
|
|
|
|
+ file.AssemblyVersion,
|
|
|
|
|
+ file.FileVersion));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ resourceAssemblies.AddRange(
|
|
|
|
|
+ library.ResourceAssemblies);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ var runtimePackageName = $"runtime.{context.Target.Runtime}.{FrameworkName}";
|
|
|
|
|
+
|
|
|
|
|
+ var runtimeLibrary = new RuntimeLibrary("package",
|
|
|
|
|
+ runtimePackageName,
|
|
|
|
|
+ FrameworkVersion,
|
|
|
|
|
+ string.Empty,
|
|
|
|
|
+ new[] { new RuntimeAssetGroup(string.Empty, runtimeFiles) },
|
|
|
|
|
+ new[] { new RuntimeAssetGroup(string.Empty, nativeFiles) },
|
|
|
|
|
+ resourceAssemblies,
|
|
|
|
|
+ Array.Empty<Dependency>(),
|
|
|
|
|
+ hashPath: null,
|
|
|
|
|
+ path: $"{runtimePackageName.ToLowerInvariant()}/{FrameworkVersion}",
|
|
|
|
|
+ serviceable: true);
|
|
|
|
|
+
|
|
|
|
|
+ var targetingPackLibrary = new RuntimeLibrary("package",
|
|
|
|
|
+ FrameworkName,
|
|
|
|
|
+ FrameworkVersion,
|
|
|
|
|
+ string.Empty,
|
|
|
|
|
+ Array.Empty<RuntimeAssetGroup>(),
|
|
|
|
|
+ Array.Empty<RuntimeAssetGroup>(),
|
|
|
|
|
+ resourceAssemblies,
|
|
|
|
|
+ new[] { new Dependency(runtimeLibrary.Name, runtimeLibrary.Version) },
|
|
|
|
|
+ hashPath: null,
|
|
|
|
|
+ path: $"{FrameworkName.ToLowerInvariant()}/{FrameworkVersion}",
|
|
|
|
|
+ serviceable: true);
|
|
|
|
|
+
|
|
|
context = new DependencyContext(
|
|
context = new DependencyContext(
|
|
|
context.Target,
|
|
context.Target,
|
|
|
CompilationOptions.Default,
|
|
CompilationOptions.Default,
|
|
|
Array.Empty<CompilationLibrary>(),
|
|
Array.Empty<CompilationLibrary>(),
|
|
|
- trimmedRuntimeLibraries,
|
|
|
|
|
|
|
+ new[] { targetingPackLibrary, runtimeLibrary },
|
|
|
expandedGraph
|
|
expandedGraph
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -86,43 +131,5 @@ namespace RepoTasks
|
|
|
new DependencyContextWriter().Write(context, depsStream);
|
|
new DependencyContextWriter().Write(context, depsStream);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private IEnumerable<RuntimeLibrary> ResolveProjectsAsPackages(ITaskItem[] resolvedProjects, IEnumerable<RuntimeLibrary> compilationLibraries)
|
|
|
|
|
- {
|
|
|
|
|
- var projects = resolvedProjects.ToDictionary(k => k.GetMetadata("PackageId"), k => k, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
-
|
|
|
|
|
- foreach (var library in compilationLibraries)
|
|
|
|
|
- {
|
|
|
|
|
- if (projects.TryGetValue(library.Name, out var project))
|
|
|
|
|
- {
|
|
|
|
|
- Log.LogMessage("Replacing the library entry for {0}", library.Name);
|
|
|
|
|
-
|
|
|
|
|
- var packagePath = project.ItemSpec;
|
|
|
|
|
- var packageId = library.Name;
|
|
|
|
|
- var version = library.Version;
|
|
|
|
|
- string packageHash;
|
|
|
|
|
- using (var sha512 = SHA512.Create())
|
|
|
|
|
- {
|
|
|
|
|
- packageHash = "sha512-" + sha512.ComputeHashAsBase64(File.OpenRead(packagePath), leaveStreamOpen: false);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- yield return new RuntimeLibrary("package",
|
|
|
|
|
- library.Name,
|
|
|
|
|
- library.Version,
|
|
|
|
|
- packageHash,
|
|
|
|
|
- library.RuntimeAssemblyGroups,
|
|
|
|
|
- library.NativeLibraryGroups,
|
|
|
|
|
- library.ResourceAssemblies,
|
|
|
|
|
- library.Dependencies,
|
|
|
|
|
- serviceable: true,
|
|
|
|
|
- path: $"{library.Name}/{library.Version}".ToLowerInvariant(),
|
|
|
|
|
- hashPath: $"{library.Name}.{library.Version}.nupkg.sha512".ToLowerInvariant());
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- yield return library;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|