Skip to content

Commit

Permalink
put 'native' section in to runtime targets for deps file
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed Mar 14, 2016
1 parent dc11ed2 commit 008a1ad
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private Library GetLibrary(LibraryExport export,
export.Library.Identity.Version.ToString(),
export.Library.Hash,
assemblies.Select(RuntimeAssembly.Create),
export.NativeLibraries.Select(l => l.RelativePath),
export.ResourceAssemblies.Select(CreateResourceAssembly),
export.RuntimeTargets.Select(CreateRuntimeTarget),
libraryDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public DependencyContext Read(Stream stream)
version: identity.Item3,
hash: identity.Item4,
assemblies: packageGroup.Select(l => RuntimeAssembly.Create(l.AssetPath)),
nativeLibraries: Enumerable.Empty<string>(),
resourceAssemblies: Enumerable.Empty<ResourceAssembly>(),
subTargets: Enumerable.Empty<RuntimeTarget>(),
dependencies: Enumerable.Empty<Dependency>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ private Library ReadLibrary(JProperty property, bool runtime, Dictionary<string,
));
}

var assemblies = ReadAssemblies(libraryObject, DependencyContextStrings.RuntimeAssembliesKey)
var assemblies = ReadAssetList(libraryObject, DependencyContextStrings.RuntimeAssembliesKey)
.Select(RuntimeAssembly.Create)
.ToArray();

var nativeLibraries = ReadAssetList(libraryObject, DependencyContextStrings.NativeLibrariesKey);

var resourceAssemblies = ReadResourceAssemblies((JObject)libraryObject[DependencyContextStrings.ResourceAssembliesPropertyName]);

return new RuntimeLibrary(
Expand All @@ -181,14 +183,15 @@ private Library ReadLibrary(JProperty property, bool runtime, Dictionary<string,
version: version,
hash: stub.Hash,
assemblies: assemblies,
nativeLibraries: nativeLibraries,
resourceAssemblies: resourceAssemblies,
subTargets: runtimeTargets.ToArray(),
dependencies: dependencies,
serviceable: stub.Serviceable);
}
else
{
var assemblies = ReadAssemblies(libraryObject, DependencyContextStrings.CompileTimeAssembliesKey);
var assemblies = ReadAssetList(libraryObject, DependencyContextStrings.CompileTimeAssembliesKey);
return new CompilationLibrary(stub.Type, name, version, stub.Hash, assemblies, dependencies, stub.Serviceable);
}
}
Expand Down Expand Up @@ -226,7 +229,7 @@ private static IEnumerable<RuntimeTargetEntryStub> ReadRuntimeTargetEntries(JObj
}
}

private static string[] ReadAssemblies(JObject libraryObject, string name)
private static string[] ReadAssetList(JObject libraryObject, string name)
{
var assembliesObject = (JObject) libraryObject[name];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal class DependencyContextStrings

internal const string RuntimeAssembliesKey = "runtime";

internal const string NativeLibrariesKey = "native";

internal const string RuntimeTargetPropertyName = "runtimeTarget";

internal const string LibrariesPropertyName = "libraries";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void AddCompilationAssemblies(JObject libraryObject, IEnumerable<string>
return;
}
libraryObject.Add(new JProperty(DependencyContextStrings.CompileTimeAssembliesKey,
WriteAssemblies(compilationAssemblies))
WriteAssetList(compilationAssemblies))
);
}

Expand All @@ -158,7 +158,7 @@ private void AddRuntimeAssemblies(JObject libraryObject, IEnumerable<RuntimeAsse
return;
}
libraryObject.Add(new JProperty(DependencyContextStrings.RuntimeAssembliesKey,
WriteAssemblies(runtimeAssemblies.Select(a => a.Path)))
WriteAssetList(runtimeAssemblies.Select(a => a.Path)))
);
}

Expand Down Expand Up @@ -197,6 +197,12 @@ private JObject WriteTargetLibrary(Library library)
AddDependencies(libraryObject, runtimeLibrary.Dependencies);
AddRuntimeAssemblies(libraryObject, runtimeLibrary.Assemblies);
AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies);

if (runtimeLibrary.NativeLibraries.Any())
{
libraryObject.Add(DependencyContextStrings.NativeLibrariesKey, WriteAssetList(runtimeLibrary.NativeLibraries));
}

return libraryObject;
}

Expand All @@ -213,7 +219,6 @@ private JObject WriteTargetLibrary(Library library)

private JObject WritePortableTargetLibrary(RuntimeLibrary runtimeLibrary, CompilationLibrary compilationLibrary)
{

var libraryObject = new JObject();

var dependencies = new HashSet<Dependency>();
Expand All @@ -229,6 +234,7 @@ private JObject WritePortableTargetLibrary(RuntimeLibrary runtimeLibrary, Compil
}
AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies);
AddRuntimeAssemblies(libraryObject, runtimeLibrary.Assemblies);
libraryObject.Add(DependencyContextStrings.NativeLibrariesKey, WriteAssetList(runtimeLibrary.NativeLibraries));

