Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into Restore3 #150

Merged
merged 8 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void ItAssignsValidParentTargetsAndPackages(string projectName)

// set of valid targets and packages
HashSet<string> validTargets = new HashSet<string>(lockFile.Targets.Select(x => x.Name));
HashSet<string> validPackages = new HashSet<string>(lockFile.Libraries.Select(x => $"{x.Name}/{x.Version.ToString()}"));
HashSet<string> validPackages = new HashSet<string>(lockFile.Libraries.Select(x => $"{x.Name}/{x.Version.ToNormalizedString()}"));

Func<ITaskItem[], bool> allValidParentTarget =
(items) => items.All(x => validTargets.Contains(x.GetMetadata(MetadataKeys.ParentTarget)));
Expand Down Expand Up @@ -611,51 +611,46 @@ public void ItFiltersAnalyzersByProjectLanguage()
}

[Fact]
public void ItUsesMinVersionFromPackageDependencyRanges()
public void ItUsesResolvedPackageVersionFromSameTarget()
{
string targetLibC = CreateTargetLibrary("LibC/1.2.3", "package",
dependencies: new string[] {
"\"Dep.Lib.Alpha\": \"4.0.0\"",
"\"Dep.Lib.Beta\": \"[4.0.0]\"",
"\"Dep.Lib.Chi\": \"[4.0.0, 5.0.0)\"",
"\"Dep.Lib.Delta\": \"[4.0.0)\"",
});

string targetLibChi1 = CreateTargetLibrary("Dep.Lib.Chi/4.0.0", "package");
string targetLibChi2 = CreateTargetLibrary("Dep.Lib.Chi/4.1.0", "package");

string lockFileContent = CreateLockFileSnippet(
targets: new string[] {
CreateTarget(".NETCoreApp,Version=v1.0", TargetLibA, TargetLibB, targetLibC),
CreateTarget(".NETCoreApp,Version=v1.0", TargetLibA, TargetLibB, targetLibC, targetLibChi1),
CreateTarget(".NETCoreApp,Version=v1.0/osx.10.11-x64", TargetLibA, TargetLibB, targetLibC, targetLibChi2),
},
libraries: new string[] {
LibADefn, LibBDefn, LibCDefn,
CreateLibrary("Dep.Lib.Alpha/4.0.0", "package", "lib/file/Alpha.dll"),
CreateLibrary("Dep.Lib.Beta/4.0.0", "package", "lib/file/Beta.dll"),
CreateLibrary("Dep.Lib.Chi/4.0.0", "package", "lib/file/Chi.dll"),
CreateLibrary("Dep.Lib.Delta/4.0.0", "package", "lib/file/Delta.dll"),
CreateLibrary("Dep.Lib.Chi/4.1.0", "package", "lib/file/Chi.dll"),
},
projectFileDependencyGroups: new string[] { ProjectGroup, NETCoreGroup, NETCoreOsxGroup }
);

var task = GetExecutedTaskFromContents(lockFileContent);

task.PackageDependencies
.Where(t => t.ItemSpec.StartsWith("Dep.Lib."))
.Count().Should().Be(4);
var chiDeps = task.PackageDependencies
.Where(t => t.ItemSpec.StartsWith("Dep.Lib.Chi"));

task.PackageDependencies
.Any(t => t.ItemSpec == "Dep.Lib.Alpha/4.0.0")
.Should().BeTrue();
chiDeps.Count().Should().Be(2);

task.PackageDependencies
.Any(t => t.ItemSpec == "Dep.Lib.Beta/4.0.0")
.Should().BeTrue();
// Dep.Lib.Chi has version range [4.0.0, 5.0.0), but the version assigned
// is that of the library in the same target

task.PackageDependencies
.Any(t => t.ItemSpec == "Dep.Lib.Chi/4.0.0")
.Should().BeTrue();
chiDeps.Where(t => t.GetMetadata(MetadataKeys.ParentTarget) == ".NETCoreApp,Version=v1.0")
.Select(t => t.ItemSpec)
.First().Should().Be("Dep.Lib.Chi/4.0.0");

task.PackageDependencies
.Any(t => t.ItemSpec == "Dep.Lib.Delta/4.0.0")
.Should().BeTrue();
chiDeps.Where(t => t.GetMetadata(MetadataKeys.ParentTarget) == ".NETCoreApp,Version=v1.0/osx.10.11-x64")
.Select(t => t.ItemSpec)
.First().Should().Be("Dep.Lib.Chi/4.1.0");
}

