Skip to content

Commit

Permalink
fixed rebuild scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
hlotyaks committed Jan 6, 2020
1 parent 645bd83 commit 86bbe4a
Show file tree
Hide file tree
Showing 23 changed files with 230 additions and 2 deletions.
76 changes: 76 additions & 0 deletions ConsoleTest/ConsoleTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphBuilder", "..\GraphBuilder\src\GraphBuilder.csproj", "{6A28B56B-954A-4B13-98F9-EE9F0809550E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageBuilder", "..\PackageBuilder\src\PackageBuilder.csproj", "{D56FBF34-841A-46DE-A451-29072979A058}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageHasher", "..\PackageHasher\src\PackageHasher.csproj", "{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "src\ConsoleTest.csproj", "{6990819A-89F7-4C68-8166-698017244944}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|x64.Build.0 = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|x86.ActiveCfg = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Debug|x86.Build.0 = Debug|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|Any CPU.Build.0 = Release|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|x64.ActiveCfg = Release|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|x64.Build.0 = Release|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|x86.ActiveCfg = Release|Any CPU
{6A28B56B-954A-4B13-98F9-EE9F0809550E}.Release|x86.Build.0 = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|x64.ActiveCfg = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|x64.Build.0 = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|x86.ActiveCfg = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Debug|x86.Build.0 = Debug|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|Any CPU.Build.0 = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|x64.ActiveCfg = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|x64.Build.0 = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|x86.ActiveCfg = Release|Any CPU
{D56FBF34-841A-46DE-A451-29072979A058}.Release|x86.Build.0 = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|x64.ActiveCfg = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|x64.Build.0 = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|x86.ActiveCfg = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Debug|x86.Build.0 = Debug|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|Any CPU.Build.0 = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|x64.ActiveCfg = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|x64.Build.0 = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|x86.ActiveCfg = Release|Any CPU
{7F1CD306-1EE9-4665-8BD1-E9DAAA854107}.Release|x86.Build.0 = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|x64.ActiveCfg = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|x64.Build.0 = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|x86.ActiveCfg = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Debug|x86.Build.0 = Debug|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|Any CPU.Build.0 = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|x64.ActiveCfg = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|x64.Build.0 = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|x86.ActiveCfg = Release|Any CPU
{6990819A-89F7-4C68-8166-698017244944}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions ConsoleTest/src/ConsoleTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\GraphBuilder\src\GraphBuilder.csproj" />
<ProjectReference Include="..\..\PackageBuilder\src\PackageBuilder.csproj" />
<ProjectReference Include="..\..\PackageHasher\src\PackageHasher.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
43 changes: 43 additions & 0 deletions ConsoleTest/src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PackageAnalyzer;

namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{

string packageroot = "A";
string packagedescriptions = @"\pkgs\descriptions";
string packagesource = @"\src";
string testroot = @"C:\tmp";

GraphBuilder gb = new GraphBuilder($"{testroot}{packagedescriptions}");

if (gb.Graph.IsCyclic)
{
Console.WriteLine("Build graph contains cyclic dependencies.");
return;
}

DirectoryInfo di = new DirectoryInfo($"{testroot}{packagesource}");
List<string> paths = di.GetDirectories().Select(d => d.FullName).ToList();
var task = Task.Run(async () => await PackageHasher.HashFoldersAsync(paths, testroot));
Dictionary<string, string> packageSourceHash = task.Result;

PackageBuilder pb = new PackageBuilder(testroot);
Dictionary<string, bool> buildResults = pb.Build(packageroot, $"{testroot}{packagesource}", packageSourceHash, gb.Graph);

foreach (string key in buildResults.Keys)
{
Console.WriteLine($"package {key} build : {buildResults[key]}");
}

}
}
}
10 changes: 10 additions & 0 deletions GraphBuilder/src/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public Graph()
parentnodes = new Dictionary<string, List<string>>();
}

public string[] Nodes
{
get
{
string[] nodes = new string[directednodes.Keys.Count];
directednodes.Keys.CopyTo(nodes, 0);
return nodes;
}
}

public List<string> Paths(string V)
{
return directednodes[V];
Expand Down
5 changes: 4 additions & 1 deletion GraphBuilder/tests/Graph.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public void SimpleGraphCycleTest1()
GraphBuilder gb = GraphTestUtilities.PopulateGB("simplecycle1");

Assert.IsTrue(gb.Graph.IsCyclic);
Assert.AreEqual(2, gb.Graph.Nodes.Length);
}

