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

Add DeltaBuild into Arcade #12885

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions Arcade.sln
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.XUnitAsser
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.XUnitAssert.Tests", "src\Microsoft.DotNet.XUnitAssert\tests\Microsoft.DotNet.XUnitAssert.Tests.csproj", "{14462553-E4E1-4F67-B954-4BF24B1DAAFE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.DeltaBuild", "src\Microsoft.DotNet.DeltaBuild\Microsoft.DotNet.DeltaBuild.csproj", "{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.DeltaBuild.Tests", "src\Microsoft.DotNet.DeltaBuild.Tests\Microsoft.DotNet.DeltaBuild.Tests.csproj", "{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -923,6 +927,30 @@ Global
{14462553-E4E1-4F67-B954-4BF24B1DAAFE}.Release|x64.Build.0 = Release|Any CPU
{14462553-E4E1-4F67-B954-4BF24B1DAAFE}.Release|x86.ActiveCfg = Release|Any CPU
{14462553-E4E1-4F67-B954-4BF24B1DAAFE}.Release|x86.Build.0 = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|x64.ActiveCfg = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|x64.Build.0 = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|x86.ActiveCfg = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Debug|x86.Build.0 = Debug|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|Any CPU.Build.0 = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|x64.ActiveCfg = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|x64.Build.0 = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|x86.ActiveCfg = Release|Any CPU
{C98CBA55-7CA8-475C-87A8-86A1036DC9A4}.Release|x86.Build.0 = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|x64.ActiveCfg = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|x64.Build.0 = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Debug|x86.Build.0 = Debug|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|Any CPU.Build.0 = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|x64.ActiveCfg = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|x64.Build.0 = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|x86.ActiveCfg = Release|Any CPU
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -964,6 +992,7 @@ Global
{3C542789-2576-48C8-9772-C9D7575F7E42} = {6DA9F58A-34D5-45A6-998E-5D2B8037C3FE}
{AB8D5F86-60FA-416A-B047-83B1E9118425} = {3C542789-2576-48C8-9772-C9D7575F7E42}
{14462553-E4E1-4F67-B954-4BF24B1DAAFE} = {3C542789-2576-48C8-9772-C9D7575F7E42}
{7E4ABD92-0AE0-417F-8C8B-D9E784948C3F} = {C53DD924-C212-49EA-9BC4-1827421361EF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {32B9C883-432E-4FC8-A1BF-090EB033DD5B}
Expand Down
1 change: 1 addition & 0 deletions eng/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<FileSignInfo Include="LibGit2Sharp.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="SharpYaml.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="FluentAssertions.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="StructuredLogger.dll" CertificateName="3PartySHA2" />

<!-- Despite being called "Microsoft.*", these are not produced by Microsoft. These assemblies come from the Wix toolset project. -->
<FileSignInfo Include="Microsoft.Deployment.Compression.Cab.dll" CertificateName="3PartySHA2" />
Expand Down
3 changes: 3 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<MicrosoftiOSTemplatesVersion>15.2.302-preview.14.122</MicrosoftiOSTemplatesVersion>
<SystemCollectionsImmutableVersion>7.0.0</SystemCollectionsImmutableVersion>
<SystemCompositionVersion>7.0.0</SystemCompositionVersion>
<SystemCommandLineVersion>2.0.0-beta4.22272.1</SystemCommandLineVersion>
<SystemIOPackagingVersion>7.0.0</SystemIOPackagingVersion>
<SystemReflectionMetadataVersion>7.0.0</SystemReflectionMetadataVersion>
<SystemSecurityCryptographyX509CertificatesVersion>4.3.2</SystemSecurityCryptographyX509CertificatesVersion>
Expand Down Expand Up @@ -84,6 +85,7 @@
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
<HandlebarsNetVersion>1.11.5</HandlebarsNetVersion>
<JetBrainsAnnotationsVersion>2018.2.1</JetBrainsAnnotationsVersion>
<LibGit2SharpVersion>0.27.2</LibGit2SharpVersion>
<LZMA_SDKVersion>19.0.0</LZMA_SDKVersion>
<McMasterExtensionsCommandLineUtils>2.3.0</McMasterExtensionsCommandLineUtils>
<MicrosoftApplicationInsightsVersion>2.21.0</MicrosoftApplicationInsightsVersion>
Expand All @@ -97,6 +99,7 @@
<MicrosoftOpenApiVersion>1.3.2</MicrosoftOpenApiVersion>
<MicrosoftSignedWixVersion>1.0.0-v3.14.0.5722</MicrosoftSignedWixVersion>
<MicrosoftVisualStudioOLEInteropVersion>7.10.6071</MicrosoftVisualStudioOLEInteropVersion>
<MSBuildStructuredLoggerVersion>2.1.790</MSBuildStructuredLoggerVersion>
<MonoOptionsVersion>5.3.0.1</MonoOptionsVersion>
<MoqVersion>4.18.4</MoqVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
Expand Down
129 changes: 129 additions & 0 deletions src/Microsoft.DotNet.DeltaBuild.Tests/AffectedProjectsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Arcade.Test.Common;
using Xunit;

namespace Microsoft.DotNet.DeltaBuild.Tests;

public class AffectedProjectsTests
{
[Fact]
public void AffectedProjects_Construction_CreatesCorrectly()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, string>
{
{ Path.GetFullPath("/root1/dir1/proj1.csproj"), "" },
{ Path.GetFullPath("/root1/dir1/proj2.csproj"), "" },
{ Path.GetFullPath("/root1/dir2/proj3.csproj"), "" }
});

var directlyAffected = new List<FilePath> {
FilePath.Create(fileSystem, "/root1/dir1/proj1.csproj"),
FilePath.Create(fileSystem, "/root1/dir1/proj2.csproj")
};

var upstreamTree = new List<FilePath> { FilePath.Create(fileSystem, "/root1/dir2/proj3.csproj") };
var downstreamTree = new List<FilePath>();

// Act
var affectedProjects = new AffectedProjects(directlyAffected, upstreamTree, downstreamTree);

// Assert
Assert.Equal(directlyAffected, affectedProjects.DirectlyAffectedProjects);
Assert.Equal(upstreamTree, affectedProjects.UpstreamTree);
Assert.Equal(downstreamTree, affectedProjects.DownstreamTree);
}

[Fact]
public void MergeWith_CombinesAffectedProjectsCorrectly()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, string>
{
{ Path.GetFullPath("/root1/dir1/proj1.csproj"), "" },
{ Path.GetFullPath("/root1/dir1/proj2.csproj"), "" },
{ Path.GetFullPath("/root1/dir2/proj3.csproj"), "" },
{ Path.GetFullPath("/root2/dir1/proj4.csproj"), "" },
{ Path.GetFullPath("/root2/dir1/proj5.csproj"), "" },
{ Path.GetFullPath("/root2/dir2/proj6.csproj"), "" }
});

var directlyAffected1 = new List<FilePath> {
FilePath.Create(fileSystem, "/root1/dir1/proj1.csproj"),
FilePath.Create(fileSystem, "/root1/dir1/proj2.csproj")
};
var upstreamTree1 = new List<FilePath> { FilePath.Create(fileSystem, "/root1/dir2/proj3.csproj") };
var downstreamTree1 = new List<FilePath>();

var directlyAffected2 = new List<FilePath> {
FilePath.Create(fileSystem, "/root2/dir1/proj4.csproj"),
FilePath.Create(fileSystem, "/root2/dir1/proj5.csproj")
};
var upstreamTree2 = new List<FilePath> { FilePath.Create(fileSystem, "/root2/dir2/proj6.csproj") };
var downstreamTree2 = new List<FilePath>();

var affectedProjects1 = new AffectedProjects(directlyAffected1, upstreamTree1, downstreamTree1);
var affectedProjects2 = new AffectedProjects(directlyAffected2, upstreamTree2, downstreamTree2);

// Act
var mergedProjects = affectedProjects1.MergeWith(affectedProjects2);

// Assert
Assert.Equal(
directlyAffected1.Union(directlyAffected2).OrderBy(p => p.FullPath).ToList(),
mergedProjects.DirectlyAffectedProjects.OrderBy(p => p.FullPath).ToList());

Assert.Equal(
upstreamTree1.Union(upstreamTree2).OrderBy(p => p.FullPath).ToList(),
mergedProjects.UpstreamTree.OrderBy(p => p.FullPath).ToList());

Assert.Equal(
downstreamTree1.Union(downstreamTree2).OrderBy(p => p.FullPath).ToList(),
mergedProjects.DownstreamTree.OrderBy(p => p.FullPath).ToList());
}

[Fact]
public void ChangeRoot_ChangesRootCorrectly()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, string>
{
{ Path.GetFullPath("/oldRoot/directlyAffected1"), "" },
{ Path.GetFullPath("/oldRoot/upstream1"), "" },
{ Path.GetFullPath("/oldRoot/downstream1"), "" },
{ Path.GetFullPath("/newRoot/directlyAffected1"), "" }, // add these new paths
{ Path.GetFullPath("/newRoot/upstream1"), "" },
{ Path.GetFullPath("/newRoot/downstream1"), "" }
});

