diff options
Diffstat (limited to 'src/ext/Bal/wixext/BalBurnBackendExtension.cs')
-rw-r--r-- | src/ext/Bal/wixext/BalBurnBackendExtension.cs | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/src/ext/Bal/wixext/BalBurnBackendExtension.cs b/src/ext/Bal/wixext/BalBurnBackendExtension.cs new file mode 100644 index 00000000..e8dc7a3e --- /dev/null +++ b/src/ext/Bal/wixext/BalBurnBackendExtension.cs | |||
@@ -0,0 +1,171 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Bal | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Linq; | ||
8 | using WixToolset.Bal.Symbols; | ||
9 | using WixToolset.Data; | ||
10 | using WixToolset.Data.Burn; | ||
11 | using WixToolset.Data.Symbols; | ||
12 | using WixToolset.Extensibility; | ||
13 | |||
14 | public class BalBurnBackendExtension : BaseBurnBackendBinderExtension | ||
15 | { | ||
16 | private static readonly IntermediateSymbolDefinition[] BurnSymbolDefinitions = | ||
17 | { | ||
18 | BalSymbolDefinitions.WixBalBAFactoryAssembly, | ||
19 | BalSymbolDefinitions.WixBalBAFunctions, | ||
20 | BalSymbolDefinitions.WixBalCondition, | ||
21 | BalSymbolDefinitions.WixBalPackageInfo, | ||
22 | BalSymbolDefinitions.WixDncOptions, | ||
23 | BalSymbolDefinitions.WixMbaPrereqInformation, | ||
24 | BalSymbolDefinitions.WixStdbaOptions, | ||
25 | BalSymbolDefinitions.WixStdbaOverridableVariable, | ||
26 | }; | ||
27 | |||
28 | protected override IReadOnlyCollection<IntermediateSymbolDefinition> SymbolDefinitions => BurnSymbolDefinitions; | ||
29 | |||
30 | public override void SymbolsFinalized(IntermediateSection section) | ||
31 | { | ||
32 | base.SymbolsFinalized(section); | ||
33 | |||
34 | var baSymbol = section.Symbols.OfType<WixBootstrapperApplicationDllSymbol>().SingleOrDefault(); | ||
35 | var baId = baSymbol?.Id?.Id; | ||
36 | if (null == baId) | ||
37 | { | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | var isStdBA = baId.StartsWith("WixStandardBootstrapperApplication"); | ||
42 | var isMBA = baId.StartsWith("WixManagedBootstrapperApplicationHost"); | ||
43 | var isDNC = baId.StartsWith("WixDotNetCoreBootstrapperApplicationHost"); | ||
44 | var isSCD = isDNC && this.VerifySCD(section); | ||
45 | |||
46 | if (isDNC) | ||
47 | { | ||
48 | this.FinalizeBAFactorySymbol(section); | ||
49 | } | ||
50 | |||
51 | if (isStdBA || isMBA || isDNC) | ||
52 | { | ||
53 | this.VerifyBAFunctions(section); | ||
54 | } | ||
55 | |||
56 | if (isMBA || (isDNC && !isSCD)) | ||
57 | { | ||
58 | this.VerifyPrereqPackages(section, isDNC); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | private void FinalizeBAFactorySymbol(IntermediateSection section) | ||
63 | { | ||
64 | var factorySymbol = section.Symbols.OfType<WixBalBAFactoryAssemblySymbol>().SingleOrDefault(); | ||
65 | if (null == factorySymbol) | ||
66 | { | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | var factoryPayloadSymbol = section.Symbols.OfType<WixBundlePayloadSymbol>() | ||
71 | .Where(p => p.Id.Id == factorySymbol.PayloadId) | ||
72 | .SingleOrDefault(); | ||
73 | if (null == factoryPayloadSymbol) | ||
74 | { | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | factorySymbol.FilePath = factoryPayloadSymbol.Name; | ||
79 | } | ||
80 | |||
81 | private void VerifyBAFunctions(IntermediateSection section) | ||
82 | { | ||
83 | WixBalBAFunctionsSymbol baFunctionsSymbol = null; | ||
84 | foreach (var symbol in section.Symbols.OfType<WixBalBAFunctionsSymbol>()) | ||
85 | { | ||
86 | if (null == baFunctionsSymbol) | ||
87 | { | ||
88 | baFunctionsSymbol = symbol; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | this.Messaging.Write(BalErrors.MultipleBAFunctions(symbol.SourceLineNumbers)); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | var payloadPropertiesSymbols = section.Symbols.OfType<WixBundlePayloadSymbol>().ToList(); | ||
97 | if (null == baFunctionsSymbol) | ||
98 | { | ||
99 | foreach (var payloadPropertiesSymbol in payloadPropertiesSymbols) | ||
100 | { | ||
101 | if (string.Equals(payloadPropertiesSymbol.Name, "bafunctions.dll", StringComparison.OrdinalIgnoreCase) && | ||
102 | BurnConstants.BurnUXContainerName == payloadPropertiesSymbol.ContainerRef) | ||
103 | { | ||
104 | this.Messaging.Write(BalWarnings.UnmarkedBAFunctionsDLL(payloadPropertiesSymbol.SourceLineNumbers)); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | var payloadId = baFunctionsSymbol.Id; | ||
111 | var bundlePayloadSymbol = payloadPropertiesSymbols.Single(x => payloadId == x.Id); | ||
112 | if (BurnConstants.BurnUXContainerName != bundlePayloadSymbol.ContainerRef) | ||
113 | { | ||
114 | this.Messaging.Write(BalErrors.BAFunctionsPayloadRequiredInUXContainer(baFunctionsSymbol.SourceLineNumbers)); | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | |||
119 | private void VerifyPrereqPackages(IntermediateSection section, bool isDNC) | ||
120 | { | ||
121 | var prereqInfoSymbols = section.Symbols.OfType<WixMbaPrereqInformationSymbol>().ToList(); | ||
122 | if (prereqInfoSymbols.Count == 0) | ||
123 | { | ||
124 | var message = isDNC ? BalErrors.MissingDNCPrereq() : BalErrors.MissingMBAPrereq(); | ||
125 | this.Messaging.Write(message); | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | var foundLicenseFile = false; | ||
130 | var foundLicenseUrl = false; | ||
131 | |||
132 | foreach (var prereqInfoSymbol in prereqInfoSymbols) | ||
133 | { | ||
134 | if (null != prereqInfoSymbol.LicenseFile) | ||
135 | { | ||
136 | if (foundLicenseFile || foundLicenseUrl) | ||
137 | { | ||
138 | this.Messaging.Write(BalErrors.MultiplePrereqLicenses(prereqInfoSymbol.SourceLineNumbers)); | ||
139 | return; | ||
140 | } | ||
141 | |||
142 | foundLicenseFile = true; | ||
143 | } | ||
144 | |||
145 | if (null != prereqInfoSymbol.LicenseUrl) | ||
146 | { | ||
147 | if (foundLicenseFile || foundLicenseUrl) | ||
148 | { | ||
149 | this.Messaging.Write(BalErrors.MultiplePrereqLicenses(prereqInfoSymbol.SourceLineNumbers)); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | foundLicenseUrl = true; | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | |||
158 | private bool VerifySCD(IntermediateSection section) | ||
159 | { | ||
160 | var isSCD = false; | ||
161 | |||
162 | var dncOptions = section.Symbols.OfType<WixDncOptionsSymbol>().SingleOrDefault(); | ||
163 | if (dncOptions != null) | ||
164 | { | ||
165 | isSCD = dncOptions.SelfContainedDeployment != 0; | ||
166 | } | ||
167 | |||
168 | return isSCD; | ||
169 | } | ||
170 | } | ||
171 | } | ||