Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add support for the "path" property in the .deps.json file
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Aug 11, 2016
1 parent d93d40d commit 7252718
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 32 deletions.
61 changes: 60 additions & 1 deletion Microsoft.DotNet.CoreSetup.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A29E8E3-A0FC-4C57-81DD-297B56D1A119}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -31,6 +31,14 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-deb-tool", "tools\do
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestUtils", "test\TestUtils\TestUtils.xproj", "{42095367-4423-4157-BD31-D1A8E3B823B9}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.InternalAbstractions", "src\Microsoft.DotNet.PlatformAbstractions\Microsoft.DotNet.InternalAbstractions.xproj", "{BD4F0750-4E81-4AD2-90B5-E470881792C3}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DependencyModel", "src\Microsoft.Extensions.DependencyModel\Microsoft.Extensions.DependencyModel.xproj", "{688870C8-9843-4F9E-8576-D39290AD0F25}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DependencyModel.Tests", "test\Microsoft.Extensions.DependencyModel.Tests\Microsoft.Extensions.DependencyModel.Tests.xproj", "{4A4711D8-4312-49FC-87B5-4F183F4C6A51}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FAA448DA-7D1C-4481-915D-5765BF906332}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -171,6 +179,54 @@ Global
{42095367-4423-4157-BD31-D1A8E3B823B9}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{42095367-4423-4157-BD31-D1A8E3B823B9}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{42095367-4423-4157-BD31-D1A8E3B823B9}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Debug|x64.Build.0 = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Release|Any CPU.Build.0 = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Release|x64.ActiveCfg = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.Release|x64.Build.0 = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{BD4F0750-4E81-4AD2-90B5-E470881792C3}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Debug|x64.ActiveCfg = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Debug|x64.Build.0 = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Release|Any CPU.Build.0 = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Release|x64.ActiveCfg = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.Release|x64.Build.0 = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{688870C8-9843-4F9E-8576-D39290AD0F25}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|x64.ActiveCfg = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|x64.Build.0 = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|Any CPU.Build.0 = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|x64.ActiveCfg = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|x64.Build.0 = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -184,5 +240,8 @@ Global
{386D412C-003C-47B1-8258-0E35865CB7C4} = {5CE8410C-3100-4F41-8FA9-E6B4132D9703}
{F39F3D8B-B26F-4C77-B08C-D6CA753EE84E} = {0722D325-24C8-4E83-B5AF-0A083E7F0749}
{42095367-4423-4157-BD31-D1A8E3B823B9} = {5CE8410C-3100-4F41-8FA9-E6B4132D9703}
{BD4F0750-4E81-4AD2-90B5-E470881792C3} = {FAA448DA-7D1C-4481-915D-5765BF906332}
{688870C8-9843-4F9E-8576-D39290AD0F25} = {FAA448DA-7D1C-4481-915D-5765BF906332}
{4A4711D8-4312-49FC-87B5-4F183F4C6A51} = {5CE8410C-3100-4F41-8FA9-E6B4132D9703}
EndGlobalSection
EndGlobal
14 changes: 13 additions & 1 deletion src/Microsoft.Extensions.DependencyModel/CompilationLibrary.cs
Expand Up @@ -17,7 +17,19 @@ public class CompilationLibrary : Library
IEnumerable<string> assemblies,
IEnumerable<Dependency> dependencies,
bool serviceable)
: base(type, name, version, hash, dependencies, serviceable)
: this(type, name, version, hash, assemblies, dependencies, serviceable, path: null)
{
}

public CompilationLibrary(string type,
string name,
string version,
string hash,
IEnumerable<string> assemblies,
IEnumerable<Dependency> dependencies,
bool serviceable,
string path)
: base(type, name, version, hash, dependencies, serviceable, path)
{
if (assemblies == null)
{
Expand Down
Expand Up @@ -496,6 +496,7 @@ private LibraryStub ReadOneLibrary(JsonTextReader reader)
string hash = null;
string type = null;
bool serviceable = false;
string path = null;

reader.ReadStartObject();

Expand All @@ -512,6 +513,9 @@ private LibraryStub ReadOneLibrary(JsonTextReader reader)
case DependencyContextStrings.ServiceablePropertyName:
serviceable = reader.ReadAsBoolean().GetValueOrDefault(false);
break;
case DependencyContextStrings.PathPropertyName:
path = reader.ReadAsString();
break;
default:
throw new FormatException($"Unknown property name '{reader.Value}'");
}
Expand All @@ -523,7 +527,8 @@ private LibraryStub ReadOneLibrary(JsonTextReader reader)
{
Hash = hash,
Type = Pool(type),
Serviceable = serviceable
Serviceable = serviceable,
Path = path
};
}

