aboutsummaryrefslogtreecommitdiff
path: root/src/light/LightCommandLine.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2018-07-19 00:58:00 -0700
committerRob Mensching <rob@firegiant.com>2018-07-21 07:36:59 -0700
commit2724cfee4c163f3297ee25edfd2372767cfd4945 (patch)
tree8cdda34c83bea014a586a491e3b4b187ad8f16da /src/light/LightCommandLine.cs
parent4d40bef9cf51b8cff7e1f6a73fdf68b9722eb8a0 (diff)
downloadwix-2724cfee4c163f3297ee25edfd2372767cfd4945.tar.gz
wix-2724cfee4c163f3297ee25edfd2372767cfd4945.tar.bz2
wix-2724cfee4c163f3297ee25edfd2372767cfd4945.zip
Move tool projects to Tools repo
Diffstat (limited to 'src/light/LightCommandLine.cs')
-rw-r--r--src/light/LightCommandLine.cs421
1 files changed, 0 insertions, 421 deletions
diff --git a/src/light/LightCommandLine.cs b/src/light/LightCommandLine.cs
deleted file mode 100644
index 2aa9ea59..00000000
--- a/src/light/LightCommandLine.cs
+++ /dev/null
@@ -1,421 +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 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services;
12
13 public class LightCommandLine
14 {
15 public LightCommandLine(IMessaging messaging)
16 {
17 this.Messaging = messaging;
18 this.ShowLogo = true;
19 this.Tidy = true;
20
21 this.CubeFiles = new List<string>();
22 this.SuppressIces = new List<string>();
23 this.Ices = new List<string>();
24 this.BindPaths = new List<BindPath>();
25 this.Files = new List<string>();
26 this.LocalizationFiles = new List<string>();
27 this.Variables = new Dictionary<string, string>();
28 }
29
30 public IMessaging Messaging { get; }
31
32 public string PdbFile { get; private set; }
33
34 public CompressionLevel? DefaultCompressionLevel { get; set; }
35
36 public bool SuppressAclReset { get; private set; }
37
38 public bool SuppressLayout { get; private set; }
39
40 public bool SuppressWixPdb { get; private set; }
41
42 public bool SuppressValidation { get; private set; }
43
44 public string IntermediateFolder { get; private set; }
45
46 public string OutputsFile { get; private set; }
47
48 public string BuiltOutputsFile { get; private set; }
49
50 public string WixprojectFile { get; private set; }
51
52 public string ContentsFile { get; private set; }
53
54 public List<string> Ices { get; private set; }
55
56 public string CabCachePath { get; private set; }
57
58 public int CabbingThreadCount { get; private set; }
59
60 public List<string> CubeFiles { get; private set; }
61
62 public List<string> SuppressIces { get; private set; }
63
64 public bool ShowLogo { get; private set; }
65
66 public bool ShowHelp { get; private set; }
67
68 public bool ShowPedanticMessages { get; private set; }
69
70 public bool SuppressLocalization { get; private set; }
71
72 public bool SuppressVersionCheck { get; private set; }
73
74 public string[] Cultures { get; private set; }
75
76 public string OutputFile { get; private set; }
77
78 public bool OutputXml { get; private set; }
79
80 public List<BindPath> BindPaths { get; private set; }
81
82 public List<string> Files { get; private set; }
83
84 public List<string> LocalizationFiles { get; private set; }
85
86 public bool Tidy { get; private set; }
87
88 public string UnreferencedSymbolsFile { get; private set; }
89
90 public IDictionary<string, string> Variables { get; private set; }
91
92 /// <summary>
93 /// Parse the commandline arguments.
94 /// </summary>
95 /// <param name="args">Commandline arguments.</param>
96 public string[] Parse(ICommandLineContext context)
97 {
98 var unprocessed = new List<string>();
99
100 var extensions = context.ExtensionManager.Create<IExtensionCommandLine>();
101
102 foreach (var extension in extensions)
103 {
104 extension.PreParse(context);
105 }
106
107 var parser = context.Arguments.Parse();
108
109 while (!this.ShowHelp &&
110 String.IsNullOrEmpty(parser.ErrorArgument) &&
111 parser.TryGetNextSwitchOrArgument(out var arg))
112 {
113 if (String.IsNullOrWhiteSpace(arg)) // skip blank arguments.
114 {
115 continue;
116 }
117
118 if (parser.IsSwitch(arg))
119 {
120 var parameter = arg.Substring(1);
121 if (parameter.Equals("b", StringComparison.Ordinal))
122 {
123 var result = parser.GetNextArgumentOrError(arg);
124 if (!String.IsNullOrEmpty(result))
125 {
126 var bindPath = BindPath.Parse(result);
127
128 this.BindPaths.Add(bindPath);
129 }
130 }
131 else if (parameter.StartsWith("cultures:", StringComparison.Ordinal))
132 {
133 string culturesString = arg.Substring(10).ToLower(CultureInfo.InvariantCulture);
134
135 // When null is used treat it as if cultures wasn't specified.
136 // This is needed for batching over the light task when using MSBuild which doesn't
137 // support empty items
138 if (culturesString.Equals("null", StringComparison.OrdinalIgnoreCase))
139 {
140 this.Cultures = null;
141 }
142 else
143 {
144 this.Cultures = culturesString.Split(';', ',');
145
146 for (int c = 0; c < this.Cultures.Length; ++c)
147 {
148 // Neutral is different from null. For neutral we still want to do WXL filtering.
149 // Set the culture to the empty string = identifier for the invariant culture
150 if (this.Cultures[c].Equals("neutral", StringComparison.OrdinalIgnoreCase))
151 {
152 this.Cultures[c] = String.Empty;
153 }
154 }
155 }
156 }
157 else if (parameter.StartsWith("dcl:", StringComparison.Ordinal))
158 {
159 string defaultCompressionLevel = arg.Substring(5);
160
161 if (String.IsNullOrEmpty(defaultCompressionLevel))
162 {
163 break;
164 }
165 else if (Enum.TryParse(defaultCompressionLevel, true, out CompressionLevel compressionLevel))
166 {
167 this.DefaultCompressionLevel = compressionLevel;
168 }
169 }
170 else if (parameter.StartsWith("d", StringComparison.Ordinal))
171 {
172 parameter = arg.Substring(2);
173 string[] value = parameter.Split("=".ToCharArray(), 2);
174
175 string preexisting;
176 if (1 == value.Length)
177 {
178 this.Messaging.Write(ErrorMessages.ExpectedWixVariableValue(value[0]));
179 }
180 else if (this.Variables.TryGetValue(value[0], out preexisting))
181 {
182 this.Messaging.Write(ErrorMessages.WixVariableCollision(null, value[0]));
183 }
184 else
185 {
186 this.Variables.Add(value[0], value[1]);
187 }
188 }
189 else if (parameter.Equals("loc", StringComparison.Ordinal))
190 {
191 parser.GetNextArgumentAsFilePathOrError(arg, "localization files", this.LocalizationFiles);
192 }
193 else if (parameter.Equals("nologo", StringComparison.Ordinal))
194 {
195 this.ShowLogo = false;
196 }
197 else if (parameter.Equals("notidy", StringComparison.Ordinal))
198 {
199 this.Tidy = false;
200 }
201 else if ("o" == parameter || "out" == parameter)
202 {
203 this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);
204 }
205 else if (parameter.Equals("pedantic", StringComparison.Ordinal))
206 {
207 this.ShowPedanticMessages = true;
208 }
209 else if (parameter.Equals("sloc", StringComparison.Ordinal))
210 {
211 this.SuppressLocalization = true;
212 }
213 else if (parameter.Equals("usf", StringComparison.Ordinal))
214 {
215 this.UnreferencedSymbolsFile = parser.GetNextArgumentAsDirectoryOrError(arg);
216 }
217 else if (parameter.Equals("xo", StringComparison.Ordinal))
218 {
219 this.OutputXml = true;
220 }
221 else if (parameter.Equals("cc", StringComparison.Ordinal))
222 {
223 this.CabCachePath = parser.GetNextArgumentAsDirectoryOrError(arg);
224 }
225 else if (parameter.Equals("ct", StringComparison.Ordinal))
226 {
227 var result = parser.GetNextArgumentOrError(arg);
228 if (!String.IsNullOrEmpty(result))
229 {
230 if (!Int32.TryParse(result, out var ct) || 0 >= ct)
231 {
232 this.Messaging.Write(ErrorMessages.IllegalCabbingThreadCount(result));
233 parser.ErrorArgument = arg;
234 break;
235 }
236
237 this.CabbingThreadCount = ct;
238 this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString()));
239 }
240 }
241 else if (parameter.Equals("cub", StringComparison.Ordinal))
242 {
243 parser.GetNextArgumentAsFilePathOrError(arg, "static validation files", this.CubeFiles);
244 }
245 else if (parameter.StartsWith("ice:", StringComparison.Ordinal))
246 {
247 this.Ices.Add(parameter.Substring(4));
248 }
249 else if (parameter.Equals("intermediatefolder", StringComparison.OrdinalIgnoreCase))
250 {
251 this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg);
252 }
253 else if (parameter.Equals("contentsfile", StringComparison.Ordinal))
254 {
255 this.ContentsFile = parser.GetNextArgumentAsFilePathOrError(arg);
256 }
257 else if (parameter.Equals("outputsfile", StringComparison.Ordinal))
258 {
259 this.OutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
260 }
261 else if (parameter.Equals("builtoutputsfile", StringComparison.Ordinal))
262 {
263 this.BuiltOutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
264 }
265 else if (parameter.Equals("wixprojectfile", StringComparison.Ordinal))
266 {
267 this.WixprojectFile = parser.GetNextArgumentAsFilePathOrError(arg);
268 }
269 else if (parameter.Equals("pdbout", StringComparison.Ordinal))
270 {
271 this.PdbFile = parser.GetNextArgumentAsFilePathOrError(arg);
272 }
273 else if (parameter.StartsWith("sice:", StringComparison.Ordinal))
274 {
275 this.SuppressIces.Add(parameter.Substring(5));
276 }
277 else if (parameter.Equals("sl", StringComparison.Ordinal))
278 {
279 this.SuppressLayout = true;
280 }
281 else if (parameter.Equals("spdb", StringComparison.Ordinal))
282 {
283 this.SuppressWixPdb = true;
284 }
285 else if (parameter.Equals("sacl", StringComparison.Ordinal))
286 {
287 this.SuppressAclReset = true;
288 }
289 else if (parameter.Equals("sval", StringComparison.Ordinal))
290 {
291 this.SuppressValidation = true;
292 }
293 else if ("sv" == parameter)
294 {
295 this.SuppressVersionCheck = true;
296 }
297 else if (parameter.StartsWith("sw", StringComparison.Ordinal))
298 {
299 string paramArg = parameter.Substring(2);
300 if (0 == paramArg.Length)
301 {
302 this.Messaging.SuppressAllWarnings = true;
303 }
304 else
305 {
306 int suppressWarning = 0;
307 if (!Int32.TryParse(paramArg, out suppressWarning) || 0 >= suppressWarning)
308 {
309 this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg));
310 }
311 else
312 {
313 this.Messaging.SuppressWarningMessage(suppressWarning);
314 }
315 }
316 }
317 else if (parameter.StartsWith("wx", StringComparison.Ordinal))
318 {
319 string paramArg = parameter.Substring(2);
320 if (0 == paramArg.Length)
321 {
322 this.Messaging.WarningsAsError = true;
323 }
324 else
325 {
326 int elevateWarning = 0;
327 if (!Int32.TryParse(paramArg, out elevateWarning) || 0 >= elevateWarning)
328 {
329 this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg));
330 }
331 else
332 {
333 this.Messaging.ElevateWarningMessage(elevateWarning);
334 }
335 }
336 }
337 else if ("v" == parameter)
338 {
339 this.Messaging.ShowVerboseMessages = true;
340 }
341 else if ("?" == parameter || "help" == parameter)
342 {
343 this.ShowHelp = true;
344 break;
345 }
346 else if (!this.TryParseCommandLineArgumentWithExtension(arg, parser, extensions))
347 {
348 unprocessed.Add(arg);
349 }
350 }
351 else if (!this.TryParseCommandLineArgumentWithExtension(arg, parser, extensions))
352 {
353 unprocessed.Add(arg);
354 }
355 }
356
357 return this.ParsePostExtensions(parser, unprocessed.ToArray());
358 }
359
360 private string[] ParsePostExtensions(IParseCommandLine parser, string[] remaining)
361 {
362 var unprocessed = new List<string>();
363
364 for (int i = 0; i < remaining.Length; ++i)
365 {
366 var arg = remaining[i];
367
368 if (parser.IsSwitch(arg))
369 {
370 unprocessed.Add(arg);
371 }
372 else
373 {
374 parser.GetArgumentAsFilePathOrError(arg, "source files", this.Files);
375 }
376 }
377
378 if (0 == this.Files.Count)
379 {
380 this.ShowHelp = true;
381 }
382 else if (String.IsNullOrEmpty(this.OutputFile))
383 {
384 if (1 < this.Files.Count)
385 {
386 this.Messaging.Write(ErrorMessages.MustSpecifyOutputWithMoreThanOneInput());
387 }
388
389 // After the linker tells us what the output type actually is, we'll change the ".wix" to the correct extension.
390 this.OutputFile = Path.ChangeExtension(Path.GetFileName(this.Files[0]), ".wix");
391
392 // Add the directories of the input files as unnamed bind paths.
393 foreach (string file in this.Files)
394 {
395 var bindPath = new BindPath(Path.GetDirectoryName(Path.GetFullPath(file)));
396 this.BindPaths.Add(bindPath);
397 }
398 }
399
400 if (!this.SuppressWixPdb && String.IsNullOrEmpty(this.PdbFile) && !String.IsNullOrEmpty(this.OutputFile))
401 {
402 this.PdbFile = Path.ChangeExtension(this.OutputFile, ".wixpdb");
403 }
404
405 return unprocessed.ToArray();
406 }
407
408 private bool TryParseCommandLineArgumentWithExtension(string arg, IParseCommandLine parser, IEnumerable<IExtensionCommandLine> extensions)
409 {
410 foreach (var extension in extensions)
411 {
412 if (extension.TryParseArgument(parser, arg))
413 {
414 return true;
415 }
416 }
417
418 return false;
419 }
420 }
421}