Trim platfrom libraries from deps fiels

This commit is contained in:
Pavel Krymets 2016-06-14 14:55:59 -07:00
parent 191812690d
commit 6b54ae0bcc
8 changed files with 113 additions and 14 deletions

View file

@ -157,9 +157,12 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
private void WriteDepsFileAndCopyProjectDependencies(LibraryExporter exporter)
{
// When called this way we don't need to filter exports, so we pass the same list to both.
var exports = exporter.GetAllExports().ToList();
WriteConfigurationFiles(exports, exports, includeDevConfig: true);
var exportsLookup = exports.ToDictionary(e => e.Library.Identity.Name);
var platformExclusionList = _context.GetPlatformExclusionList(exportsLookup);
var filteredExports = exports.FilterExports(platformExclusionList);
WriteConfigurationFiles(exports, filteredExports, exports, includeDevConfig: true);
var projectExports = exporter.GetAllProjectTypeDependencies();
CopyAssemblies(projectExports);
@ -169,9 +172,13 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
CopyAssets(packageExports);
}
public void WriteConfigurationFiles(IEnumerable<LibraryExport> allExports, IEnumerable<LibraryExport> depsExports, bool includeDevConfig)
public void WriteConfigurationFiles(
IEnumerable<LibraryExport> allExports,
IEnumerable<LibraryExport> depsRuntimeExports,
IEnumerable<LibraryExport> depsCompilationExports,
bool includeDevConfig)
{
WriteDeps(depsExports);
WriteDeps(depsRuntimeExports, depsCompilationExports);
if (_context.ProjectFile.HasRuntimeOutput(_configuration))
{
WriteRuntimeConfig(allExports);
@ -272,7 +279,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
runtimeOptions.Add("additionalProbingPaths", additionalProbingPaths);
}
public void WriteDeps(IEnumerable<LibraryExport> exports)
public void WriteDeps(IEnumerable<LibraryExport> runtimeExports, IEnumerable<LibraryExport> compilationExports)
{
Directory.CreateDirectory(_runtimeOutputPath);
@ -280,8 +287,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
var dependencyContext = new DependencyContextBuilder().Build(
compilerOptions: includeCompile ? _compilerOptions : null,
compilationExports: includeCompile ? exports : null,
runtimeExports: exports,
compilationExports: includeCompile ? compilationExports : null,
runtimeExports: runtimeExports,
portable: _context.IsPortable,
target: _context.TargetFramework,
runtime: _context.RuntimeIdentifier ?? string.Empty);

View file

@ -64,5 +64,10 @@ namespace Microsoft.DotNet.ProjectModel
}
}
}
public static IEnumerable<LibraryExport> FilterExports(this IEnumerable<LibraryExport> exports, HashSet<string> exclusionList)
{
return exports.Where(e => !exclusionList.Contains(e.Library.Identity.Name));
}
}
}

View file

@ -178,7 +178,9 @@ namespace Microsoft.Extensions.DependencyModel
{
return Enumerable.Empty<Library>();
}
return librariesObject.Properties().Select(property => ReadLibrary(property, runtime, libraryStubs));
return librariesObject.Properties()
.Select(property => ReadLibrary(property, runtime, libraryStubs))
.Where(library => library != null);
}
private Library ReadLibrary(JProperty property, bool runtime, Dictionary<string, LibraryStub> libraryStubs)
@ -202,6 +204,13 @@ namespace Microsoft.Extensions.DependencyModel
if (runtime)
{
// Runtime section of this library was trimmed by type:platform
var isCompilationOnly = libraryObject.Value<bool?>(DependencyContextStrings.CompilationOnlyPropertyName);
if (isCompilationOnly == true)
{
return null;
}
var runtimeTargetsObject = (JObject)libraryObject[DependencyContextStrings.RuntimeTargetsPropertyName];
var entries = ReadRuntimeTargetEntries(runtimeTargetsObject).ToArray();

View file

@ -74,5 +74,7 @@ namespace Microsoft.Extensions.DependencyModel
internal const string ResourceAssembliesPropertyName = "resources";
internal const string LocalePropertyName = "locale";
internal const string CompilationOnlyPropertyName = "compileOnly";
}
}