var directlyAffected = new List<FilePath> { FilePath.Create(fileSystem, "/oldRoot/directlyAffected1") };
var upstreamTree = new List<FilePath> { FilePath.Create(fileSystem, "/oldRoot/upstream1") };
var downstreamTree = new List<FilePath> { FilePath.Create(fileSystem, "/oldRoot/downstream1") };

var affectedProjects = new AffectedProjects(directlyAffected, upstreamTree, downstreamTree);

var oldRoot = new DirectoryInfo("/oldRoot");
var newRoot = new DirectoryInfo("/newRoot");

// Act
var changedProjects = affectedProjects.ChangeRoot(fileSystem, oldRoot, newRoot);

// Assert
Assert.Equal(
Path.GetFullPath("/newRoot/directlyAffected1"),
changedProjects.DirectlyAffectedProjects.Single().FullPath);

Assert.Equal(
Path.GetFullPath("/newRoot/upstream1"),
changedProjects.UpstreamTree.Single().FullPath);

Assert.Equal(
Path.GetFullPath("/newRoot/downstream1"),
changedProjects.DownstreamTree.Single().FullPath);
}
}
146 changes: 146 additions & 0 deletions src/Microsoft.DotNet.DeltaBuild.Tests/DependencyResolverTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Microsoft.DotNet.DeltaBuild.Tests;