[TestMethod]
Expand Down Expand Up @@ -63,7 +64,9 @@ public void IntermediateGraphCycleTest1()
Assert.AreEqual(1, gb.Graph.Children("D").Count);
Assert.IsTrue(gb.Graph.Children("D").Contains("E"));

Assert.AreEqual(0, gb.Graph.Children("E").Count);
Assert.AreEqual(0, gb.Graph.Children("E").Count);

Assert.AreEqual(5, gb.Graph.Nodes.Length);
}
}
}
15 changes: 14 additions & 1 deletion PackageBuilder/src/PackageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public Dictionary<string, bool> Build(string startNode, string sourceFolder, Dic

Dictionary<string, bool> packageBuildResults = new Dictionary<string, bool>();

// Initialize the results collection
foreach (string node in g.Nodes)
{
packageBuildResults.Add(node,false);
}

BuildPackages(packages, hash, g, packageBuildResults);

return packageBuildResults;
Expand Down Expand Up @@ -84,8 +90,13 @@ private void BuildPackages(List<string> packages, Dictionary<string, string> has
forceBuild = true;
}
}
bool result = BuildPackage(package, hash, forceBuild);

buildResults.Add(package, BuildPackage(package, hash, forceBuild));
if (result)
{
buildResults[package] = result;
}


children.AddRange(g.Children(package));
}
Expand Down Expand Up @@ -133,6 +144,8 @@ private void Compile(string package, string packageHashName)
string source = $"{_sourceRoot}{package}";
string dest = $"{_outputRoot}{packageHashName}.zip";

File.Delete($"{_outputRoot}{packageHashName}.zip");

ZipFile.CreateFromDirectory($"{_sourceRoot}{package}", $"{_outputRoot}{packageHashName}.zip");
}
}
Expand Down
39 changes: 39 additions & 0 deletions PackageBuilder/tests/PackageBuilder.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,44 @@ public void IntermediateBuilderTest1()
Assert.IsTrue(buildResults["E"]);
}
}

[TestMethod]
public void IntermediateBuilderTest2()
{
//
// cache contains a pre built A and B. A and B do not build. C will build.
//

string cwd = Directory.GetCurrentDirectory();
string testroot = $"{cwd}\\testcases\\intermediate1";

GraphBuilder gb = new GraphBuilder($"{testroot}{packagedescriptions}");

DirectoryInfo di = new DirectoryInfo($"{testroot}{packagesource}");
List<string> paths = di.GetDirectories().Select(d => d.FullName).ToList();
var task = Task.Run(async () => await PackageHasher.HashFoldersAsync(paths, testroot));

// package source to package source hash mapping
Dictionary<string, string> packageSourceHash = task.Result;

List<string> excludeList = new List<string>();
excludeList.Add(packageSourceHash["A"]);
excludeList.Add(packageSourceHash["B"]);
excludeList.Add(packageSourceHash["C"]);
excludeList.Add(packageSourceHash["D"]);
excludeList.Add(packageSourceHash["E"]);
CleanCache(testroot, excludeList);

{
CleanOutput(testroot);
PackageBuilder pb = new PackageBuilder(testroot);
Dictionary<string, bool> buildResults = pb.Build("A", $"{testroot}{packagesource}", packageSourceHash, gb.Graph);
Assert.IsFalse(buildResults["A"]);
Assert.IsFalse(buildResults["B"]);
Assert.IsFalse(buildResults["C"]);
Assert.IsFalse(buildResults["D"]);
Assert.IsFalse(buildResults["E"]);
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<package id="A">
</package>

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<package id="B">
<dependency>
<package id="A"/>
</dependency>
</package>

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<package id="C">
<dependency>
<package id="A"/>
</dependency>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<package id="D">
<dependency>
<package id="C"/>
</dependency>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<package id="E">
<dependency>
<package id="C"/>
<package id="D"/>
</dependency>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for file1. Just needed to get a hash value.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for file1. Just needed to get a hash value.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for file1. Just needed to get a hash value.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for file1. Just needed to get a hash value.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test data for file1. Just needed to get a hash value.

0 comments on commit 86bbe4a

Please sign in to comment.