aboutsummaryrefslogtreecommitdiff
path: root/src/candle/CandleCommandLine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/candle/CandleCommandLine.cs')
-rw-r--r--src/candle/CandleCommandLine.cs343
1 files changed, 0 insertions, 343 deletions
diff --git a/src/candle/CandleCommandLine.cs b/src/candle/CandleCommandLine.cs
deleted file mode 100644
index 81fdf7b2..00000000
--- a/src/candle/CandleCommandLine.cs
+++ /dev/null
@@ -1,343 +0,0 @@
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
3namespace WixToolset.Tools
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Globalization;
8 using System.IO;
9 using WixToolset.Data;
10
11 /// <summary>
12 /// Parse command line for candle.
13 /// </summary>
14 public class CandleCommandLine
15 {
16 public CandleCommandLine()
17 {
18 this.Platform = Platform.X86;
19
20 this.ShowLogo = true;
21 this.Extensions = new List<string>();
22 this.Files = new List<CompileFile>();
23 this.IncludeSearchPaths = new List<string>();
24 this.PreprocessorVariables = new Dictionary<string, string>();
25 }
26
27 public Platform Platform { get; private set; }
28
29 public bool ShowLogo { get; private set; }
30
31 public bool ShowHelp { get; private set; }
32
33 public bool ShowPedanticMessages { get; private set; }
34
35 public string OutputFolder { get; private set; }
36
37 public string OutputFile { get; private set; }
38
39 public List<string> Extensions { get; private set; }
40
41 public List<CompileFile> Files { get; private set; }
42
43 public List<string> IncludeSearchPaths { get; private set; }
44
45 public string PreprocessFile { get; private set; }
46
47 public Dictionary<string, string> PreprocessorVariables { get; private set; }
48
49 /// <summary>
50 /// Parse the commandline arguments.
51 /// </summary>
52 /// <param name="args">Commandline arguments.</param>
53 public string[] Parse(string[] args)
54 {
55 List<string> unprocessed = new List<string>();
56
57 for (int i = 0; i < args.Length; ++i)
58 {
59 string arg = args[i];
60 if (String.IsNullOrEmpty(arg)) // skip blank arguments
61 {
62 continue;
63 }
64
65 if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves.
66 {
67 unprocessed.Add(arg);
68 }
69 else if ('-' == arg[0] || '/' == arg[0])
70 {
71 string parameter = arg.Substring(1);
72 if ('d' == parameter[0])
73 {
74 if (1 >= parameter.Length || '=' == parameter[1])
75 {
76 Messaging.Instance.OnMessage(WixErrors.InvalidVariableDefinition(arg));
77 break;
78 }
79
80 parameter = arg.Substring(2);
81
82 string[] value = parameter.Split("=".ToCharArray(), 2);
83
84 if (this.PreprocessorVariables.ContainsKey(value[0]))
85 {
86 Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], this.PreprocessorVariables[value[0]]));
87 break;
88 }
89
90 if (1 == value.Length)
91 {
92 this.PreprocessorVariables.Add(value[0], String.Empty);
93 }
94 else
95 {
96 this.PreprocessorVariables.Add(value[0], value[1]);
97 }
98 }
99 else if ('I' == parameter[0])
100 {
101 this.IncludeSearchPaths.Add(parameter.Substring(1));
102 }
103 else if ("ext" == parameter)
104 {
105 if (!CommandLine.IsValidArg(args, ++i))
106 {
107 Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext"));
108 break;
109 }
110 else
111 {
112 this.Extensions.Add(args[i]);
113 }
114 }
115 else if ("nologo" == parameter)
116 {
117 this.ShowLogo = false;
118 }
119 else if ("o" == parameter || "out" == parameter)
120 {
121 string path = CommandLine.GetFileOrDirectory(parameter, args, ++i);
122
123 if (!String.IsNullOrEmpty(path))
124 {
125 if (path.EndsWith("\\", StringComparison.Ordinal) || path.EndsWith("/", StringComparison.Ordinal))
126 {
127 this.OutputFolder = path;
128 }
129 else
130 {
131 this.OutputFile = path;
132 }
133 }
134 else
135 {
136 break;
137 }
138 }
139 else if ("pedantic" == parameter)
140 {
141 this.ShowPedanticMessages = true;
142 }
143 else if ("arch" == parameter)
144 {
145 if (!CommandLine.IsValidArg(args, ++i))
146 {
147 Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, String.Empty));
148 break;
149 }
150
151 if (String.Equals(args[i], "intel", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "x86", StringComparison.OrdinalIgnoreCase))
152 {
153 this.Platform = Platform.X86;
154 }
155 else if (String.Equals(args[i], "x64", StringComparison.OrdinalIgnoreCase))
156 {
157 this.Platform = Platform.X64;
158 }
159 else if (String.Equals(args[i], "intel64", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "ia64", StringComparison.OrdinalIgnoreCase))
160 {
161 this.Platform = Platform.IA64;
162 }
163 else if (String.Equals(args[i], "arm", StringComparison.OrdinalIgnoreCase))
164 {
165 this.Platform = Platform.ARM;
166 }
167 else
168 {
169 Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, args[i]));
170 }
171 }
172 else if ('p' == parameter[0])
173 {
174 string file = parameter.Substring(1);
175 this.PreprocessFile = String.IsNullOrEmpty(file) ? "con:" : file;
176 }
177 else if (parameter.StartsWith("sw", StringComparison.Ordinal))
178 {
179 string paramArg = parameter.Substring(2);
180 try
181 {
182 if (0 == paramArg.Length)
183 {
184 Messaging.Instance.SuppressAllWarnings = true;
185 }
186 else
187 {
188 int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat);
189 if (0 >= suppressWarning)
190 {
191 Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg));
192 }
193
194 Messaging.Instance.SuppressWarningMessage(suppressWarning);
195 }
196 }
197 catch (FormatException)
198 {
199 Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg));
200 }
201 catch (OverflowException)
202 {
203 Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg));
204 }
205 }
206 else if (parameter.StartsWith("wx", StringComparison.Ordinal))
207 {
208 string paramArg = parameter.Substring(2);
209 try
210 {
211 if (0 == paramArg.Length)
212 {
213 Messaging.Instance.WarningsAsError = true;
214 }
215 else
216 {
217 int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat);
218 if (0 >= elevateWarning)
219 {
220 Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg));
221 }
222
223 Messaging.Instance.ElevateWarningMessage(elevateWarning);
224 }
225 }
226 catch (FormatException)
227 {
228 Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg));
229 }
230 catch (OverflowException)
231 {
232 Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg));
233 }
234 }
235 else if ("v" == parameter)
236 {
237 Messaging.Instance.ShowVerboseMessages = true;
238 }
239 else if ("?" == parameter || "help" == parameter)
240 {
241 this.ShowHelp = true;
242 break;
243 }
244 else
245 {
246 unprocessed.Add(arg);
247 }
248 }
249 else if ('@' == arg[0])
250 {
251 string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1));
252 string[] unparsedArgs = this.Parse(parsedArgs);
253 unprocessed.AddRange(unparsedArgs);
254 }
255 else
256 {
257 unprocessed.Add(arg);
258 }
259 }
260
261 return unprocessed.ToArray();
262 }
263
264 public string[] ParsePostExtensions(string[] remaining)
265 {
266 List<string> unprocessed = new List<string>();
267 List<string> files = new List<string>();
268
269 for (int i = 0; i < remaining.Length; ++i)
270 {
271 string arg = remaining[i];
272 if (String.IsNullOrEmpty(arg)) // skip blank arguments
273 {
274 continue;
275 }
276
277 if (1 < arg.Length && ('-' == arg[0] || '/' == arg[0]))
278 {
279 unprocessed.Add(arg);
280 }
281 else
282 {
283 files.AddRange(CommandLine.GetFiles(arg, "Source"));
284 }
285 }
286
287 if (0 == files.Count)
288 {
289 this.ShowHelp = true;
290 }
291 else
292 {
293 Dictionary<string, List<string>> sourcesForOutput = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
294 foreach (string file in files)
295 {
296 string sourceFileName = Path.GetFileName(file);
297
298 CompileFile compileFile = new CompileFile();
299 compileFile.SourcePath = Path.GetFullPath(file);
300
301 if (null != this.OutputFile)
302 {
303 compileFile.OutputPath = this.OutputFile;
304 }
305 else if (null != this.OutputFolder)
306 {
307 compileFile.OutputPath = Path.Combine(this.OutputFolder, Path.ChangeExtension(sourceFileName, ".wixobj"));
308 }
309 else
310 {
311 compileFile.OutputPath = Path.ChangeExtension(sourceFileName, ".wixobj");
312 }
313
314 // Track which source files result in a given output file, to ensure we aren't
315 // overwriting the output.
316 List<string> sources;
317 string targetPath = Path.GetFullPath(compileFile.OutputPath);
318 if (!sourcesForOutput.TryGetValue(targetPath, out sources))
319 {
320 sources = new List<string>();
321 sourcesForOutput.Add(targetPath, sources);
322 }
323
324 sources.Add(compileFile.SourcePath);
325
326 this.Files.Add(compileFile);
327 }
328
329 // Show an error for every output file that had more than 1 source file.
330 foreach (KeyValuePair<string, List<string>> outputSources in sourcesForOutput)
331 {
332 if (1 < outputSources.Value.Count)
333 {
334 string sourceFiles = String.Join(", ", outputSources.Value);
335 Messaging.Instance.OnMessage(WixErrors.DuplicateSourcesForOutput(sourceFiles, outputSources.Key));
336 }
337 }
338 }
339
340 return unprocessed.ToArray();
341 }
342 }
343}