Skip to content

Commit

Permalink
Fix issue with paths in deps.json not being normalized to have /, als…
Browse files Browse the repository at this point in the history
…o moves rid graph section to root leve instead of being inside arget subsection
  • Loading branch information
pakrym committed Mar 10, 2016
1 parent ccf1a8b commit 5214d17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
27 changes: 16 additions & 11 deletions src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ public void Write(DependencyContext context, Stream stream)

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)
Expand All @@ -46,11 +50,7 @@ private string WriteRuntimeTargetInfo(DependencyContext context)
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)))
);
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private void AddResourceAssemblies(JObject libraryObject, IEnumerable<ResourceAs
}
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))))
)
);
}
Expand Down Expand Up @@ -263,7 +263,7 @@ private IEnumerable<JProperty> WriteRuntimeTargetAssemblies(IEnumerable<string>
{
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)
Expand All @@ -274,7 +274,7 @@ private IEnumerable<JProperty> WriteRuntimeTargetAssemblies(IEnumerable<string>

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)
Expand All @@ -294,5 +294,10 @@ private JObject WriteLibrary(Library library)
new JProperty(DependencyContextStrings.Sha512PropertyName, library.Hash)
);
}

private string NormalizePath(string path)
{
return path.Replace('\\', '/');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public void SavesRuntimeGraph()
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")
Expand Down Expand Up @@ -159,7 +156,7 @@ public void WritesRuntimeLibrariesToRuntimeTarget()
{
new RuntimeTarget("win7-x64",
new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") },
new [] { "Banana.Win7-x64.so" }
new [] { "native\\Banana.Win7-x64.so" }
)
},
new [] {
Expand All @@ -184,12 +181,12 @@ public void WritesRuntimeLibrariesToRuntimeTarget()
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
Expand Down

0 comments on commit 5214d17

Please sign in to comment.