public class DependencyResolverTests
{
[Fact]
public void GetDownstreamDependencies_ReturnsCorrectDependencies()
{
// Arrange
var project1 = FilePath.Create("project1");
var project2 = FilePath.Create("project2");
var project3 = FilePath.Create("project3");
var project4 = FilePath.Create("project4");

var projects = new Dictionary<FilePath, HashSet<FilePath>>
{
{project1, new HashSet<FilePath>{project2}},
{project2, new HashSet<FilePath>{project3}},
{project3, new HashSet<FilePath>{project4}},
{project4, new HashSet<FilePath>()},
};

// Act
var dependencies = DependencyResolver.GetDownstreamDependencies(projects, project1).ToList();

// Assert
Assert.Equal(3, dependencies.Count);
Assert.Contains(project2, dependencies);
Assert.Contains(project3, dependencies);
Assert.Contains(project4, dependencies);
}

[Fact]
public void GetDownstreamDependencies_ReturnsEmptyForProjectWithoutDependencies()
{
// Arrange
var project1 = FilePath.Create("project1");

var projects = new Dictionary<FilePath, HashSet<FilePath>>
{
{project1, new HashSet<FilePath>()},
};

// Act
var dependencies = DependencyResolver.GetDownstreamDependencies(projects, project1).ToList();

// Assert
Assert.Empty(dependencies);
}

[Fact]
public void GetDownstreamDependencies_ReturnsEmptyWhenProjectNotInDictionary()
{
// Arrange
var projects = new Dictionary<FilePath, HashSet<FilePath>>();
var wanted = FilePath.Create("wanted");

// Act
Assert.Throws<KeyNotFoundException>(() => DependencyResolver.GetDownstreamDependencies(projects, wanted).ToList());
}

[Fact]
public void GetUpstreamDependencies_ReturnsCorrectDependencies()
{
// Arrange
var project1 = FilePath.Create("project1");
var project2 = FilePath.Create("project2");
var project3 = FilePath.Create("project3");
var project4 = FilePath.Create("project4");

var projects = new Dictionary<FilePath, HashSet<FilePath>>
{
{project1, new HashSet<FilePath>()},
{project2, new HashSet<FilePath>{project1}},
{project3, new HashSet<FilePath>{project2}},
{project4, new HashSet<FilePath>{project3}},
};

// Act
var dependencies = DependencyResolver.GetUpstreamDependencies(projects, project1).ToList();

// Assert
Assert.Equal(3, dependencies.Count);
Assert.Contains(project2, dependencies);
Assert.Contains(project3, dependencies);
Assert.Contains(project4, dependencies);
}

[Fact]
public void GetUpstreamDependencies_ReturnsEmptyForProjectWithoutDependencies()
{
// Arrange
var project1 = FilePath.Create("project1");

var projects = new Dictionary<FilePath, HashSet<FilePath>>
{
{project1, new HashSet<FilePath>()},
};

// Act
var dependencies = DependencyResolver.GetUpstreamDependencies(projects, project1).ToList();

// Assert
Assert.Empty(dependencies);
}

[Fact]
public void GetUpstreamDependencies_ReturnsEmptyForEmptyProjects()
{
// Arrange
var projects = new Dictionary<FilePath, HashSet<FilePath>>();
var project1 = FilePath.Create("project1");

// Act
var dependencies = DependencyResolver.GetUpstreamDependencies(projects, project1).ToList();

// Assert
Assert.Empty(dependencies);
}

[Fact]
public void GetUpstreamDependencies_ReturnsEmptyWhenProjectIsNotDependency()
{
// Arrange
var project1 = FilePath.Create("project1");
var project2 = FilePath.Create("project2");

var projects = new Dictionary<FilePath, HashSet<FilePath>>
{
{project1, new HashSet<FilePath>()},
{project2, new HashSet<FilePath>()},
};

// Act
var dependencies = DependencyResolver.GetUpstreamDependencies(projects, project1).ToList();

// Assert
Assert.Empty(dependencies);
}
}