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

Commit 9477f52

Browse files
committed
[packages,C] Fixes #181. POTENTIALLY BREAKING CHANGE. Clarified the use of the 'public' utility functions in the C package. The CompilePubliclyAndLinkAgainst function has moved from C.ConsoleApplication to C.DynamicLibrary and C.Cxx.DynamicLibrary to enforce that 'public' inheritance of patches to dependents are not necessary for executables, but are for dynamic libraries. Added LinkPubliclyAgainst to C.DynamicLibrary and C.Cxx.DynamicLibrary. Added Bam.Core.Module.UsePublicPatchesPrivately, which takes the public patches from a dependent, but only applies them to the build of the current module, rather than forwarding them to any future dependees. Added more documentation to Bam.Core.Module regarding the application of patches. The likely changes to make to existing build scripts is to change CompilePubliclyAndLinkAgainst to CompileAndLinkAgainst in C.ConsoleApplication to C.GuiApplication (particularly for WindowsSDK), or that modules were previously compiling because patches had been leaked through prior to this change.
1 parent eb607a1 commit 9477f52

File tree

16 files changed

+132
-62
lines changed

16 files changed

+132
-62
lines changed

Bam.Core/Module.cs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,29 @@ public void
368368
}
369369

370370
/// <summary>
371-
/// Instruct a module to use the public patches from module.
371+
/// Instruct this module to use the public patches, and any inherited patches, from the dependent module.
372+
/// All inherited patches will be forwarded onto any uses of this module.
372373
/// </summary>
373-
/// <param name="module">Module.</param>
374+
/// <param name="module">Dependent module containing patches to use.</param>
374375
public void
375376
UsePublicPatches(
376377
Module module)
377378
{
378-
this.ExternalPatches.Add(module.PublicPatches);
379-
this.ExternalPatches.AddRange(module.ExternalPatches);
379+
this.PublicInheritedPatches.Add(module.PublicPatches);
380+
this.PublicInheritedPatches.AddRange(module.PublicInheritedPatches);
381+
}
382+
383+
/// <summary>
384+
/// Instruct this module to use the public patches from the dependent module.
385+
/// All patches will be used privately to this module.
386+
/// </summary>
387+
/// <param name="module">Dependent module containing patches to use.</param>
388+
public void
389+
UsePublicPatchesPrivately(
390+
Module module)
391+
{
392+
this.PrivateInheritedPatches.Add(module.PublicPatches);
393+
this.PrivateInheritedPatches.AddRange(module.PublicInheritedPatches);
380394
}
381395

382396
/// <summary>
@@ -389,7 +403,7 @@ public bool HasPatches
389403
{
390404
return (this.PrivatePatches.Count() > 0) ||
391405
(this.PublicPatches.Count() > 0) ||
392-
(this.ExternalPatches.Count() > 0);
406+
(this.PublicInheritedPatches.Count() > 0);
393407
}
394408
}
395409

@@ -461,7 +475,8 @@ public System.Collections.ObjectModel.ReadOnlyCollection<Module> Children
461475

462476
private System.Collections.Generic.List<PrivatePatchDelegate> PrivatePatches = new System.Collections.Generic.List<PrivatePatchDelegate>();
463477
private System.Collections.Generic.List<PublicPatchDelegate> PublicPatches = new System.Collections.Generic.List<PublicPatchDelegate>();
464-
private System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>> ExternalPatches = new System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>>();
478+
private System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>> PublicInheritedPatches = new System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>>();
479+
private System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>> PrivateInheritedPatches = new System.Collections.Generic.List<System.Collections.Generic.List<PublicPatchDelegate>>();
465480

466481
/// <summary>
467482
/// Get the dictionary of keys and strings for all registered generated paths with the module.
@@ -584,9 +599,19 @@ public void
584599