Expand Down Expand Up @@ -632,12 +637,21 @@ private Library CreateLibrary(TargetLibrary targetLibrary, bool runtime, Diction
nativeLibraryGroups: nativeLibraryGroups,
resourceAssemblies: targetLibrary.Resources ?? Enumerable.Empty<ResourceAssembly>(),
dependencies: targetLibrary.Dependencies,
serviceable: stub.Serviceable);
serviceable: stub.Serviceable,
path: stub.Path);
}
else
{
var assemblies = (targetLibrary.Compilations != null) ? targetLibrary.Compilations : Enumerable.Empty<string>();
return new CompilationLibrary(stub.Type, name, version, stub.Hash, assemblies, targetLibrary.Dependencies, stub.Serviceable);
return new CompilationLibrary(
stub.Type,
name,
version,
stub.Hash,
assemblies,
targetLibrary.Dependencies,
stub.Serviceable,
stub.Path);
}
}

Expand Down Expand Up @@ -699,6 +713,8 @@ private struct LibraryStub
public string Type;

public bool Serviceable;

public string Path;
}
}
}
Expand Up @@ -23,6 +23,8 @@ internal class DependencyContextStrings

internal const string Sha512PropertyName = "sha512";

internal const string PathPropertyName = "path";

internal const string TypePropertyName = "type";

internal const string ServiceablePropertyName = "serviceable";
Expand Down
Expand Up @@ -143,6 +143,7 @@ private JObject WritePortableTarget(IReadOnlyList<RuntimeLibrary> runtimeLibrari
Debug.Assert(compilationLibrary.Version == runtimeLibrary.Version);
Debug.Assert(compilationLibrary.Hash == runtimeLibrary.Hash);
Debug.Assert(compilationLibrary.Type == runtimeLibrary.Type);
Debug.Assert(compilationLibrary.Path == runtimeLibrary.Path);
}

var library = (Library)compilationLibrary ?? (Library)runtimeLibrary;
Expand Down Expand Up @@ -329,8 +330,8 @@ private JObject WriteLibrary(Library library)
return new JObject(
new JProperty(DependencyContextStrings.TypePropertyName, library.Type),
new JProperty(DependencyContextStrings.ServiceablePropertyName, library.Serviceable),
new JProperty(DependencyContextStrings.Sha512PropertyName, library.Hash)
);
new JProperty(DependencyContextStrings.Sha512PropertyName, library.Hash),
new JProperty(DependencyContextStrings.PathPropertyName, library.Path));
}