dependencies.UnionWith(runtimeLibrary.Dependencies);
}
Expand Down Expand Up @@ -272,9 +278,9 @@ private IEnumerable<JProperty> WriteRuntimeTargetAssemblies(IEnumerable<string>
}
}

private JObject WriteAssemblies(IEnumerable<string> assemblies)
private JObject WriteAssetList(IEnumerable<string> assetPaths)
{
return new JObject(assemblies.Select(assembly => new JProperty(NormalizePath(assembly), new JObject())));
return new JObject(assetPaths.Select(assembly => new JProperty(NormalizePath(assembly), new JObject())));
}

private JObject WriteLibraries(DependencyContext context)
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.Extensions.DependencyModel/RuntimeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public RuntimeLibrary(
string version,
string hash,
IEnumerable<RuntimeAssembly> assemblies,
IEnumerable<string> nativeLibraries,
IEnumerable<ResourceAssembly> resourceAssemblies,
IEnumerable<RuntimeTarget> subTargets,
IEnumerable<Dependency> dependencies,
Expand All @@ -23,9 +24,12 @@ public RuntimeLibrary(
Assemblies = assemblies.ToArray();
ResourceAssemblies = resourceAssemblies.ToArray();
RuntimeTargets = subTargets.ToArray();
NativeLibraries = nativeLibraries.ToArray();
}

public IReadOnlyList<RuntimeAssembly> Assemblies { get; }

public IReadOnlyList<string> NativeLibraries { get; }

public IReadOnlyList<ResourceAssembly> ResourceAssemblies { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void WritesRuntimeLibrariesToRuntimeTarget()
"1.2.3",
"HASH",
new [] { RuntimeAssembly.Create("Banana.dll")},
new [] { "runtimes\\linux\\native\\native.so" },
new [] { new ResourceAssembly("en-US\\Banana.Resource.dll", "en-US")},
new []
{
Expand All @@ -172,8 +173,11 @@ public void WritesRuntimeLibrariesToRuntimeTarget()
var library = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject;
dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");

library.Should().HavePropertyAsObject("runtime")
.Subject.Should().HaveProperty("Banana.dll");
library.Should().HavePropertyAsObject("native")
.Subject.Should().HaveProperty("runtimes/linux/native/native.so");

var runtimeTargets = library.Should().HavePropertyAsObject("runtimeTargets").Subject;

Expand Down Expand Up @@ -226,6 +230,7 @@ public void MergesRuntimeAndCompileLibrariesForPortable()
"1.2.3",
"HASH",
new [] { RuntimeAssembly.Create("Banana.dll")},
new [] { "native.dll" },
new ResourceAssembly[] {},
new []
{
Expand All @@ -247,8 +252,11 @@ public void MergesRuntimeAndCompileLibrariesForPortable()
var library = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject;
dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");

library.Should().HavePropertyAsObject("runtime")
.Subject.Should().HaveProperty("Banana.dll");
library.Should().HavePropertyAsObject("native")
.Subject.Should().HaveProperty("native.dll");

library.Should().HavePropertyAsObject("compile")
.Subject.Should().HaveProperty("ref/Banana.dll");
Expand Down Expand Up @@ -286,6 +294,7 @@ public void WritesRuntimeTargetForNonPortable()
"1.2.3",
"HASH",
new [] { RuntimeAssembly.Create("Banana.dll")},
new [] { "runtimes\\osx\\native\\native.dylib" },
new ResourceAssembly[] {},
new RuntimeTarget[] {},
new [] {
Expand All @@ -303,6 +312,8 @@ public void WritesRuntimeTargetForNonPortable()
dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");
library.Should().HavePropertyAsObject("runtime")
.Subject.Should().HaveProperty("Banana.dll");
library.Should().HavePropertyAsObject("native")
.Subject.Should().HaveProperty("runtimes/osx/native/native.dylib");

//libraries
var libraries = result.Should().HavePropertyAsObject("libraries").Subject;
Expand All @@ -327,6 +338,7 @@ public void WritesResourceAssembliesForNonPortable()
"1.2.3",
"HASH",
new RuntimeAssembly[] { },
new string[] { },
new []
{
new ResourceAssembly("en-US/Fruits.resources.dll", "en-US")
Expand Down Expand Up @@ -361,6 +373,7 @@ public void WritesResourceAssembliesForPortable()
"1.2.3",
"HASH",
new RuntimeAssembly[] { },
new string[] { },
new []
{
new ResourceAssembly("en-US/Fruits.resources.dll", "en-US")
Expand Down

0 comments on commit 008a1ad

Please sign in to comment.