From f75481f731d761115fd7bbf4c95a5cc37d7bd9c0 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 23 Mar 2016 14:51:03 -0700 Subject: [PATCH] Add runtime signature into deps.json --- Microsoft.DotNet.Cli.sln | 19 +++++++ global.json | 2 +- .../DependencyContextBuilder.cs | 33 ++++++++++-- .../DependencyContext.cs | 50 +++++++++++++------ .../DependencyContextJsonReader.cs | 20 ++++++-- .../DependencyContextLoader.cs | 2 +- .../DependencyContextStrings.cs | 2 + .../DependencyContextWriter.cs | 23 ++++++--- src/corehost/cli/deps_format.cpp | 5 +- .../DependencyContextBuilderTests.cs | 19 +++++-- .../DependencyContextJsonReaderTest.cs | 24 +++++---- .../DependencyContextJsonWriterTests.cs | 25 +++++++--- .../DependencyContextLoaderTests.cs | 25 +++++----- .../DependencyContextTests.cs | 10 +--- tools/RuntimeGraphGenerator/Program.cs | 6 +-- 15 files changed, 187 insertions(+), 78 deletions(-) diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 52d420f5b..3e51e48dd 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -83,6 +83,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "update-dependencies", "scri EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Cli.Utils.Tests", "test\Microsoft.DotNet.Cli.Utils.Tests\Microsoft.DotNet.Cli.Utils.Tests.xproj", "{09C52F96-EFDD-4448-95EC-6D362DD60BAA}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RuntimeGraphGenerator", "tools\RuntimeGraphGenerator\RuntimeGraphGenerator.xproj", "{EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -591,6 +593,22 @@ Global {09C52F96-EFDD-4448-95EC-6D362DD60BAA}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {09C52F96-EFDD-4448-95EC-6D362DD60BAA}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {09C52F96-EFDD-4448-95EC-6D362DD60BAA}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Debug|x64.ActiveCfg = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Debug|x64.Build.0 = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Release|Any CPU.Build.0 = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Release|x64.ActiveCfg = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.Release|x64.Build.0 = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25}.RelWithDebInfo|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -629,5 +647,6 @@ Global {60C33D0A-A5D8-4AB0-9956-1F804654DF05} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {A28BD8AC-DF15-4F58-8299-98A9AE2B8726} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} {09C52F96-EFDD-4448-95EC-6D362DD60BAA} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} + {EFC4FE68-83EB-40E4-BFA8-61D0B4626F25} = {0722D325-24C8-4E83-B5AF-0A083E7F0749} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index 9a66d5edc..14dc04189 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": [ "src", "test" ] + "projects": [ "src", "test", "tools" ] } diff --git a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs index 60eb4bc77..b5111adbb 100644 --- a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; +using System.Text; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Graph; @@ -49,16 +51,41 @@ namespace Microsoft.Extensions.DependencyModel var compilationOptions = compilerOptions != null ? GetCompilationOptions(compilerOptions) : CompilationOptions.Default; + + var runtimeSignature = GenerateRuntimeSignature(runtimeExports); + return new DependencyContext( - target.DotNetFrameworkName, - runtime, - portable, + new TargetInfo(target.DotNetFrameworkName, runtime, runtimeSignature, portable), compilationOptions, GetLibraries(compilationExports, dependencyLookup, runtime: false).Cast(), GetLibraries(runtimeExports, dependencyLookup, runtime: true).Cast(), new RuntimeFallbacks[] {}); } + private static string GenerateRuntimeSignature(IEnumerable runtimeExports) + { + var sha1 = SHA1.Create(); + var builder = new StringBuilder(); + var packages = runtimeExports + .Where(libraryExport => libraryExport.Library.Identity.Type == LibraryType.Package); + var seperator = "|"; + foreach (var libraryExport in packages) + { + builder.Append(libraryExport.Library.Identity.Name); + builder.Append(seperator); + builder.Append(libraryExport.Library.Identity.Version.ToString()); + builder.Append(seperator); + } + var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(builder.ToString())); + + builder.Clear(); + foreach (var b in hash) + { + builder.AppendFormat("{0:x2}", b); + } + return builder.ToString(); + } + private static CompilationOptions GetCompilationOptions(CommonCompilerOptions compilerOptions) { return new CompilationOptions(compilerOptions.Defines, diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs index bd4a200f4..2ba03fcc3 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs @@ -10,21 +10,47 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.Extensions.DependencyModel { + public class TargetInfo + { + public TargetInfo(string framework, + string runtime, + string runtimeSignature, + bool isPortable) + { + if (string.IsNullOrEmpty(framework)) + { + throw new ArgumentException(nameof(framework)); + } + + Framework = framework; + Runtime = runtime; + RuntimeSignature = runtimeSignature; + IsPortable = isPortable; + } + + public string Framework { get; } + + public string Runtime { get; } + + public string RuntimeSignature { get; } + + public bool IsPortable { get; } + + } + public class DependencyContext { private static readonly Lazy _defaultContext = new Lazy(LoadDefault); - public DependencyContext(string targetFramework, - string runtime, - bool isPortable, + public DependencyContext(TargetInfo target, CompilationOptions compilationOptions, IEnumerable compileLibraries, IEnumerable runtimeLibraries, IEnumerable runtimeGraph) { - if (string.IsNullOrEmpty(targetFramework)) + if (target == null) { - throw new ArgumentException(nameof(targetFramework)); + throw new ArgumentNullException(nameof(target)); } if (compilationOptions == null) { @@ -43,9 +69,7 @@ namespace Microsoft.Extensions.DependencyModel throw new ArgumentNullException(nameof(runtimeGraph)); } - TargetFramework = targetFramework; - Runtime = runtime; - IsPortable = isPortable; + Target = target; CompilationOptions = compilationOptions; CompileLibraries = compileLibraries.ToArray(); RuntimeLibraries = runtimeLibraries.ToArray(); @@ -54,11 +78,7 @@ namespace Microsoft.Extensions.DependencyModel public static DependencyContext Default => _defaultContext.Value; - public string TargetFramework { get; } - - public string Runtime { get; } - - public bool IsPortable { get; } + public TargetInfo Target { get; } public CompilationOptions CompilationOptions { get; } @@ -76,9 +96,7 @@ namespace Microsoft.Extensions.DependencyModel } return new DependencyContext( - TargetFramework, - Runtime, - IsPortable, + Target, CompilationOptions, CompileLibraries.Union(other.CompileLibraries, new LibraryMergeEqualityComparer()), RuntimeLibraries.Union(other.RuntimeLibraries, new LibraryMergeEqualityComparer()), diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs index 110fcd459..13bee633d 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs @@ -35,8 +35,22 @@ namespace Microsoft.Extensions.DependencyModel var runtime = string.Empty; var target = string.Empty; var isPortable = true; + string runtimeTargetName = null; + string runtimeSignature = null; - var runtimeTargetName = root[DependencyContextStrings.RuntimeTargetPropertyName]?.Value(); + var runtimeTargetInfo = root[DependencyContextStrings.RuntimeTargetPropertyName]; + + // This fallback is temporary + if (runtimeTargetInfo is JValue) + { + runtimeTargetName = runtimeTargetInfo.Value(); + } + else + { + var runtimeTargetObject = (JObject) runtimeTargetInfo; + runtimeTargetName = runtimeTargetObject?[DependencyContextStrings.RuntimeTargetNamePropertyName]?.Value(); + runtimeSignature = runtimeTargetObject?[DependencyContextStrings.RuntimeTargetSignaturePropertyName]?.Value(); + } var libraryStubs = ReadLibraryStubs((JObject)root[DependencyContextStrings.LibrariesPropertyName]); var targetsObject = (JObject)root[DependencyContextStrings.TargetsPropertyName]; @@ -98,9 +112,7 @@ namespace Microsoft.Extensions.DependencyModel } return new DependencyContext( - target, - runtime, - isPortable, + new TargetInfo(target, runtime, runtimeSignature, isPortable), ReadCompilationOptions((JObject)root[DependencyContextStrings.CompilationOptionsPropertName]), ReadLibraries(compileTarget, false, libraryStubs).Cast().ToArray(), ReadLibraries(runtimeTarget, true, libraryStubs).Cast().ToArray(), diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs index 9cc4d5f6c..49630a971 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs @@ -71,7 +71,7 @@ namespace Microsoft.Extensions.DependencyModel context = LoadAssemblyContext(assembly); } - if (context?.IsPortable == true) + if (context?.Target.IsPortable == true) { var runtimeContext = LoadRuntimeContext(); if (runtimeContext != null) diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs index b5df3f7a3..393a1f493 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs @@ -57,6 +57,8 @@ namespace Microsoft.Extensions.DependencyModel internal const string RuntimeTargetNamePropertyName = "name"; + internal const string RuntimeTargetSignaturePropertyName = "signature"; + internal const string RuntimesPropertyName = "runtimes"; internal const string RuntimeTargetsPropertyName = "runtimeTargets"; diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs index 81c5cc9a7..858bc3316 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs @@ -48,11 +48,18 @@ namespace Microsoft.Extensions.DependencyModel return contextObject; } - private string WriteRuntimeTargetInfo(DependencyContext context) + private JObject WriteRuntimeTargetInfo(DependencyContext context) { - return context.IsPortable ? - context.TargetFramework : - context.TargetFramework + DependencyContextStrings.VersionSeperator + context.Runtime; + return new JObject( + new JProperty(DependencyContextStrings.RuntimeTargetNamePropertyName, + context.Target.IsPortable ? + context.Target.Framework : + context.Target.Framework + DependencyContextStrings.VersionSeperator + context.Target.Runtime + ), + new JProperty(DependencyContextStrings.RuntimeTargetSignaturePropertyName, + context.Target.RuntimeSignature + ) + ); } private JObject WriteRuntimeGraph(DependencyContext context) @@ -93,16 +100,16 @@ namespace Microsoft.Extensions.DependencyModel private JObject WriteTargets(DependencyContext context) { - if (context.IsPortable) + if (context.Target.IsPortable) { return new JObject( - new JProperty(context.TargetFramework, WritePortableTarget(context.RuntimeLibraries, context.CompileLibraries)) + new JProperty(context.Target.Framework, WritePortableTarget(context.RuntimeLibraries, context.CompileLibraries)) ); } return new JObject( - new JProperty(context.TargetFramework, WriteTarget(context.CompileLibraries)), - new JProperty(context.TargetFramework + DependencyContextStrings.VersionSeperator + context.Runtime, + new JProperty(context.Target.Framework, WriteTarget(context.CompileLibraries)), + new JProperty(context.Target.Framework + DependencyContextStrings.VersionSeperator + context.Target.Runtime, WriteTarget(context.RuntimeLibraries)) ); } diff --git a/src/corehost/cli/deps_format.cpp b/src/corehost/cli/deps_format.cpp index 889d51425..101b84953 100644 --- a/src/corehost/cli/deps_format.cpp +++ b/src/corehost/cli/deps_format.cpp @@ -319,7 +319,10 @@ bool deps_json_t::load(bool portable, const pal::string_t& deps_path, const rid_ const auto json = json_value::parse(file); const auto& runtime_target = json.at(_X("runtimeTarget")); - const pal::string_t& name = runtime_target.as_string(); + + const pal::string_t& name = runtime_target.is_string()? + runtime_target.as_string(): + runtime_target.at(_X("name")).as_string(); return (portable) ? load_portable(json, name, rid_fallback_graph) : load_standalone(json, name); } diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs index 24c8532c5..45966e37c 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs @@ -84,15 +84,15 @@ namespace Microsoft.Extensions.DependencyModel.Tests { var context = Build(portable: true); - context.IsPortable.Should().BeTrue(); + context.Target.IsPortable.Should().BeTrue(); } [Fact] public void FillsRuntimeAndTarget() { var context = Build(target: new NuGetFramework("SomeFramework",new Version(1,2)), runtime: "win8-x86"); - context.Runtime.Should().Be("win8-x86"); - context.TargetFramework.Should().Be("SomeFramework,Version=v1.2"); + context.Target.Runtime.Should().Be("win8-x86"); + context.Target.Framework.Should().Be("SomeFramework,Version=v1.2"); } [Fact] @@ -291,6 +291,19 @@ namespace Microsoft.Extensions.DependencyModel.Tests lib.Dependencies.Should().BeEmpty(); } + [Fact] + public void GeneratesRuntimeSignatureOutOfPackageNamesAndVersions() + { + var context = Build(runtimeExports: new[] + { + Export(PackageDescription("Pack.Age", new NuGetVersion(1, 2, 3))), + Export(PackageDescription("Pack.Age", new NuGetVersion(1, 2, 3))), + }); + + context.Target.RuntimeSignature.Should().Be("d0fc00006ed69e4aae80383dda08599a6892fd31"); + } + + private LibraryExport Export( LibraryDescription description, IEnumerable compilationAssemblies = null, diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs index dfe5ab3f1..af99a8fac 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs @@ -25,14 +25,16 @@ namespace Microsoft.Extensions.DependencyModel.Tests { var context = Read( @"{ - ""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"", + ""runtimeTarget"": { + ""name"":"".NETStandardApp,Version=v1.5/osx.10.10-x64"" + }, ""targets"": { "".NETStandardApp,Version=v1.5/osx.10.10-x64"": {}, } }"); - context.IsPortable.Should().BeFalse(); - context.TargetFramework.Should().Be(".NETStandardApp,Version=v1.5"); - context.Runtime.Should().Be("osx.10.10-x64"); + context.Target.IsPortable.Should().BeFalse(); + context.Target.Framework.Should().Be(".NETStandardApp,Version=v1.5"); + context.Target.Runtime.Should().Be("osx.10.10-x64"); } [Fact] @@ -44,7 +46,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests "".NETStandardApp,Version=v1.5"": {} } }"); - context.IsPortable.Should().BeTrue(); + context.Target.IsPortable.Should().BeTrue(); } [Fact] @@ -52,12 +54,14 @@ namespace Microsoft.Extensions.DependencyModel.Tests { var context = Read( @"{ - ""runtimeTarget"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"", + ""runtimeTarget"": { + ""name"": "".NETStandardApp,Version=v1.5/osx.10.10-x64"" + }, ""targets"": { "".NETStandardApp,Version=v1.5/osx.10.10-x64"": {} } }"); - context.IsPortable.Should().BeFalse(); + context.Target.IsPortable.Should().BeFalse(); } [Fact] @@ -69,7 +73,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests "".NETStandardApp,Version=v1.5"": {} } }"); - context.TargetFramework.Should().Be(".NETStandardApp,Version=v1.5"); + context.Target.Framework.Should().Be(".NETStandardApp,Version=v1.5"); } [Fact] @@ -152,7 +156,9 @@ namespace Microsoft.Extensions.DependencyModel.Tests { var context = Read( @"{ - ""runtimeTarget"": "".NETStandardApp,Version=v1.5"", + ""runtimeTarget"": { + ""name"": "".NETStandardApp,Version=v1.5"" + }, ""targets"": { "".NETStandardApp,Version=v1.5"": { ""MyApp/1.0.1"": { diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs index 5549d186a..f3d4841e9 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs @@ -37,12 +37,14 @@ namespace Microsoft.Extensions.DependencyModel.Tests CompilationOptions compilationOptions = null, CompilationLibrary[] compileLibraries = null, RuntimeLibrary[] runtimeLibraries = null, - IReadOnlyList runtimeGraph = null) + IReadOnlyList runtimeGraph = null, + string runtimeSignature = null) { - return new DependencyContext( + return new DependencyContext(new TargetInfo( target ?? "DefaultTarget", runtime ?? string.Empty, - isPortable ?? false, + runtimeSignature ?? string.Empty, + isPortable ?? false), compilationOptions ?? CompilationOptions.Default, compileLibraries ?? new CompilationLibrary[0], runtimeLibraries ?? new RuntimeLibrary[0], @@ -80,10 +82,13 @@ namespace Microsoft.Extensions.DependencyModel.Tests var result = Save(Create( "Target", "runtime", - false) + false, + runtimeSignature: "runtimeSignature") ); - - result.Should().HavePropertyValue("runtimeTarget", "Target/runtime"); + result.Should().HavePropertyAsObject("runtimeTarget") + .Which.Should().HavePropertyValue("name", "Target/runtime"); + result.Should().HavePropertyAsObject("runtimeTarget") + .Which.Should().HavePropertyValue("signature", "runtimeSignature"); } [Fact] @@ -92,9 +97,13 @@ namespace Microsoft.Extensions.DependencyModel.Tests var result = Save(Create( "Target", "runtime", - true) + true, + runtimeSignature: "runtimeSignature") ); - result.Should().HavePropertyValue("runtimeTarget", "Target"); + result.Should().HavePropertyAsObject("runtimeTarget") + .Which.Should().HavePropertyValue("name", "Target"); + result.Should().HavePropertyAsObject("runtimeTarget") + .Which.Should().HavePropertyValue("signature", "runtimeSignature"); } [Fact] diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs index 2a996495a..76f819878 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs @@ -39,18 +39,14 @@ namespace Microsoft.Extensions.DependencyModel.Tests }; var context = new DependencyContext( - "Framework", - "runtime", - true, + CreateTargetInfo(), CompilationOptions.Default, compilationLibraries, runtimeLibraries, new RuntimeFallbacks[] { }); var contextRedist = new DependencyContext( - "Framework", - "runtime", - true, + CreateTargetInfo(), CompilationOptions.Default, compilationLibrariesRedist, runtimeLibrariesRedist, @@ -76,9 +72,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests public void MergeMergesRuntimeGraph() { var context = new DependencyContext( - "Framework", - "runtime", - true, + CreateTargetInfo(), CompilationOptions.Default, Enumerable.Empty(), Enumerable.Empty(), @@ -88,9 +82,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests }); var contextRedist = new DependencyContext( - "Framework", - "runtime", - true, + CreateTargetInfo(), CompilationOptions.Default, Enumerable.Empty(), Enumerable.Empty(), @@ -106,6 +98,15 @@ namespace Microsoft.Extensions.DependencyModel.Tests Subject.Fallbacks.Should().BeEquivalentTo("win7-x64", "win7-x86"); } + private TargetInfo CreateTargetInfo() + { + return new TargetInfo( + "Framework", + "runtime", + "runtimeSignature", + true); + } + private CompilationLibrary CreateCompilation(string name) { return new CompilationLibrary( diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs index de0f52256..b23d8e3a4 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs @@ -16,10 +16,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests [InlineData("FlibbidyFlob", "FlibbidyFlob")] public void GetRuntimeAssemblyNamesExtractsCorrectAssemblyName(string path, string expected) { - var context = new DependencyContext( - ".NETStandard,Version=v1.3", - string.Empty, - isPortable: true, + var context = new DependencyContext(new TargetInfo(".NETStandard,Version=v1.3", string.Empty, string.Empty, true), compilationOptions: CompilationOptions.Default, compileLibraries: new CompilationLibrary[] { }, runtimeLibraries: new[] { @@ -94,10 +91,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests private DependencyContext BuildTestContext() { - return new DependencyContext( - ".NETStandard,Version=v1.3", - string.Empty, - isPortable: true, + return new DependencyContext(new TargetInfo(".NETStandard,Version=v1.3", string.Empty, string.Empty, true), compilationOptions: CompilationOptions.Default, compileLibraries: new[] { diff --git a/tools/RuntimeGraphGenerator/Program.cs b/tools/RuntimeGraphGenerator/Program.cs index 09253af49..ebf1ff29a 100644 --- a/tools/RuntimeGraphGenerator/Program.cs +++ b/tools/RuntimeGraphGenerator/Program.cs @@ -69,7 +69,7 @@ namespace RuntimeGraphGenerator { context = new DependencyContextJsonReader().Read(depsStream); } - var framework = NuGetFramework.Parse(context.TargetFramework); + var framework = NuGetFramework.Parse(context.Target.Framework); var projectContext = ProjectContext.Create(projectDirectory, framework); // Configuration is used only for P2P dependencies so were don't care @@ -79,9 +79,7 @@ namespace RuntimeGraphGenerator var expandedGraph = manager.Expand(graph, runtimes); context = new DependencyContext( - context.TargetFramework, - context.Runtime, - context.IsPortable, + context.Target, context.CompilationOptions, context.CompileLibraries, context.RuntimeLibraries,