@joebigelow / wix-1 / commits / 5ba862bf

Add support for loading Intermediates from extensions

Rob Mensching committed Dec 6, 2017 at 11:39 UTC 5ba862bfa618c89a563d555e8ce7b44a904df406
17 files changed +40 -52
src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
+2 -5
@@ -28,19 +28,16 @@ namespace WixToolset.Core.Bind
28 /// <returns>The extract path for the embedded file.</returns>
29 public string AddEmbeddedFileIndex(Uri uri, int embeddedFileIndex, string tempPath)
30 {
31 - string extractPath;
32 - SortedList<int, string> extracts;
33 -
31 // If the uri to the file that contains the embedded file does not already have embedded files
32 // being extracted, create the dictionary to track that.
36 - if (!filesWithEmbeddedFiles.TryGetValue(uri, out extracts))
33 + if (!filesWithEmbeddedFiles.TryGetValue(uri, out var extracts))
34 {
35 extracts = new SortedList<int, string>();
36 filesWithEmbeddedFiles.Add(uri, extracts);
37 }
38
39 // If the embedded file is not already tracked in the dictionary of extracts, add it.
43 - if (!extracts.TryGetValue(embeddedFileIndex, out extractPath))
40 + if (!extracts.TryGetValue(embeddedFileIndex, out var extractPath))
41 {
42 string localFileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath);
43 string unique = this.HashUri(uri.AbsoluteUri);
src/WixToolset.Core/CommandLine/BuildCommand.cs
+3 -1
@@ -168,8 +168,10 @@ namespace WixToolset.Core
168 var context = this.ServiceProvider.GetService<ILinkContext>();
169 context.Messaging = Messaging.Instance;
170 context.Extensions = this.ExtensionManager.Create<ILinkerExtension>();
171 - context.Intermediates = intermediates.Union(libraries).ToList();
171 + context.ExtensionData = this.ExtensionManager.Create<IExtensionData>();
172 context.ExpectedOutputType = this.OutputType;
173 + context.Intermediates = intermediates.Union(libraries).ToList();
174 + context.TupleDefinitionCreator = creator;
175
176 var linker = new Linker();
177 var output = linker.Link(context);
src/WixToolset.Core/LinkContext.cs
+4
@@ -21,8 +21,12 @@ namespace WixToolset.Core
21
22 public IEnumerable<ILinkerExtension> Extensions { get; set; }
23
24 + public IEnumerable<IExtensionData> ExtensionData { get; set; }
25 +
26 public OutputType ExpectedOutputType { get; set; }
27
28 public IEnumerable<Intermediate> Intermediates { get; set; }
29 +
30 + public ITupleDefinitionCreator TupleDefinitionCreator { get; set; }
31 }
32 }
src/WixToolset.Core/Linker.cs
+11 -41
@@ -55,32 +55,6 @@ namespace WixToolset.Core
55 /// <value>The Wix variable resolver.</value>
56 //internal IBindVariableResolver WixVariableResolver { get; set; }
57
58 - /// <summary>
59 - /// Adds an extension.
60 - /// </summary>
61 - /// <param name="extension">The extension to add.</param>
62 - //public void AddExtensionData(IExtensionData extension)
63 - //{
64 - // if (null != extension.TableDefinitions)
65 - // {
66 - // foreach (TableDefinition tableDefinition in extension.TableDefinitions)
67 - // {
68 - // if (!this.tableDefinitions.Contains(tableDefinition.Name))
69 - // {
70 - // this.tableDefinitions.Add(tableDefinition);
71 - // }
72 - // else
73 - // {
74 - // throw new WixException(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name));
75 - // }
76 - // }
77 - // }
78 -
79 - // // keep track of extension data so the libraries can be loaded from these later once all the table definitions
80 - // // are loaded; this will allow extensions to have cross table definition dependencies
81 - // this.extensionData.Add(extension);
82 - //}
83 -
58 /// <summary>
59 /// Links a collection of sections into an output.
60 /// </summary>
@@ -91,10 +65,19 @@ namespace WixToolset.Core
65 {
66 this.Context = context ?? throw new ArgumentNullException(nameof(context));
67
94 - //IEnumerable<Section> inputs, OutputType expectedOutputType
95 -
68 var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList();
69
70 + // Add sections from the extensions with data.
71 + foreach (var data in context.ExtensionData)
72 + {
73 + var library = data.GetLibrary(context.TupleDefinitionCreator);
74 +
75 + if (library != null)
76 + {
77 + sections.AddRange(library.Sections);
78 + }
79 + }
80 +
81 #if MOVE_TO_BACKEND
82 bool containsModuleSubstitution = false;
83 bool containsModuleConfiguration = false;
@@ -144,19 +127,6 @@ namespace WixToolset.Core
127 }
128 #endif
129
147 -#if TODO
148 - // Add sections from the extensions with data.
149 - foreach (IExtensionData data in this.extensionData)
150 - {
151 - Library library = data.GetLibrary(this.tableDefinitions);
152 -
153 - if (null != library)
154 - {
155 - sections.AddRange(library.Sections);
156 - }
157 - }
158 -#endif
159 -
130 // First find the entry section and while processing all sections load all the symbols from all of the sections.
131 // sections.FindEntrySectionAndLoadSymbols(false, this, expectedOutputType, out entrySection, out allSymbols);
132 var find = new FindEntrySectionAndLoadSymbolsCommand(sections);
src/test/TestData/Example.Extension/Data/example.txt new
+1
@@ -0,0 +1 @@
1 +This is example.txt.
\ No newline at end of file
src/test/TestData/Example.Extension/Data/example.wir
Binary files /dev/null and b/src/test/TestData/Example.Extension/Data/example.wir differ
src/test/TestData/Example.Extension/Data/example.wxs new
+8
@@ -0,0 +1,8 @@
1 +<?xml version='1.0'?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <Property Id="PropertyFromExampleWir" Value="FromWir" />
5 +
6 + <Binary Id="BinFromWir" SourceFile="example.txt" />
7 + </Fragment>
8 +</Wix>
src/test/TestData/Example.Extension/Example.Extension.csproj renamed
+4
@@ -7,6 +7,10 @@
7 <IsPackable>false</IsPackable>
8 </PropertyGroup>
9
10 + <ItemGroup>
11 + <EmbeddedResource Include="Data\Example.wir" />
12 + </ItemGroup>
13 +
14 <ItemGroup>
15 <ProjectReference Include="$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj" Condition=" '$(Configuration)' == 'Debug' And Exists('$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj') " />
16 <PackageReference Include="WixToolset.Data" Version="4.0.*" Condition=" '$(Configuration)' == 'Release' Or !Exists('$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj') " />
src/test/TestData/Example.Extension/ExampleCompilerExtension.cs renamed
src/test/TestData/Example.Extension/ExampleExtensionData.cs renamed
+1 -1
@@ -11,7 +11,7 @@ namespace Example.Extension
11
12 public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions)
13 {
14 - return null;
14 + return Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions);
15 }
16
17 public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
src/test/TestData/Example.Extension/ExampleExtensionFactory.cs renamed
src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs renamed
src/test/TestData/Example.Extension/ExampleTuple.cs renamed
src/test/TestData/Example.Extension/TupleDefinitions.cs renamed
src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs
+3 -3
@@ -44,13 +44,13 @@ namespace WixToolsetTest.CoreIntegration
44 Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\MsiPackage\example.txt")));
45
46 var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"bin\extest.wir"));
47 - Assert.Single(intermediate.Sections);
47 + var section = intermediate.Sections.Single();
48
49 - var wixFile = intermediate.Sections.SelectMany(s => s.Tuples).OfType<WixFileTuple>().Single();
49 + var wixFile = section.Tuples.OfType<WixFileTuple>().Single();
50 Assert.Equal(Path.Combine(folder, @"data\example.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path);
51 Assert.Equal(@"example.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path);
52
53 - var example = intermediate.Sections.SelectMany(s => s.Tuples).Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).Single();
53 + var example = section.Tuples.Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).Single();
54 Assert.Equal("Foo", example.Id.Id);
55 Assert.Equal("Foo", example[0].AsString());
56 Assert.Equal("Bar", example[1].AsString());
src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs
+2
@@ -8,6 +8,8 @@
8
9 <Property Id="ExampleProperty" Value="$(ex.Test)" />
10
11 + <PropertyRef Id="PropertyFromExampleWir" />
12 +
13 <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
14 <ComponentGroupRef Id="ProductComponents" />
15 </Feature>
src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj
+1 -1
@@ -31,7 +31,7 @@
31
32 <ItemGroup>
33 <ProjectReference Include="..\..\wix\wix.csproj" />
34 - <ProjectReference Include="..\Example.Extension\Example.Extension.csproj" />
34 + <ProjectReference Include="..\TestData\Example.Extension\Example.Extension.csproj" />
35 </ItemGroup>
36
37 <ItemGroup>