private string NormalizePath(string path)
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.Extensions.DependencyModel/Library.cs
Expand Up @@ -10,6 +10,11 @@ namespace Microsoft.Extensions.DependencyModel
public class Library
{
public Library(string type, string name, string version, string hash, IEnumerable<Dependency> dependencies, bool serviceable)
: this(type, name, version, hash, dependencies, serviceable, path: null)
{
}

public Library(string type, string name, string version, string hash, IEnumerable<Dependency> dependencies, bool serviceable, string path)
{
if (string.IsNullOrEmpty(type))
{
Expand All @@ -33,6 +38,7 @@ public Library(string type, string name, string version, string hash, IEnumerabl
Hash = hash;
Dependencies = dependencies.ToArray();
Serviceable = serviceable;
Path = path;
}

public string Type { get; }
Expand All @@ -46,5 +52,7 @@ public Library(string type, string name, string version, string hash, IEnumerabl
public IReadOnlyList<Dependency> Dependencies { get; }

public bool Serviceable { get; }

public string Path { get; }
}
}
17 changes: 16 additions & 1 deletion src/Microsoft.Extensions.DependencyModel/RuntimeLibrary.cs
Expand Up @@ -19,7 +19,22 @@ public class RuntimeLibrary : Library
IEnumerable<ResourceAssembly> resourceAssemblies,
IEnumerable<Dependency> dependencies,
bool serviceable)
: base(type, name, version, hash, dependencies, serviceable)
: this(type, name, version, hash, runtimeAssemblyGroups, nativeLibraryGroups, resourceAssemblies, dependencies, serviceable, path: null)
{
}

public RuntimeLibrary(
string type,
string name,
string version,
string hash,
IReadOnlyList<RuntimeAssetGroup> runtimeAssemblyGroups,
IReadOnlyList<RuntimeAssetGroup> nativeLibraryGroups,
IEnumerable<ResourceAssembly> resourceAssemblies,
IEnumerable<Dependency> dependencies,
bool serviceable,
string path)
: base(type, name, version, hash, dependencies, serviceable, path)
{
if (runtimeAssemblyGroups == null)
{
Expand Down
Expand Up @@ -19,6 +19,7 @@ public class DependencyContextBuilderTests
private NuGetFramework _defaultFramework;
private string _defaultName = "Library.Name";
private string _defaultHash = "Hash";
private string _defaultPath = "the/Package/PATH";
private NuGetVersion _defaultVersion = new NuGetVersion(1, 2, 3, new []{"dev"}, string.Empty);

public DependencyContext Build(CommonCompilerOptions compilerOptions = null,
Expand Down Expand Up @@ -136,7 +137,8 @@ public void FillsRuntimeLibraryProperties()
new VersionRange(new NuGetVersion(2, 1, 2)),
LibraryType.ReferenceAssembly,
LibraryDependencyType.Default)
}),
},
path: "path/TO/package"),
resourceAssemblies: new[]
{
new LibraryResourceAssembly(
Expand Down Expand Up @@ -176,6 +178,9 @@ public void FillsRuntimeLibraryProperties()
lib.Dependencies.Should().OnlyContain(l => l.Name == "System.Collections" && l.Version == "3.3.3");
lib.ResourceAssemblies.Should().OnlyContain(l => l.Path == "en-US/Pack.Age.resources.dll" && l.Locale == "en-US");

// When ProjectModel supports path in the lock file library, this should assert "path/TO/package".
lib.Path.Should().BeNull();

lib.RuntimeAssemblyGroups.GetDefaultAssets().Should().OnlyContain(l => l == "lib/Pack.Age.dll");
lib.RuntimeAssemblyGroups.GetRuntimeAssets("win8-x64").Should().OnlyContain(l => l == "win8-x64/Pack.Age.dll");
lib.NativeLibraryGroups.GetRuntimeAssets("win8-x64").Should().OnlyContain(l => l == "win8-x64/Pack.Age.native.dll");
Expand All @@ -186,6 +191,7 @@ public void FillsRuntimeLibraryProperties()
asm.Hash.Should().BeEmpty();
asm.Dependencies.Should().BeEmpty();
asm.RuntimeAssemblyGroups.GetDefaultAssets().Should().OnlyContain(l => l == "System.Collections.dll");
asm.Path.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -232,7 +238,8 @@ public void FillsCompileLibraryProperties()
new VersionRange(new NuGetVersion(2, 1, 2)),
LibraryType.ReferenceAssembly,
LibraryDependencyType.Default)
}),
},
path: "path/TO/package"),
compilationAssemblies: new[]
{
new LibraryAsset("Dll", "lib/Pack.Age.dll", ""),
Expand All @@ -256,12 +263,16 @@ public void FillsCompileLibraryProperties()
lib.Dependencies.Should().OnlyContain(l => l.Name == "System.Collections" && l.Version == "3.3.3");
lib.Assemblies.Should().OnlyContain(a => a == "lib/Pack.Age.dll");

// When ProjectModel supports path in the lock file library, this should assert "path/TO/package".
lib.Path.Should().BeNull();

var asm = context.CompileLibraries.Should().Contain(l => l.Name == "System.Collections").Subject;
asm.Type.Should().Be("referenceassembly");
asm.Version.Should().Be("3.3.3");
asm.Hash.Should().BeEmpty();
asm.Dependencies.Should().BeEmpty();
asm.Assemblies.Should().OnlyContain(a => a == "System.Collections.dll");
asm.Path.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -354,8 +365,12 @@ public void GeneratesRuntimeSignatureOutOfPackageNamesAndVersions()
NuGetVersion version = null,
string hash = null,
IEnumerable<LibraryRange> dependencies = null,
bool? servicable = null)
bool? servicable = null,
string path = null)
{
// The LockFilePackageLibrary type in Microsoft.DotNet.ProjectModel currently does not
// support the "path" property. Therefore, the path property to this method is ignored
// and calling tests should assert that the value is not plumbed through.
return new PackageDescription(
"PATH",
new LockFilePackageLibrary()
Expand Down Expand Up @@ -406,7 +421,5 @@ public void GeneratesRuntimeSignatureOutOfPackageNamesAndVersions()
true,
true);
}


}
}

0 comments on commit 7252718

Please sign in to comment.