Merge pull request #1801 from dotnet/pakrym/deps-rids-paths

Fix issue with paths in deps.json not being normalized to have `/`
This commit is contained in:
Pavel Krymets 2016-03-10 15:20:36 -08:00
commit 5a121215cd
2 changed files with 20 additions and 18 deletions

View file

@ -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<string> 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('\\', '/');
}
}
}

View file

@ -62,10 +62,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
new KeyValuePair<string, string[]>("win8-x64", new [] { "win7-x64"}),
}));
var runtimes = result.Should().HaveProperty("runtimes")
.Subject.Should().BeOfType<JObject>().Subject;
var rids = runtimes.Should().HaveProperty("Target")
var rids = result.Should().HaveProperty("runtimes")
.Subject.Should().BeOfType<JObject>().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