From 5214d176cd5081967f444c4f0f4684d9cd64153b Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 10 Mar 2016 12:18:05 -0800 Subject: [PATCH] Fix issue with paths in deps.json not being normalized to have /, also moves rid graph section to root leve instead of being inside arget subsection --- .../DependencyContextWriter.cs | 27 +++++++++++-------- .../DependencyContextJsonWriterTests.cs | 11 +++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs index 18dea9304..2f26e8c49 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs @@ -27,13 +27,17 @@ namespace Microsoft.Extensions.DependencyModel private JObject Write(DependencyContext context) { - return new JObject( + var contextObject = new JObject( new JProperty(DependencyContextStrings.RuntimeTargetPropertyName, WriteRuntimeTargetInfo(context)), new JProperty(DependencyContextStrings.CompilationOptionsPropertName, WriteCompilationOptions(context.CompilationOptions)), new JProperty(DependencyContextStrings.TargetsPropertyName, WriteTargets(context)), - new JProperty(DependencyContextStrings.LibrariesPropertyName, WriteLibraries(context)), - new JProperty(DependencyContextStrings.RuntimesPropertyName, WriteRuntimeGraph(context)) + new JProperty(DependencyContextStrings.LibrariesPropertyName, WriteLibraries(context)) ); + if (context.RuntimeGraph.Any()) + { + contextObject.Add(new JProperty(DependencyContextStrings.RuntimesPropertyName, WriteRuntimeGraph(context))); + } + return contextObject; } private string WriteRuntimeTargetInfo(DependencyContext context) @@ -46,11 +50,7 @@ namespace Microsoft.Extensions.DependencyModel private JObject WriteRuntimeGraph(DependencyContext context) { return new JObject( - new JProperty(context.TargetFramework, - new JObject( - context.RuntimeGraph.Select(g => new JProperty(g.Key, new JArray(g.Value))) - ) - ) + context.RuntimeGraph.Select(g => new JProperty(g.Key, new JArray(g.Value))) ); } @@ -183,7 +183,7 @@ namespace Microsoft.Extensions.DependencyModel } libraryObject.Add(DependencyContextStrings.ResourceAssembliesPropertyName, new JObject(resourceAssemblies.Select(a => - new JProperty(a.Path, new JObject(new JProperty(DependencyContextStrings.LocalePropertyName, a.Locale)))) + new JProperty(NormalizePath(a.Path), new JObject(new JProperty(DependencyContextStrings.LocalePropertyName, a.Locale)))) ) ); } @@ -263,7 +263,7 @@ namespace Microsoft.Extensions.DependencyModel { foreach (var assembly in assemblies) { - yield return new JProperty(assembly, + yield return new JProperty(NormalizePath(assembly), new JObject( new JProperty(DependencyContextStrings.RidPropertyName, runtime), new JProperty(DependencyContextStrings.AssetTypePropertyName, assetType) @@ -274,7 +274,7 @@ namespace Microsoft.Extensions.DependencyModel private JObject WriteAssemblies(IEnumerable assemblies) { - return new JObject(assemblies.Select(assembly => new JProperty(assembly, new JObject()))); + return new JObject(assemblies.Select(assembly => new JProperty(NormalizePath(assembly), new JObject()))); } private JObject WriteLibraries(DependencyContext context) @@ -294,5 +294,10 @@ namespace Microsoft.Extensions.DependencyModel new JProperty(DependencyContextStrings.Sha512PropertyName, library.Hash) ); } + + private string NormalizePath(string path) + { + return path.Replace('\\', '/'); + } } } diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs index 2c0b76840..cafc90bf2 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs @@ -62,10 +62,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests new KeyValuePair("win8-x64", new [] { "win7-x64"}), })); - var runtimes = result.Should().HaveProperty("runtimes") - .Subject.Should().BeOfType().Subject; - - var rids = runtimes.Should().HaveProperty("Target") + var rids = result.Should().HaveProperty("runtimes") .Subject.Should().BeOfType().Subject; rids.Should().HaveProperty("win7-x64") @@ -159,7 +156,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests { new RuntimeTarget("win7-x64", new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") }, - new [] { "Banana.Win7-x64.so" } + new [] { "native\\Banana.Win7-x64.so" } ) }, new [] { @@ -184,12 +181,12 @@ namespace Microsoft.Extensions.DependencyModel.Tests runtimeAssembly.Should().HavePropertyValue("rid", "win7-x64"); runtimeAssembly.Should().HavePropertyValue("assetType", "runtime"); - var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.so").Subject; + var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("native/Banana.Win7-x64.so").Subject; nativeLibrary.Should().HavePropertyValue("rid", "win7-x64"); nativeLibrary.Should().HavePropertyValue("assetType", "native"); var resourceAssemblies = library.Should().HavePropertyAsObject("resources").Subject; - var resourceAssembly = resourceAssemblies.Should().HavePropertyAsObject("en-US\\Banana.Resource.dll").Subject; + var resourceAssembly = resourceAssemblies.Should().HavePropertyAsObject("en-US/Banana.Resource.dll").Subject; resourceAssembly.Should().HavePropertyValue("locale", "en-US"); //libraries