585600
/// <summary>
586601
/// Apply any patches set on the module with the settings for its tool.
587-
/// </summary>
588-
/// <param name="settings">Settings.</param>
589-
/// <param name="honourParents">If set to <c>true</c> honour parents takes private patches from any parent module
602+
/// Order of evaluation is:
603+
/// 1. If this is a child module, and honourParents is true, apply private patches from the parent.
604+
/// 2. Apply private patches of this.
605+
/// 3. Apply inherited private patches of this.
606+
/// 4. If this is a child module, and honourParents is true, apply public patches from the parent.
607+
/// 5. Apply public patches of this.
608+
/// 6. If this is a child module, and honourParents is true, apply any inherited patches from the parent.
609+
/// 7. Apply inherited public patches of this.
610+
/// Inherited patches are the mechanism for transient dependencies, where dependencies filter up the module hierarchy.
611+
/// See UsePublicPatches and UsePublicPatchesPrivately.
612+
/// </summary>
613+
/// <param name="settings">Settings object to apply patches to.</param>
614+
/// <param name="honourParents">If set to <c>true</c>, honourParents takes patches from any parent module
590615
/// and also invokes those if this module is a child.</param>
591616
public void
592617
ApplySettingsPatches(
@@ -611,6 +636,13 @@ public void
611636
{
612637
patch(settings);
613638
}
639+
foreach (var patchList in this.PrivateInheritedPatches)
640+
{
641+
foreach (var patch in patchList)
642+
{
643+
patch(settings, this);
644+
}
645+
}
614646
if (parentModule != null)
615647
{
616648
foreach (var patch in parentModule.PublicPatches)
@@ -624,15 +656,15 @@ public void
624656
}
625657
if (parentModule != null)
626658
{
627-
foreach (var patchList in parentModule.ExternalPatches)
659+
foreach (var patchList in parentModule.PublicInheritedPatches)
628660
{
629661
foreach (var patch in patchList)
630662
{
631663
patch(settings, this);
632664
}
633665
}
634666
}
635-
foreach (var patchList in this.ExternalPatches)
667+
foreach (var patchList in this.PublicInheritedPatches)
636668
{
637669
foreach (var patch in patchList)
638670
{

Changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
25-Mar-2016 Fixes #181. POTENTIALLY BREAKING CHANGE. Clarified the use of the 'public' utility functions in the C package. The CompilePubliclyAndLinkAgainst function has moved from C.ConsoleApplication to C.DynamicLibrary and C.Cxx.DynamicLibrary to enforce that 'public' inheritance of patches to dependents are not necessary for executables, but are for dynamic libraries. Added LinkPubliclyAgainst to C.DynamicLibrary and C.Cxx.DynamicLibrary. Added Bam.Core.Module.UsePublicPatchesPrivately, which takes the public patches from a dependent, but only applies them to the build of the current module, rather than forwarding them to any future dependees. Added more documentation to Bam.Core.Module regarding the application of patches. The likely changes to make to existing build scripts is to change CompilePubliclyAndLinkAgainst to CompileAndLinkAgainst in C.ConsoleApplication to C.GuiApplication (particularly for WindowsSDK), or that modules were previously compiling because patches had been leaked through prior to this change.
2+
13
25-Mar-2016 Fixes #182. When the C# assembly for all the packages in a build fails to compile, an improved error message is now displayed, hinting at using the command line option in bam for enabling debug symbols, and the option to generate a debuggable project in one of the applicable IDEs (VisualStudio/Xamarin Studio/MonoDevelop).
24

35
25-Mar-2016 Fixes #180. C.DynamicLibrary and C.Cxx.DynamicLibrary that identify dynamic library dependencies with CompilePubliclyAndLinkAgainst now forward those dependencies on, just like how StaticLibraries already do. If the public API in dynamic library D is exposed in the public API of dynamic library E, then it is legal for a compilation step dependent on D to invoke calls in E that were not resolved during D's link. This change simplifies writing build scripts in that transient dynamic dependencies no longer need to be manually specified.

packages/C/bam/Scripts/ConsoleApplication.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ConsoleApplication :
3737
CModule
3838
{
3939
protected Bam.Core.Array<Bam.Core.Module> sourceModules = new Bam.Core.Array<Bam.Core.Module>();
40-
private Bam.Core.Array<Bam.Core.Module> linkedModules = new Bam.Core.Array<Bam.Core.Module>();
40+
protected Bam.Core.Array<Bam.Core.Module> linkedModules = new Bam.Core.Array<Bam.Core.Module>();
4141
private ILinkingPolicy Policy = null;
4242

4343
static public Bam.Core.PathKey Key = Bam.Core.PathKey.Generate("ExecutableFile");
@@ -159,6 +159,7 @@ public void
159159

160160
/// <summary>
161161
/// Application is linked against the DependentModule type.
162+
/// Any public patches of DependentModule are applied privately to the Application.
162163
/// </summary>
163164
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
164165
public void
@@ -167,7 +168,7 @@ public void
167168
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
168169
this.DependsOn(dependent);
169170
this.linkedModules.Add(dependent);
170-
this.UsePublicPatches(dependent);
171+
this.UsePublicPatchesPrivately(dependent);
171172
}
172173

173174
/// <summary>
@@ -225,23 +226,7 @@ public void
225226
source.UsePublicPatches(dependent);
226227
}
227228
this.LinkAllForwardedDependenciesFromLibraries(dependent);
228-
}
229-
230-
/// <summary>
231-
/// Specified sources and the application compiles and links against the DependentModule, and the
232-
/// application uses patches from the dependent.
233-
/// </summary>
234-
/// <param name="affectedSource">Required source module.</param>
235-
/// <param name="affectedSources">Optional list of additional sources.</param>
236-
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
237-
public virtual void
238-
CompilePubliclyAndLinkAgainst<DependentModule>(
239-
CModule affectedSource,
240-
params CModule[] additionalSources) where DependentModule : CModule, new()
241-
{
242-
this.CompileAndLinkAgainst<DependentModule>(affectedSource, additionalSources);
243-
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
244-
this.UsePublicPatches(dependent);
229+
this.UsePublicPatchesPrivately(dependent);
245230
}
246231

247232
private void

packages/C/bam/Scripts/CxxDynamicLibrary.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,40 @@ public void
159159
this.UsePublicPatches(dependent);
160160
}
161161

