diff options
Diffstat (limited to '')
-rw-r--r-- | src/candle/candle.cs | 200 | ||||
-rw-r--r-- | src/candle/candle.csproj | 62 |
2 files changed, 262 insertions, 0 deletions
diff --git a/src/candle/candle.cs b/src/candle/candle.cs new file mode 100644 index 00000000..f5c65cb1 --- /dev/null +++ b/src/candle/candle.cs | |||
@@ -0,0 +1,200 @@ | |||
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.Tools | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Linq; | ||
9 | using System.Runtime.InteropServices; | ||
10 | using System.Xml.Linq; | ||
11 | using WixToolset.Data; | ||
12 | using WixToolset.Extensibility; | ||
13 | |||
14 | /// <summary> | ||
15 | /// The main entry point for candle. | ||
16 | /// </summary> | ||
17 | public sealed class Candle | ||
18 | { | ||
19 | private CandleCommandLine commandLine; | ||
20 | |||
21 | private IEnumerable<IPreprocessorExtension> preprocessorExtensions; | ||
22 | private IEnumerable<ICompilerExtension> compilerExtensions; | ||
23 | private IEnumerable<IExtensionData> extensionData; | ||
24 | |||
25 | /// <summary> | ||
26 | /// The main entry point for candle. | ||
27 | /// </summary> | ||
28 | /// <param name="args">Commandline arguments for the application.</param> | ||
29 | /// <returns>Returns the application error code.</returns> | ||
30 | [MTAThread] | ||
31 | public static int Main(string[] args) | ||
32 | { | ||
33 | AppCommon.PrepareConsoleForLocalization(); | ||
34 | Messaging.Instance.InitializeAppName("CNDL", "candle.exe").Display += AppCommon.ConsoleDisplayMessage; | ||
35 | |||
36 | Candle candle = new Candle(); | ||
37 | return candle.Execute(args); | ||
38 | } | ||
39 | |||
40 | private int Execute(string[] args) | ||
41 | { | ||
42 | try | ||
43 | { | ||
44 | string[] unparsed = this.ParseCommandLineAndLoadExtensions(args); | ||
45 | |||
46 | if (!Messaging.Instance.EncounteredError) | ||
47 | { | ||
48 | if (this.commandLine.ShowLogo) | ||
49 | { | ||
50 | AppCommon.DisplayToolHeader(); | ||
51 | } | ||
52 | |||
53 | if (this.commandLine.ShowHelp) | ||
54 | { | ||
55 | Console.WriteLine(CandleStrings.HelpMessage); | ||
56 | AppCommon.DisplayToolFooter(); | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | foreach (string arg in unparsed) | ||
61 | { | ||
62 | Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(arg)); | ||
63 | } | ||
64 | |||
65 | this.Run(); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | catch (WixException we) | ||
70 | { | ||
71 | Messaging.Instance.OnMessage(we.Error); | ||
72 | } | ||
73 | catch (Exception e) | ||
74 | { | ||
75 | Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); | ||
76 | if (e is NullReferenceException || e is SEHException) | ||
77 | { | ||
78 | throw; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return Messaging.Instance.LastErrorNumber; | ||
83 | } | ||
84 | |||
85 | private string[] ParseCommandLineAndLoadExtensions(string[] args) | ||
86 | { | ||
87 | this.commandLine = new CandleCommandLine(); | ||
88 | string[] unprocessed = commandLine.Parse(args); | ||
89 | if (Messaging.Instance.EncounteredError) | ||
90 | { | ||
91 | return unprocessed; | ||
92 | } | ||
93 | |||
94 | // Load extensions. | ||
95 | ExtensionManager extensionManager = new ExtensionManager(); | ||
96 | foreach (string extension in this.commandLine.Extensions) | ||
97 | { | ||
98 | extensionManager.Load(extension); | ||
99 | } | ||
100 | |||
101 | // Preprocessor extension command line processing. | ||
102 | this.preprocessorExtensions = extensionManager.Create<IPreprocessorExtension>(); | ||
103 | foreach (IExtensionCommandLine pce in this.preprocessorExtensions.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>()) | ||
104 | { | ||
105 | pce.MessageHandler = Messaging.Instance; | ||
106 | unprocessed = pce.ParseCommandLine(unprocessed); | ||
107 | } | ||
108 | |||
109 | // Compiler extension command line processing. | ||
110 | this.compilerExtensions = extensionManager.Create<ICompilerExtension>(); | ||
111 | foreach (IExtensionCommandLine cce in this.compilerExtensions.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>()) | ||
112 | { | ||
113 | cce.MessageHandler = Messaging.Instance; | ||
114 | unprocessed = cce.ParseCommandLine(unprocessed); | ||
115 | } | ||
116 | |||
117 | // Extension data command line processing. | ||
118 | this.extensionData = extensionManager.Create<IExtensionData>(); | ||
119 | foreach (IExtensionCommandLine dce in this.extensionData.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>()) | ||
120 | { | ||
121 | dce.MessageHandler = Messaging.Instance; | ||
122 | unprocessed = dce.ParseCommandLine(unprocessed); | ||
123 | } | ||
124 | |||
125 | return commandLine.ParsePostExtensions(unprocessed); | ||
126 | } | ||
127 | |||
128 | private void Run() | ||
129 | { | ||
130 | // Create the preprocessor and compiler | ||
131 | Preprocessor preprocessor = new Preprocessor(); | ||
132 | preprocessor.CurrentPlatform = this.commandLine.Platform; | ||
133 | |||
134 | foreach (string includePath in this.commandLine.IncludeSearchPaths) | ||
135 | { | ||
136 | preprocessor.IncludeSearchPaths.Add(includePath); | ||
137 | } | ||
138 | |||
139 | foreach (IPreprocessorExtension pe in this.preprocessorExtensions) | ||
140 | { | ||
141 | preprocessor.AddExtension(pe); | ||
142 | } | ||
143 | |||
144 | Compiler compiler = new Compiler(); | ||
145 | compiler.ShowPedanticMessages = this.commandLine.ShowPedanticMessages; | ||
146 | compiler.CurrentPlatform = this.commandLine.Platform; | ||
147 | |||
148 | foreach (IExtensionData ed in this.extensionData) | ||
149 | { | ||
150 | compiler.AddExtensionData(ed); | ||
151 | } | ||
152 | |||
153 | foreach (ICompilerExtension ce in this.compilerExtensions) | ||
154 | { | ||
155 | compiler.AddExtension(ce); | ||
156 | } | ||
157 | |||
158 | // Preprocess then compile each source file. | ||
159 | foreach (CompileFile file in this.commandLine.Files) | ||
160 | { | ||
161 | // print friendly message saying what file is being compiled | ||
162 | Console.WriteLine(file.SourcePath); | ||
163 | |||
164 | // preprocess the source | ||
165 | XDocument sourceDocument; | ||
166 | try | ||
167 | { | ||
168 | if (!String.IsNullOrEmpty(this.commandLine.PreprocessFile)) | ||
169 | { | ||
170 | preprocessor.PreprocessOut = this.commandLine.PreprocessFile.Equals("con:", StringComparison.OrdinalIgnoreCase) ? Console.Out : new StreamWriter(this.commandLine.PreprocessFile); | ||
171 | } | ||
172 | |||
173 | sourceDocument = preprocessor.Process(file.SourcePath, this.commandLine.PreprocessorVariables); | ||
174 | } | ||
175 | finally | ||
176 | { | ||
177 | if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) | ||
178 | { | ||
179 | preprocessor.PreprocessOut.Close(); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | // If we're not actually going to compile anything, move on to the next file. | ||
184 | if (null == sourceDocument || !String.IsNullOrEmpty(this.commandLine.PreprocessFile)) | ||
185 | { | ||
186 | continue; | ||
187 | } | ||
188 | |||
189 | // and now we do what we came here to do... | ||
190 | Intermediate intermediate = compiler.Compile(sourceDocument); | ||
191 | |||
192 | // save the intermediate to disk if no errors were found for this source file | ||
193 | if (null != intermediate) | ||
194 | { | ||
195 | intermediate.Save(file.OutputPath); | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | } | ||
diff --git a/src/candle/candle.csproj b/src/candle/candle.csproj new file mode 100644 index 00000000..cea0cf62 --- /dev/null +++ b/src/candle/candle.csproj | |||
@@ -0,0 +1,62 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <!-- 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. --> | ||
3 | |||
4 | |||
5 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> | ||
6 | <PropertyGroup> | ||
7 | <ProjectGuid>{956401A5-3C04-4786-9611-B2AEC6207686}</ProjectGuid> | ||
8 | <AssemblyName>candle</AssemblyName> | ||
9 | <OutputType>Exe</OutputType> | ||
10 | <RootNamespace>WixToolset.Tools</RootNamespace> | ||
11 | <PlatformTarget>x86</PlatformTarget> | ||
12 | </PropertyGroup> | ||
13 | <ItemGroup> | ||
14 | <Compile Include="AssemblyInfo.cs" /> | ||
15 | <Compile Include="candle.cs" /> | ||
16 | <Compile Include="CandleCommandLine.cs" /> | ||
17 | <Compile Include="CompileFile.cs" /> | ||
18 | <Compile Include="CandleStrings.Designer.cs"> | ||
19 | <AutoGen>True</AutoGen> | ||
20 | <DesignTime>True</DesignTime> | ||
21 | <DependentUpon>CandleStrings.resx</DependentUpon> | ||
22 | </Compile> | ||
23 | </ItemGroup> | ||
24 | <ItemGroup> | ||
25 | <EmbeddedNativeResource Include="candle.rc" /> | ||
26 | </ItemGroup> | ||
27 | <ItemGroup> | ||
28 | <None Include="app.config" /> | ||
29 | </ItemGroup> | ||
30 | <ItemGroup> | ||
31 | <EmbeddedResource Include="CandleStrings.resx"> | ||
32 | <SubType>Designer</SubType> | ||
33 | <Generator>ResXFileCodeGenerator</Generator> | ||
34 | <LastGenOutput>CandleStrings.Designer.cs</LastGenOutput> | ||
35 | </EmbeddedResource> | ||
36 | </ItemGroup> | ||
37 | <ItemGroup> | ||
38 | <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" /> | ||
39 | </ItemGroup> | ||
40 | <ItemGroup> | ||
41 | <Reference Include="System" /> | ||
42 | <Reference Include="System.Xml" /> | ||
43 | <ProjectReference Include="..\..\libs\WixToolset.Data\WixToolset.Data.csproj"> | ||
44 | <Project>{6a98499e-40ec-4335-9c31-96a2511d47c6}</Project> | ||
45 | <Name>WixToolset.Data</Name> | ||
46 | </ProjectReference> | ||
47 | <ProjectReference Include="..\..\libs\WixToolset.Extensibility\WixToolset.Extensibility.csproj"> | ||
48 | <Project>{eee88c2a-45a0-4e48-a40a-431a4ba458d8}</Project> | ||
49 | <Name>WixToolset.Extensibility</Name> | ||
50 | </ProjectReference> | ||
51 | <ProjectReference Include="..\wconsole\wconsole.csproj"> | ||
52 | <Project>{4B2BD779-59F7-4BF1-871C-A75952BCA749}</Project> | ||
53 | <Name>wconsole</Name> | ||
54 | </ProjectReference> | ||
55 | <ProjectReference Include="..\wix\Wix.csproj"> | ||
56 | <Project>{9E03A94C-C70E-45C6-A269-E737BBD8B319}</Project> | ||
57 | <Name>Wix</Name> | ||
58 | </ProjectReference> | ||
59 | <Reference Include="System.Xml.Linq" /> | ||
60 | </ItemGroup> | ||
61 | <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), wix.proj))\tools\WixBuild.targets" /> | ||
62 | </Project> | ||