Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 8c2bc0a

Browse files
authored
[Core] Fixes #526
Downloading and extracting package source archives now requires that a Module from the Package has been used in the build. This means that there may be packages with source archives that don't get downloaded on some platforms. Note that the concurrent download seen in previous alphas of v2.0 is no longer present, since the downloads must now be deferred until a sequential part of the build step.
1 parent c3c34a6 commit 8c2bc0a

File tree

7 files changed

+57
-76
lines changed

7 files changed

+57
-76
lines changed

Bam.Core/BamState.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ public BamState()
129129
this.VersionString = productVersion;
130130
this.TargetFrameworkVersion = targetFrameworkName;
131131

132-
this.preBuildTasks = new Array<System.Threading.Tasks.Task>();
133-
134132
this.BuildStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime;
135133
}
136134

@@ -174,58 +172,5 @@ public BamState()
174172
int? ISemanticVersion.MinorVersion => Version.Minor;
175173

176174
int? ISemanticVersion.PatchVersion => Version.Build;
177-
178-
private readonly Array<System.Threading.Tasks.Task> preBuildTasks;
179-
180-
/// <summary>
181-
/// Append a task from an async method that must be completed before builds start.
182-
/// </summary>
183-
/// <param name="task"></param>
184-
public void
185-
AppendPreBuildTask(
186-
System.Threading.Tasks.Task task)
187-
{
188-
lock (this.preBuildTasks)
189-
{
190-
Log.DebugMessage($"Adding task {task.ToString()}");
191-
this.preBuildTasks.Add(task);
192-
}
193-
}
194-
195-
private async System.Threading.Tasks.Task
196-
InternalWaitOnAllPreBuildTasks()
197-
{
198-
var total = this.preBuildTasks.Count;
199-
var all = System.Threading.Tasks.Task.WhenAll(this.preBuildTasks.ToArray());
200-
for (; ; )
201-
{
202-
var timer = System.Threading.Tasks.Task.Delay(1000); // every second
203-
var finishedTask = await System.Threading.Tasks.Task.WhenAny(all, timer);
204-
if (finishedTask.IsFaulted)
205-
{
206-
throw finishedTask.Exception;
207-
}
208-
if (all.IsCompleted)
209-
{
210-
return;
211-
}
212-
Log.DetailProgress($"{100 * this.preBuildTasks.Count(task => task.IsCompleted) / total}%");
213-
}
214-
}
215-
216-
/// <summary>
217-
/// Wait on all prebuild tasks to complete. This is a blocking function.
218-
/// </summary>
219-
public void
220-
WaitOnAllPreBuildTasks()
221-
{
222-
if (!this.preBuildTasks.Any())
223-
{
224-
return;
225-
}
226-
Log.Info($"Waiting on package source downloads to finish before the build starts...");
227-
var all = this.InternalWaitOnAllPreBuildTasks();
228-
all.Wait(); // safety
229-
}
230175
}
231176
}

Bam.Core/EntryPoint.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public static void
9999
PackageUtilities.CompilePackageAssembly(true);
100100
PackageUtilities.LoadPackageAssembly();
101101
}
102-
Graph.Instance.ProcessState.WaitOnAllPreBuildTasks();
103102

104103
var packageMetaDataProfile = new TimeProfile(ETimingProfiles.PackageMetaData);
105104
packageMetaDataProfile.StartProfile();

Bam.Core/Graph.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,20 @@ public void
773773
this.InternalValidateGraph(rank.Key, m.Requirements);
774774
}
775775
}
776+
Log.DebugMessage("Used packages:");
777+
foreach (var package in this.PackageDefinitions.Where(item => item.CreatedModules().Any()))
778+
{
779+
Log.DebugMessage($"\t{package.Name}");
780+
foreach (var module in package.CreatedModules())
781+
{
782+
Log.DebugMessage($"\t\t{module.ToString()}");
783+
}
784+
}
785+
Log.DebugMessage("Unused packages:");
786+
foreach (var package in this.PackageDefinitions.Where(item => !item.CreatedModules().Any()))
787+
{
788+
Log.DebugMessage($"\t{package.Name}");
789+
}
776790
}
777791