162-
public override void
162+
/// <summary>
163+
/// Specified sources and the application compiles and links against the DependentModule, and the
164+
/// application uses patches from the dependent.
165+
/// </summary>
166+
/// <param name="affectedSource">Required source module.</param>
167+
/// <param name="affectedSources">Optional list of additional sources.</param>
168+
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
169+
public void
163170
CompilePubliclyAndLinkAgainst<DependentModule>(
164171
CModule affectedSource,
165-
params CModule[] additionalSources)
172+
params CModule[] additionalSources) where DependentModule : CModule, new()
166173
{
167174
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
168175
if (dependent is C.DynamicLibrary || dependent is C.Cxx.DynamicLibrary)
169176
{
170177
this.forwardedDeps.AddUnique(dependent);
171178
}
172-
base.CompilePubliclyAndLinkAgainst<DependentModule>(affectedSource, additionalSources);
179+
this.CompileAndLinkAgainst<DependentModule>(affectedSource, additionalSources);
180+
this.UsePublicPatches(dependent);
181+
}
182+
183+
/// <summary>
184+
/// DynamicLibrary is linked against the DependentModule type.
185+
/// Any public patches of DependentModule are applied publicly to the DynamicLibrary, and will be inherited
186+
/// by any module depending on the DynamicLibrary.
187+
/// </summary>
188+
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
189+
public void
190+
LinkPubliclyAgainst<DependentModule>() where DependentModule : CModule, new()
191+
{
192+
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
193+
this.DependsOn(dependent);
194+
this.linkedModules.Add(dependent);
195+
this.UsePublicPatches(dependent);
173196
}
174197

175198
protected sealed override void

packages/C/bam/Scripts/DynamicLibrary.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,44 @@ public void
132132
continue;
133133
}
134134
source.UsePublicPatches(dependent);
135-
this.UsePublicPatches(dependent);
136135
}
136+
this.UsePublicPatches(dependent);
137137
}
138138

139-
public override void
139+
/// <summary>
140+
/// Specified sources and the application compiles and links against the DependentModule, and the
141+
/// application uses patches from the dependent.
142+
/// </summary>
143+
/// <param name="affectedSource">Required source module.</param>
144+
/// <param name="affectedSources">Optional list of additional sources.</param>
145+
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
146+
public void
140147
CompilePubliclyAndLinkAgainst<DependentModule>(
141148
CModule affectedSource,
142-
params CModule[] additionalSources)
149+
params CModule[] additionalSources) where DependentModule : CModule, new()
143150
{
144151
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
145152
if (dependent is C.DynamicLibrary || dependent is C.Cxx.DynamicLibrary)
146153
{
147154
this.forwardedDeps.AddUnique(dependent);
148155
}
149-
base.CompilePubliclyAndLinkAgainst<DependentModule>(affectedSource, additionalSources);
156+
this.CompileAndLinkAgainst<DependentModule>(affectedSource, additionalSources);
157+
this.UsePublicPatches(dependent);
158+
}
159+
160+
/// <summary>
161+
/// DynamicLibrary is linked against the DependentModule type.
162+
/// Any public patches of DependentModule are applied publicly to the DynamicLibrary, and will be inherited
163+
/// by any module depending on the DynamicLibrary.
164+
/// </summary>
165+
/// <typeparam name="DependentModule">The 1st type parameter.</typeparam>
166+
public void
167+
LinkPubliclyAgainst<DependentModule>() where DependentModule : CModule, new()
168+
{
169+
var dependent = Bam.Core.Graph.Instance.FindReferencedModule<DependentModule>();
170+
this.DependsOn(dependent);
171+
this.linkedModules.Add(dependent);
172+
this.UsePublicPatches(dependent);
150173
}
151174

152175
protected sealed override void

packages/C/bam/Scripts/HeaderLibrary.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ protected override void
8282
}
8383
}
8484

