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

Commit 35f24e2

Browse files
committed
[Core] Fixes #228. Added Bam.Core.Module.ClosingPatch. This is a patch using the same delegate as a private patch, but is guaranteed to be executed after all other patches, i.e. so that the Module's Settings object is in its final state (i.e. just before the settings are converted to a command line or project file). Only a single closing patch is possible per module. This allows some logic on the final settings to be evaluated, such as to set a macro to be used in other TokenizedStrings (since they are expanded after patches are evaluated), or to modify a setting (e.g. add a preprocessor define based on other settings).
1 parent 064bfa7 commit 35f24e2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Bam.Core/Module.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,32 @@ public PackageDefinition PackageDefinition
421421
/// <summary>
422422
/// Add a private patch to the current module. Usually this takes the form of a lambda function.
423423
/// </summary>
424-
/// <param name="dlg">Dlg.</param>
424+
/// <param name="dlg">The delegate to execute privately on the module.</param>
425425
public void
426426
PrivatePatch(
427427
PrivatePatchDelegate dlg)
428428
{
429429
this.PrivatePatches.Add(dlg);
430430
}
431431

432+
/// <summary>
433+
/// Add a closing patch to the current module, using the same delegate as a private patch.
434+
/// There can only be one closing patch on a module.
435+
/// It is always executed after all other patches, and thus can assume that the module's Settings object has all of its
436+
/// properties in their final state just prior to execution.
437+
/// </summary>
438+
/// <param name="dlg">The delegate to execute as a closing patch on the module.</param>
439+
public void
440+
ClosingPatch(
441+
PrivatePatchDelegate dlg)
442+
{
443+
if (null != this.TheClosingPatch)
444+
{
445+
throw new Exception("Module {0} already has a closing patch", this);
446+
}
447+
this.TheClosingPatch = dlg;
448+
}
449+
432450
/// <summary>
433451
/// Delegate used for public-scope patching of Settings. Note that appliedTo is the module on which
434452
/// this delegate is being applied.
@@ -438,7 +456,7 @@ public void
438456
/// <summary>
439457
/// Add a public patch to the current module. Usually this takes the form of a lambda function.
440458
/// </summary>
441-
/// <param name="dlg">Dlg.</param>
459+
/// <param name="dlg">The delegate to execute on the module, and on its dependees.</param>
442460
public void
443461
PublicPatch(
444462
PublicPatchDelegate dlg)
@@ -482,7 +500,8 @@ public bool HasPatches
482500
{
483501
return (this.PrivatePatches.Count() > 0) ||
484502
(this.PublicPatches.Count() > 0) ||
485-
(this.PublicInheritedPatches.Count() > 0);
503+
(this.PublicInheritedPatches.Count() > 0) ||
504+
(null != this.TheClosingPatch);
486505
}
487506
}
488507

@@ -556,6 +575,7 @@ public System.Collections.ObjectModel.ReadOnlyCollection<Module> Children
556575
private System.Collections.Generic.List<PublicPatchDelegate> PublicPatches = new System.Collections.Generic.List<PublicPatchDelegate>();
557576
private System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>> PublicInheritedPatches = new System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>>();
558577
private System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>> PrivateInheritedPatches = new System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>>();
578+
private PrivatePatchDelegate TheClosingPatch = null;
559579

560580
/// <summary>
561581
/// Get the dictionary of keys and strings for all registered generated paths with the module.
@@ -687,6 +707,7 @@ public void
687707
/// 6. Apply public patches of this.
688708
/// 7. If this is a child module, and honourParents is true, apply any inherited patches from the parent.
689709
/// 8. Apply inherited public patches of this.
710+
/// Once all patches have been evaluated, if the module has a closing patch, this is now evaluated.
690711
/// Inherited patches are the mechanism for transient dependencies, where dependencies filter up the module hierarchy.
691712
/// See UsePublicPatches and UsePublicPatchesPrivately.
692713
/// </summary>
@@ -761,6 +782,10 @@ public void
761782
patch(settings, this);
762783
}
763784
}
785+
if (null != TheClosingPatch)
786+
{
787+
TheClosingPatch(settings);
788+
}
764789
}
765790

766791
/// <summary>

Changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
18-Apr-2016 Fixes #228. Added Bam.Core.Module.ClosingPatch. This is a patch using the same delegate as a private patch, but is guaranteed to be executed after all other patches, i.e. so that the Module's Settings object is in its final state (i.e. just before the settings are converted to a command line or project file). Only a single closing patch is possible per module. This allows some logic on the final settings to be evaluated, such as to set a macro to be used in other TokenizedStrings (since they are expanded after patches are evaluated), or to modify a setting (e.g. add a preprocessor define based on other settings).
2+
13
16-Apr-2016 Fixes #227. Added Bam.Core.PackageDirectoryRedirectAttribute, an attribute associated with an assembly, requiring a package name, an optional package version, and a redirected path. By default, the macro $(packagedir) is the directory containing the 'bam' folder. Should the source code for a package reside in a different location to that directory, this attribute can be placed anywhere in the compiled code for your packages, and the macro $(packagedir) is redirected to the specified path for that package. The redirect path can either be an absolute path, or a path relative to the directory containing the 'bam' folder. Such attributes could be placed in project specific locations, independent of package definitions. Modified the ProxyTest test package to demonstrate.
24

35
15-Apr-2016 Fixes #225. Specifying a package version override on the command line, which does not match the unique package version contained in all the definition files, will now report an error, rather than using the unique package version. For example, if VisualC-12.0 is the only version of the package in all definition files, but --VisualC.version=14.0 was on the command line, this now causes an error rather than just using 12.0.

0 commit comments

Comments
 (0)