View file

@ -261,6 +261,10 @@ namespace Microsoft.Extensions.DependencyModel
}
AddDependencies(libraryObject, dependencies);
if (compilationLibrary != null && runtimeLibrary == null)
{
libraryObject.Add(DependencyContextStrings.CompilationOnlyPropertyName, true);
}
return libraryObject;
}

View file

@ -140,8 +140,9 @@ namespace Microsoft.DotNet.Tools.Publish
var buildExclusionList = context.GetTypeBuildExclusionList(exportsLookup);
var allExclusionList = new HashSet<string>(platformExclusionList);
allExclusionList.UnionWith(buildExclusionList);
var filteredExports = exports.FilterExports(allExclusionList);
foreach (var export in FilterExports(exports, allExclusionList))
foreach (var export in filteredExports)
{
Reporter.Verbose.WriteLine($"publish: Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
@ -173,7 +174,10 @@ namespace Microsoft.DotNet.Tools.Publish
{
// Make executable in the new location
var executable = new Executable(context, buildOutputPaths, outputPath, buildOutputPaths.IntermediateOutputDirectoryPath, exporter, configuration);
executable.WriteConfigurationFiles(exports, FilterExports(exports, buildExclusionList), includeDevConfig: false);
var runtimeExports = filteredExports;
var compilationExports = exports.FilterExports(buildExclusionList);
executable.WriteConfigurationFiles(exports, runtimeExports, compilationExports, includeDevConfig: false);
}
var contentFiles = new ContentFiles(context);
@ -206,10 +210,6 @@ namespace Microsoft.DotNet.Tools.Publish
return true;
}
private static IEnumerable<LibraryExport> FilterExports(IEnumerable<LibraryExport> exports, HashSet<string> exclusionList)
{
return exports.Where(e => !exclusionList.Contains(e.Library.Identity.Name));
}
/// <summary>
/// Filters which export's RuntimeAssets should get copied to the output path.

View file

@ -185,6 +185,48 @@ namespace Microsoft.Extensions.DependencyModel.Tests
package.Serviceable.Should().Be(false);
}
[Fact]
public void DoesNotReadRuntimeLibraryFromCompilationOnlyEntries()
{
var context = Read(
@"{
""targets"": {
"".NETCoreApp,Version=v1.0"": {
""MyApp/1.0.1"": {
""dependencies"": {
""AspNet.Mvc"": ""1.0.0""
},
""compile"": {
""MyApp.dll"": { }
}
},
""System.Banana/1.0.0"": {
""dependencies"": {
""System.Foo"": ""1.0.0""
},
""compileOnly"": true,
""compile"": {
""ref/dotnet5.4/System.Banana.dll"": { }
}
}
}
},
""libraries"":{
""MyApp/1.0.1"": {
""type"": ""project""
},
""System.Banana/1.0.0"": {
""type"": ""package"",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
},
}
}");
context.CompileLibraries.Should().HaveCount(2);
context.RuntimeLibraries.Should().HaveCount(1);
context.RuntimeLibraries[0].Name.Should().Be("MyApp");
}
[Fact]
public void ReadsRuntimeLibrariesWithSubtargetsFromMainTargetForPortable()

View file

@ -453,6 +453,36 @@ namespace Microsoft.Extensions.DependencyModel.Tests
}
[Fact]
public void WriteCompilationOnlyAttributeIfOnlyCompilationLibraryProvided()
{
var result = Save(Create(
"Target",
"runtime",
true,
compileLibraries: new[]
{
new CompilationLibrary(
"package",
"PackageName",
"1.2.3",
"HASH",
new [] { "ref/Banana.dll" },
new [] {
new Dependency("Fruits.Abstract.dll","2.0.0")
},
true
)
}));
// targets
var targets = result.Should().HavePropertyAsObject("targets").Subject;
var target = targets.Should().HavePropertyAsObject("Target").Subject;
var library = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
library.Should().HavePropertyValue("compileOnly", true);
}
[Fact]
public void WritesCompilationOptions()
{