85+
/// <summary>
86+
/// Compile against DependentModule.
87+
/// As this is a header only library, this dependency implies a public inheritence of DependentModule's public patches.
88+
/// </summary>
89+
/// <typeparam name="DependentModule">1st generic type</typeparam>
8590
public void
8691
CompileAgainst<DependentModule>() where DependentModule : CModule, new()
8792
{

packages/VisualCCommon/bam/Scripts/Compiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected CompilerBase()
5858
if (meta.UseWindowsSDKPublicPatches)
5959
{
6060
var windowsSDK = Bam.Core.Graph.Instance.FindReferencedModule<WindowsSDK.WindowsSDK>();
61-
this.UsePublicPatches(windowsSDK);
61+
this.UsePublicPatchesPrivately(windowsSDK);
6262
}
6363
}
6464

tests/InstallerTest1/bam/Scripts/Executable.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ protected override void
4444
this.CompileAndLinkAgainst<CStaticLibrary>(source);
4545
this.CompileAndLinkAgainst<CDynamicLibrary>(source);
4646

47-
if (this.BuildEnvironment.Platform.Includes(EPlatform.Windows) &&
48-
this.Linker is VisualCCommon.LinkerBase)
47+
if (this.Linker is VisualCCommon.LinkerBase)
4948
{
50-
this.LinkAgainst<WindowsSDK.WindowsSDK>();
49+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
5150
}
5251

5352
this.PrivatePatch(settings =>
@@ -85,7 +84,7 @@ protected override void
8584
});
8685
if (this.Linker is VisualCCommon.LinkerBase)
8786
{
88-
this.LinkAgainst<WindowsSDK.WindowsSDK>();
87+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
8988
}
9089
}
9190

tests/MultiBitDepthModuleTest/bam/Scripts/MultiBitDepthModuleTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override void
5050
if (this.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows) &&
5151
this.Linker is VisualCCommon.LinkerBase)
5252
{
53-
this.CompilePubliclyAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
53+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
5454
}
5555
}
5656
}
@@ -75,7 +75,7 @@ protected override void
7575
if (this.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows) &&
7676
this.Linker is VisualCCommon.LinkerBase)
7777
{
78-
this.CompilePubliclyAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
78+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
7979
}
8080
}
8181
}

tests/ObjectiveCTest1/bam/Scripts/ObjectiveCTest1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Bam.Core;
3131
namespace ObjectiveCTest1
3232
{
33+
[Bam.Core.PlatformFilter(Bam.Core.EPlatform.Posix)]
3334
sealed class Program :
3435
C.ConsoleApplication
3536
{

tests/PublishingTest1/bam/Scripts/PublishingTest1.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ protected override void
3939
{
4040
base.Init(parent);
4141

42-
this.CreateCSourceContainer("$(packagedir)/source/main.c");
42+
var source = this.CreateCSourceContainer("$(packagedir)/source/main.c");
4343

44-
if (this.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows))
44+
if (this.Linker is VisualCCommon.LinkerBase)
4545
{
46-
if (this.Linker is VisualCCommon.LinkerBase)
47-
{
48-
this.LinkAgainst<WindowsSDK.WindowsSDK>();
49-
}
46+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
5047
}
5148
}
5249
}

tests/Test/bam/Scripts/Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected override void
146146
this.CreateWinResourceContainer("$(packagedir)/resources/win32.rc");
147147
if (this.Linker is VisualCCommon.LinkerBase)
148148
{
149-
this.CompilePubliclyAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
149+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
150150
}
151151
}
152152
}

tests/Test12/bam/Scripts/Test12.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ protected override void
5353
source.AddFile("$(packagedir)/source/osx/osx.cpp");
5454
}
5555

56-
if (this.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows) &&
57-
this.Linker is VisualCCommon.LinkerBase)
56+
if (this.Linker is VisualCCommon.LinkerBase)
5857
{
59-
this.CompilePubliclyAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
58+
this.CompileAndLinkAgainst<WindowsSDK.WindowsSDK>(source);
6059

6160
this.PrivatePatch(settings =>
6261
{

tests/Test15/bam/Scripts/Test15.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ protected override void
7676
// because DynamicLibrary1 pokes out of the public API of DynamicLibrary2, the dependency has to be marked
7777
// as 'public' so that forwarding occurs
7878
this.CompilePubliclyAndLinkAgainst<Test14.DynamicLibrary1>(source);
79+
80+
if (this.Linker is VisualCCommon.LinkerBase)
81+
{
82+
this.LinkAgainst<WindowsSDK.WindowsSDK>();
83+
}
7984
}
8085
}
8186
}

0 commit comments

Comments
 (0)