Add intermediate levels to track how IR has been lowered.
Bob Arnson committed
Mar 26, 2020 at 13:31 UTC
271601dfe0990917ef6331fbddcfd1b400882eb2
5 files changed
+78
-3
src/WixToolset.Data/ErrorMessages.cs
+18
@@ -2249,6 +2249,21 @@ namespace WixToolset.Data
2249
return Message(null, Ids.WixiplSourceFileIsExclusive, "When an intermediate post link source file is specified, it must be the only source file provided.");
2250
}
2251
2252
+ public static Message IntermediatesMustBeCompiled(string invalidIntermediates)
2253
+ {
2254
+ return Message(null, Ids.IntermediatesMustBeCompiled, "Intermediates being linked must have been compiled. Intermediates with these ids were not compiled: {0}", invalidIntermediates);
2255
+ }
2256
+
2257
+ public static Message IntermediatesMustBeLinked(string invalidIntermediate)
2258
+ {
2259
+ return Message(null, Ids.IntermediatesMustBeLinked, "Intermediates being resolved must have been linked. This intermediate was not linked: {0}", invalidIntermediate);
2260
+ }
2261
+
2262
+ public static Message IntermediatesMustBeResolved(string invalidIntermediate)
2263
+ {
2264
+ return Message(null, Ids.IntermediatesMustBeResolved, "Intermediates being bound must have been resolved. This intermediate was not resolved: {0}", invalidIntermediate);
2265
+ }
2266
+
2267
private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args)
2268
{
2269
return new Message(sourceLineNumber, MessageLevel.Error, (int)id, format, args);
@@ -2646,6 +2661,9 @@ namespace WixToolset.Data
2661
WixiplSourceFileIsExclusive = 392,
2662
UnableToConvertFieldToNumber = 393,
2663
CouldNotDetermineProductCodeFromTransformSummaryInfo = 394,
2664
+ IntermediatesMustBeCompiled = 395,
2665
+ IntermediatesMustBeLinked = 396,
2666
+ IntermediatesMustBeResolved = 397,
2667
}
2668
}
2669
}
src/WixToolset.Data/Intermediate.cs
+33
-2
@@ -29,9 +29,14 @@ namespace WixToolset.Data
29
this.Sections = new List<IntermediateSection>();
30
}
31
32
- public Intermediate(string id, IEnumerable<IntermediateSection> sections, IDictionary<string, Localization> localizationsByCulture)
32
+ public Intermediate(string id, IEnumerable<IntermediateSection> sections, IDictionary<string, Localization> localizationsByCulture) : this(id, level: null, sections, localizationsByCulture)
33
+ {
34
+ }
35
+
36
+ public Intermediate(string id, string level, IEnumerable<IntermediateSection> sections, IDictionary<string, Localization> localizationsByCulture)
37
{
38
this.Id = id;
39
+ this.Level = level;
40
this.localizationsByCulture = (localizationsByCulture != null) ? new Dictionary<string, Localization>(localizationsByCulture, StringComparer.OrdinalIgnoreCase) : new Dictionary<string, Localization>(StringComparer.OrdinalIgnoreCase);
41
this.Sections = (sections != null) ? new List<IntermediateSection>(sections) : new List<IntermediateSection>();
42
}
@@ -41,6 +46,11 @@ namespace WixToolset.Data
46
/// </summary>
47
public string Id { get; }
48
49
+ /// <summary>
50
+ /// Get the id for the intermediate.
51
+ /// </summary>
52
+ public string Level { get; private set; }
53
+
54
/// <summary>
55
/// Get the localizations contained in this intermediate.
56
/// </summary>
@@ -181,6 +191,25 @@ namespace WixToolset.Data
191
return intermediates;
192
}
193
194
+ /// <summary>
195
+ /// Updates the intermediate level to the specified level.
196
+ /// </summary>
197
+ /// <param name="level">Intermediate level.</param>
198
+ public void UpdateLevel(string level)
199
+ {
200
+ this.Level = String.IsNullOrEmpty(this.Level) ? level : String.Concat(this.Level, ";", level);
201
+ }
202
+
203
+ /// <summary>
204
+ /// Returns whether a specifed intermediate level has been set for this intermediate.
205
+ /// </summary>
206
+ /// <param name="level">Intermediate level.</param>
207
+ /// <returns>True if the specifed intermediate level has been set for this intermediate.</returns>
208
+ public bool HasLevel(string level)
209
+ {
210
+ return this.Level?.Contains(level) == true;
211
+ }
212
+
213
/// <summary>
214
/// Saves an intermediate to a path on disk.
215
/// </summary>
@@ -277,6 +306,7 @@ namespace WixToolset.Data
306
private static Intermediate FinalizeLoad(JsonObject json, Uri baseUri, ITupleDefinitionCreator creator)
307
{
308
var id = json.GetValueOrDefault<string>("id");
309
+ var level = json.GetValueOrDefault<string>("level");
310
311
var sections = new List<IntermediateSection>();
312
@@ -296,7 +326,7 @@ namespace WixToolset.Data
326
localizations.Add(localization.Culture, localization);
327
}
328
299
- return new Intermediate(id, sections, localizations);
329
+ return new Intermediate(id, level, sections, localizations);
330
}
331
332
private void SaveEmbedFiles(WixOutput wixout)
@@ -351,6 +381,7 @@ namespace WixToolset.Data
381
var jsonObject = new JsonObject
382
{
383
{ "id", this.Id },
384
+ { "level", this.Level },
385
{ "version", Intermediate.CurrentVersion.ToString() }
386
};
387
src/WixToolset.Data/IntermediateLevels.cs
new
+9
@@ -0,0 +1,9 @@
1
+namespace WixToolset.Data
2
+{
3
+ public static class IntermediateLevels
4
+ {
5
+ public const string Compiled = "compiled";
6
+ public const string Linked = "linked";
7
+ public const string Resolved = "resolved";
8
+ }
9
+}
src/WixToolset.Data/WindowsInstaller/IntermediateLevels.cs
new
+9
@@ -0,0 +1,9 @@
1
+namespace WixToolset.Data.WindowsInstaller
2
+{
3
+ public static class IntermediateLevels
4
+ {
5
+ // TODO: These are placeholder names until we (hopefully) come up with better ones.
6
+ public const string PartiallyBound = "msiPartiallyBound";
7
+ public const string FullyBound = "msiFullyBound";
8
+ }
9
+}
src/test/WixToolsetTest.Data/SerializeFixture.cs
+9
-1
@@ -26,13 +26,21 @@ namespace WixToolsetTest.Data
26
Location = ComponentLocation.Either,
27
});
28
29
- var intermediate = new Intermediate("TestIntermediate", new[] { section }, null);
29
+ var intermediate = new Intermediate("TestIntermediate", IntermediateLevels.Compiled, new[] { section }, null);
30
+
31
+ intermediate.UpdateLevel(IntermediateLevels.Linked);
32
+ intermediate.UpdateLevel(IntermediateLevels.Resolved);
33
34
var path = Path.GetTempFileName();
35
intermediate.Save(path);
36
37
var loaded = Intermediate.Load(path);
38
39
+ Assert.True(loaded.HasLevel(IntermediateLevels.Compiled));
40
+ Assert.True(loaded.HasLevel(IntermediateLevels.Linked));
41
+ Assert.True(loaded.HasLevel(IntermediateLevels.Resolved));
42
+ Assert.False(loaded.HasLevel(WixToolset.Data.WindowsInstaller.IntermediateLevels.PartiallyBound));
43
+
44
var tuple = (ComponentTuple)loaded.Sections.Single().Tuples.Single();
45
46
Assert.Equal("TestComponent", tuple.Id.Id);