private ResolvePackageDependencies GetExecutedTaskFromPrefix(string lockFilePrefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace Microsoft.NETCore.Build.Tasks
/// </summary>
public sealed class ResolvePackageDependencies : Task
{
private readonly List<string> _packageFolders = new List<string>();
private readonly Dictionary<string, string> _fileTypes = new Dictionary<string, string>();
private readonly HashSet<string> _projectFileDependencies = new HashSet<string>();
private readonly Dictionary<string, string> _fileTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _projectFileDependencies = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private IPackageResolver _packageResolver;
private LockFile _lockFile;

Expand Down Expand Up @@ -200,11 +199,11 @@ private void GetPackageAndFileDefinitions()
TaskItem item;
foreach (var package in LockFile.Libraries)
{
string packageId = $"{package.Name}/{package.Version.ToString()}";
string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}";
item = new TaskItem(packageId);
item.SetMetadata(MetadataKeys.Name, package.Name);
item.SetMetadata(MetadataKeys.Type, package.Type);
item.SetMetadata(MetadataKeys.Version, package.Version.ToString());
item.SetMetadata(MetadataKeys.Version, package.Version.ToNormalizedString());

item.SetMetadata(MetadataKeys.Path, package.Path ?? string.Empty);

Expand Down Expand Up @@ -316,10 +315,13 @@ private void RaiseLockFileTargets()

private void GetPackageAndFileDependencies(LockFileTarget target)
{
var resolvedPackageVersions = target.Libraries
.ToDictionary(pkg => pkg.Name, pkg => pkg.Version.ToNormalizedString(), StringComparer.OrdinalIgnoreCase);

TaskItem item;
foreach (var package in target.Libraries)
{
string packageId = $"{package.Name}/{package.Version.ToString()}";
string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}";

if (_projectFileDependencies.Contains(package.Name))
{
Expand All @@ -331,20 +333,30 @@ private void GetPackageAndFileDependencies(LockFileTarget target)
}

// get sub package dependencies
GetPackageDependencies(package, target.Name);
GetPackageDependencies(package, target.Name, resolvedPackageVersions);

// get file dependencies on this package
GetFileDependencies(package, target.Name);
}
}

private void GetPackageDependencies(LockFileTargetLibrary package, string targetName)
private void GetPackageDependencies(
LockFileTargetLibrary package,
string targetName,
Dictionary<string, string> resolvedPackageVersions)
{
string packageId = $"{package.Name}/{package.Version.ToString()}";
string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}";
TaskItem item;
foreach (var deps in package.Dependencies)
{
string depsName = $"{deps.Id}/{deps.VersionRange.MinVersion.ToString()}";
string version;
if (!resolvedPackageVersions.TryGetValue(deps.Id, out version))
{
Log.LogError($"Unexpected Dependency {deps.Id} with no version number");
continue;
}

string depsName = $"{deps.Id}/{version}";

item = new TaskItem(depsName);
item.SetMetadata(MetadataKeys.ParentTarget, targetName); // Foreign Key
Expand All @@ -356,7 +368,7 @@ private void GetPackageDependencies(LockFileTargetLibrary package, string target

private void GetFileDependencies(LockFileTargetLibrary package, string targetName)
{
string packageId = $"{package.Name}/{package.Version.ToString()}";
string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}";
TaskItem item;

// for each type of file group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Copyright (c) .NET Foundation. All rights reserved.
https://github.com/dotnet/roslyn/issues/13681 tracks the compiler bug.
-->
<PropertyGroup>
<TargetsTriggeredByCompilation Condition="'($OutputType)' == 'exe'">ChangeExtensionOfOutputAssembly;$(TargetsTriggeredByCompilation)</TargetsTriggeredByCompilation>
<TargetsTriggeredByCompilation Condition="'$(OutputType)' == 'exe'">ChangeExtensionOfOutputAssembly;$(TargetsTriggeredByCompilation)</TargetsTriggeredByCompilation>
</PropertyGroup>

<Target Name="ChangeExtensionOfOutputAssembly">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<OutputType>Library</OutputType>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform>AnyCPU</Platform>

<FileAlignment>512</FileAlignment>
<GlobalExclude>bin\**;obj\**;</GlobalExclude>

<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
</PropertyGroup>

<!-- User-facing configuration-specific defaults -->
Expand All @@ -42,7 +41,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Default settings for .NET Core build logic -->
<PropertyGroup>
<DebugType>portable</DebugType>

<AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
<DesignTimeAutoUnify>true</DesignTimeAutoUnify>

<GenerateDependencyFile Condition=" '$(GenerateDependencyFile)' == '' ">true</GenerateDependencyFile>

<!-- all references (even the StdLib) come from packages -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.PackageDependencyResolution.targets" Condition="Exists('$(MSBuildThisFileDirectory)Microsoft.PackageDependencyResolution.targets')" />
</ImportGroup>

<PropertyGroup>
<DefaultExcludes>bin\**;obj\**</DefaultExcludes>
</PropertyGroup>
<ItemGroup>
<Compile Remove="$(DefaultExcludes)" />
<EmbeddedResource Remove="$(DefaultExcludes)" />
</ItemGroup>

<UsingTask TaskName="GenerateDepsFile" AssemblyFile="$(MicrosoftNETCoreBuildTasksAssembly)" />
<UsingTask TaskName="GenerateRuntimeConfigurationFiles" AssemblyFile="$(MicrosoftNETCoreBuildTasksAssembly)" />
<UsingTask TaskName="GetAssemblyVersion" AssemblyFile="$(MicrosoftNETCoreBuildTasksAssembly)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Copyright (c) .NET Foundation. All rights reserved.

<ItemGroup>
<ProjectCapability Include="DotNetCoreWeb" />
<ProjectCapability Include="DependencyPackageManagement" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<None Include="project.json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<None Include="project.json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<None Include="project.json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.vb" Exclude="$(GlobalExclude)" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
<Compile Include="**\*.vb" />
<EmbeddedResource Include="**\*.resx" />
<None Include="project.json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.vb" Exclude="$(GlobalExclude)" />
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
<Compile Include="**\*.vb" />
<EmbeddedResource Include="**\*.resx" />
<None Include="project.json" />
</ItemGroup>

Expand Down