Skip to content

Flatten the dependency graph of Microsoft.AspNetCore.App #4061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure/pipelines/jobs/default-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- job: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
displayName: ${{ coalesce(parameters.jobDisplayName, parameters.agentOs) }}
dependsOn: ${{ parameters.dependsOn }}
timeoutInMinutes: 90
timeoutInMinutes: 120
workspace:
clean: all
strategy:
Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<Import Project="eng\targets\RuntimeIdentifiers.props" />
<Import Project="eng\targets\Cpp.Common.props" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
<Import Project="eng\targets\CSharp.Common.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
<Import Project="eng\targets\SharedFx.Common.props" Condition="'$(MSBuildProjectExtension)' == '.shfxproj'" />
<Import Project="eng\targets\Wix.Common.props" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />

</Project>
1 change: 0 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@

<Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
<Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
<Import Project="eng\targets\SharedFx.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.shfxproj'" />
<Import Project="eng\targets\Wix.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
</Project>
7 changes: 6 additions & 1 deletion build/Publish.targets
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
Value="$(PackageVersion)" />
</Target>

<Target Name="GetFilesToPublish" DependsOnTargets="GetArtifactInfo;GeneratePublishFiles">
<Target Name="GetFilesToPublish" DependsOnTargets="GetAllRidPackages;GetArtifactInfo;GeneratePublishFiles">
<PropertyGroup>
<BlobBasePath>aspnetcore/Runtime/$(PackageVersion)/</BlobBasePath>
<NpmBlobBasePath>aspnetcore/npm/</NpmBlobBasePath>
Expand Down Expand Up @@ -175,6 +175,11 @@
<Output TaskParameter="JoinResult" ItemName="_PackageArtifactInfoWithCategory" />
</RepoTasks.JoinItems>

<ItemGroup>
<_RidSpecificPackages Include="$(SupportedRuntimeIdentifiers)" Exclude="$(SharedFxRid)" />
<PackageToPublish Include="$(DependencyPackagesDir)runtime.%(_RidSpecificPackages.Identity).Microsoft.AspNetCore.App.$(SharedFxVersion).nupkg" Category="ship" />
</ItemGroup>

<ItemGroup>
<PackageToPublish Include="%(_PackageArtifactInfoWithCategory.ArtifactPath)" Category="%(_PackageArtifactInfoWithCategory.Category)" />
<PackageToPublish Include="%(_PackageArtifactInfo.ArtifactPath)" Category="%(_PackageArtifactInfo.Category)" Condition="'%(_PackageArtifactInfo.Category)' != ''" />
Expand Down
2 changes: 1 addition & 1 deletion build/SharedFx.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<UnitTestFxProject>$(RepositoryRoot)src\Framework\Framework.UnitTests\Framework.UnitTests.csproj</UnitTestFxProject>
<UnitTestFxProject>$(RepositoryRoot)src\Framework\test\Microsoft.AspNetCore.App.UnitTests.csproj</UnitTestFxProject>
<UnitTestFxProject>$([MSBuild]::NormalizePath($(UnitTestFxProject)))</UnitTestFxProject>
<CodeSignDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(CodeSignDependsOn);GetSharedFxFilesToSign</CodeSignDependsOn>
<BuildSharedFxDependsOn>_BuildSharedFxProjects;TestSharedFx</BuildSharedFxDependsOn>
Expand Down
2 changes: 1 addition & 1 deletion build/artifacts.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageArtifact Include="Microsoft.AspNet.Identity.AspNetCoreCompat" Category="noship" />
<PackageArtifact Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Category="noship" />
<PackageArtifact Include="Microsoft.AspNetCore.App" Category="ship" />
<PackageArtifact Include="runtime.$(SharedFxRid).Microsoft.AspNetCore.App" Category="noship" />
<PackageArtifact Include="runtime.$(SharedFxRid).Microsoft.AspNetCore.App" Category="ship" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design? Are we going to be shipping this as a package now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is intentional. This is how standalone deployment works, and what the "runtime.json" file is for.

<PackageArtifact Include="Microsoft.AspNetCore.Antiforgery" Category="ship" />
<PackageArtifact Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Category="ship" />
<PackageArtifact Include="Microsoft.AspNetCore.AspNetCoreModule" Category="noship" Condition=" '$(OS)' == 'Windows_NT' " />
Expand Down
2 changes: 1 addition & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

<CastleCorePackageVersion>4.2.1</CastleCorePackageVersion>
<DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion>2.2.0-preview1-03124-01</DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion>
<DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>2.0.0</DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>
<DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>2.1.0</DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>
<DevDependency_WindowsAzureStoragePackageVersion>8.7.0</DevDependency_WindowsAzureStoragePackageVersion>
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
<IdentityServer4PackageVersion>2.3.0-preview1-update2</IdentityServer4PackageVersion>
Expand Down
115 changes: 61 additions & 54 deletions build/tasks/ProcessSharedFrameworkDeps.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// 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.
// Sourced from https://github.com/dotnet/core-setup/tree/be8d8e3486b2bf598ed69d39b1629a24caaba45e/tools-local/tasks, needs to be kept in sync

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Extensions.DependencyModel;
Expand All @@ -28,21 +26,22 @@ public class ProcessSharedFrameworkDeps : Task
public string OutputPath { get; set; }

[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]
public string Runtime { get; set; }
public string BaseRuntimeIdentifier { get; set; }

public override bool Execute()
{
ExecuteCore();

return true;
return !Log.HasLoggedErrors;
}

private void ExecuteCore()
Expand All @@ -61,23 +60,69 @@ private void ExecuteCore()

var manager = new RuntimeGraphManager();
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.Target,
CompilationOptions.Default,
Array.Empty<CompilationLibrary>(),
trimmedRuntimeLibraries,
new[] { targetingPackLibrary, runtimeLibrary },
expandedGraph
);

Expand All @@ -86,43 +131,5 @@ private void ExecuteCore()
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;
}
}
}
}
}
1 change: 0 additions & 1 deletion build/tasks/RepoTasks.tasks
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<UsingTask TaskName="RepoTasks.JoinItems" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.OrderBy" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.ProcessSharedFrameworkDeps" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.ResolveVersionRange" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.PublishToAzureBlob" AssemblyFile="$(_RepoTaskAssembly)" />

<!-- tools from dotnet-buildtools -->
Expand Down
68 changes: 0 additions & 68 deletions build/tasks/ResolveVersionRange.cs

This file was deleted.

3 changes: 1 addition & 2 deletions build/tasks/Utilities/RuntimeGraphManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.IO;
using System.Linq;
using Microsoft.Extensions.DependencyModel;
using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.ProjectModel;
using NuGet.RuntimeModel;
Expand Down Expand Up @@ -63,4 +62,4 @@ private IEnumerable<string> FindImporters(RuntimeGraph runtimeGraph, string runt
}
}
}
}
}
Loading