778792
/// <summary>
@@ -837,23 +851,6 @@ public void
837851
{
838852
this.PackageDefinitions = packages;
839853
this.Macros.AddVerbatim("masterpackagename", this.MasterPackage.Name);
840-
841-
foreach (var package in packages)
842-
{
843-
if (null == package.Sources)
844-
{
845-
continue;
846-
}
847-
foreach (var source in package.Sources)
848-
{
849-
var fetchSourceTask = source.Fetch();
850-
if (null == fetchSourceTask)
851-
{
852-
continue;
853-
}
854-
this.ProcessState.AppendPreBuildTask(fetchSourceTask);
855-
}
856-
}
857854
}
858855

859856
/// <summary>

Bam.Core/Module.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ protected Module()
122122
this.ReasonToExecute = ExecuteReasoning.Undefined();
123123
this.ExecutionTask = null;
124124
this.EvaluationTask = null;
125+
126+
this.PackageDefinition.AddCreatedModule(this.GetType().Name);
127+
if (null != this.PackageDefinition.Sources)
128+
{
129+
foreach (var source in this.PackageDefinition.Sources)
130+
{
131+
source.Fetch();
132+
}
133+
}
125134
}
126135

127136
private void

Bam.Core/Package/PackageDefinition.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ private static void
6565

6666
private static System.Xml.XmlReaderSettings CommonReaderSettings { get; set; }
6767

68+
private System.Collections.Generic.HashSet<string> ModulesCreated = new System.Collections.Generic.HashSet<string>();
69+
70+
/// <summary>
71+
/// Enumerated unique list of module names created from this package definition.
72+
/// </summary>
73+
public System.Collections.Generic.IEnumerable<string> CreatedModules()
74+
{
75+
foreach (var m in this.ModulesCreated)
76+
{
77+
yield return m;
78+
}
79+
}
80+
81+
/// <summary>
82+
/// Add the name of another module to the unique list.
83+
/// </summary>
84+
/// <param name="name">String name of the module to add.</param>
85+
public void
86+
AddCreatedModule(
87+
string name)
88+
{
89+
lock (this.ModulesCreated)
90+
{
91+
this.ModulesCreated.Add(name);
92+
}
93+
}
94+
6895
static PackageDefinition()
6996
{
7097
var xmlReaderSettings = new System.Xml.XmlReaderSettings();

Bam.Core/Package/PackageSource.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,19 @@ public PackageSource(
132132
/// <summary>
133133
/// Begin the fetch of the package source if it's not already fetched.
134134
/// </summary>
135-
public System.Threading.Tasks.Task
135+
public void
136136
Fetch()
137137
{
138138
if (this.AlreadyFetched)
139139
{
140-
return null;
140+
return;
141141
}
142142
switch (this.Type)
143143
{
144144
case PackageSource.EType.Http:
145-
return this.DownloadAndExtractPackageViaHTTP();
145+
this.DownloadAndExtractPackageViaHTTP().Wait();
146+
this.AlreadyFetched = true;
147+
return;
146148
}
147149
throw new Exception($"Unhandled package source type, '{this.Type.ToString()}'");
148150
}

Changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
03-Apr-2019 Fixes #526. Downloading and extracting package source archives now requires that a Module from the Package has been used in the build. This means that there may be packages with source archives that don't get downloaded on some platforms.
2+
13
09-Mar-2019 Fixes #525. Resolving a package, when there is both an unversioned and (many) versioned candidates no longer fails with a null dereference. I believe this is a rare situation - usually all candidates for a package will be versioned when there is more than one.
24

35
09-Mar-2019 Fixes #524. Upgraded NuGet dependencies:

0 commit comments

Comments
 (0)