blob: f5c65cb15be49f77300c917101ae3f238171ff4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
// 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.
namespace WixToolset.Tools
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using WixToolset.Data;
using WixToolset.Extensibility;
/// <summary>
/// The main entry point for candle.
/// </summary>
public sealed class Candle
{
private CandleCommandLine commandLine;
private IEnumerable<IPreprocessorExtension> preprocessorExtensions;
private IEnumerable<ICompilerExtension> compilerExtensions;
private IEnumerable<IExtensionData> extensionData;
/// <summary>
/// The main entry point for candle.
/// </summary>
/// <param name="args">Commandline arguments for the application.</param>
/// <returns>Returns the application error code.</returns>
[MTAThread]
public static int Main(string[] args)
{
AppCommon.PrepareConsoleForLocalization();
Messaging.Instance.InitializeAppName("CNDL", "candle.exe").Display += AppCommon.ConsoleDisplayMessage;
Candle candle = new Candle();
return candle.Execute(args);
}
private int Execute(string[] args)
{
try
{
string[] unparsed = this.ParseCommandLineAndLoadExtensions(args);
if (!Messaging.Instance.EncounteredError)
{
if (this.commandLine.ShowLogo)
{
AppCommon.DisplayToolHeader();
}
if (this.commandLine.ShowHelp)
{
Console.WriteLine(CandleStrings.HelpMessage);
AppCommon.DisplayToolFooter();
}
else
{
foreach (string arg in unparsed)
{
Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(arg));
}
this.Run();
}
}
}
catch (WixException we)
{
Messaging.Instance.OnMessage(we.Error);
}
catch (Exception e)
{
Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
if (e is NullReferenceException || e is SEHException)
{
throw;
}
}
return Messaging.Instance.LastErrorNumber;
}
private string[] ParseCommandLineAndLoadExtensions(string[] args)
{
this.commandLine = new CandleCommandLine();
string[] unprocessed = commandLine.Parse(args);
if (Messaging.Instance.EncounteredError)
{
return unprocessed;
}
// Load extensions.
ExtensionManager extensionManager = new ExtensionManager();
foreach (string extension in this.commandLine.Extensions)
{
extensionManager.Load(extension);
}
// Preprocessor extension command line processing.
this.preprocessorExtensions = extensionManager.Create<IPreprocessorExtension>();
foreach (IExtensionCommandLine pce in this.preprocessorExtensions.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>())
{
pce.MessageHandler = Messaging.Instance;
unprocessed = pce.ParseCommandLine(unprocessed);
}
// Compiler extension command line processing.
this.compilerExtensions = extensionManager.Create<ICompilerExtension>();
foreach (IExtensionCommandLine cce in this.compilerExtensions.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>())
{
cce.MessageHandler = Messaging.Instance;
unprocessed = cce.ParseCommandLine(unprocessed);
}
// Extension data command line processing.
this.extensionData = extensionManager.Create<IExtensionData>();
foreach (IExtensionCommandLine dce in this.extensionData.Where(e => e is IExtensionCommandLine).Cast<IExtensionCommandLine>())
{
dce.MessageHandler = Messaging.Instance;
unprocessed = dce.ParseCommandLine(unprocessed);
}
return commandLine.ParsePostExtensions(unprocessed);
}
private void Run()
{
// Create the preprocessor and compiler
Preprocessor preprocessor = new Preprocessor();
preprocessor.CurrentPlatform = this.commandLine.Platform;
foreach (string includePath in this.commandLine.IncludeSearchPaths)
{
preprocessor.IncludeSearchPaths.Add(includePath);
}
foreach (IPreprocessorExtension pe in this.preprocessorExtensions)
{
preprocessor.AddExtension(pe);
}
Compiler compiler = new Compiler();
compiler.ShowPedanticMessages = this.commandLine.ShowPedanticMessages;
compiler.CurrentPlatform = this.commandLine.Platform;
foreach (IExtensionData ed in this.extensionData)
{
compiler.AddExtensionData(ed);
}
foreach (ICompilerExtension ce in this.compilerExtensions)
{
compiler.AddExtension(ce);
}
// Preprocess then compile each source file.
foreach (CompileFile file in this.commandLine.Files)
{
// print friendly message saying what file is being compiled
Console.WriteLine(file.SourcePath);
// preprocess the source
XDocument sourceDocument;
try
{
if (!String.IsNullOrEmpty(this.commandLine.PreprocessFile))
{
preprocessor.PreprocessOut = this.commandLine.PreprocessFile.Equals("con:", StringComparison.OrdinalIgnoreCase) ? Console.Out : new StreamWriter(this.commandLine.PreprocessFile);
}
sourceDocument = preprocessor.Process(file.SourcePath, this.commandLine.PreprocessorVariables);
}
finally
{
if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut)
{
preprocessor.PreprocessOut.Close();
}
}
// If we're not actually going to compile anything, move on to the next file.
if (null == sourceDocument || !String.IsNullOrEmpty(this.commandLine.PreprocessFile))
{
continue;
}
// and now we do what we came here to do...
Intermediate intermediate = compiler.Compile(sourceDocument);
// save the intermediate to disk if no errors were found for this source file
if (null != intermediate)
{
intermediate.Save(file.OutputPath);
}
}
}
}
}
|