-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSkc.cs
More file actions
466 lines (438 loc) · 18 KB
/
Copy pathSkc.cs
File metadata and controls
466 lines (438 loc) · 18 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Utilities;
using Microsoft.Build.Tasks;
using System.IO;
using Microsoft.Build.Framework;
using System.Diagnostics;
using System.Globalization;
using System.Collections.Specialized;
using System.Collections;
//using SharpKit.Build.Tasks.CsbService.Client;
using System.Configuration;
using JSharp.Compiler;
using cs2java.Tasks;
//using System.ServiceModel.Configuration;
//using System.ServiceModel;
namespace SharpKit.Build.Tools
{
public class Cs2Java : ManagedCompiler
{
public Cs2Java()
{
UseBuildService = true;
}
protected override string GenerateFullPathToTool()
{
return Path.Combine(ToolPath, ToolExe);
}
private static bool IsLegalIdentifier(string identifier)
{
if (identifier.Length == 0)
{
return false;
}
if (!TokenChar.IsLetter(identifier[0]) && (identifier[0] != '_'))
{
return false;
}
for (int i = 1; i < identifier.Length; i++)
{
char c = identifier[i];
if (((!TokenChar.IsLetter(c) && !TokenChar.IsDecimalDigit(c)) && (!TokenChar.IsConnecting(c) && !TokenChar.IsCombining(c))) && !TokenChar.IsFormatting(c))
{
return false;
}
}
return true;
}
internal string GetDefineConstantsSwitch(string originalDefineConstants)
{
if (originalDefineConstants != null)
{
StringBuilder builder = new StringBuilder();
foreach (string str in originalDefineConstants.Split(new char[] { ',', ';', ' ' }))
{
if (IsLegalIdentifier(str))
{
if (builder.Length > 0)
{
builder.Append(";");
}
builder.Append(str);
}
else if (str.Length > 0)
{
base.Log.LogWarningWithCodeFromResources("Csc.InvalidParameterWarning", new object[] { "/define:", str });
}
}
if (builder.Length > 0)
{
return builder.ToString();
}
}
return null;
}
public ITaskItem[] NoneFiles { get; set; }
public ITaskItem[] ContentFiles { get; set; }
public ITaskItem[] SkcPlugins { get; set; }
protected override void AddResponseFileCommands(CommandLineBuilderExtension commandLine)
{
if (OutputGeneratedFile != null && !String.IsNullOrEmpty(OutputGeneratedFile.ItemSpec))
commandLine.AppendSwitchIfNotNull("/outputgeneratedfile:", OutputGeneratedFile);
commandLine.AppendSwitchUnquotedIfNotNull("/define:", this.GetDefineConstantsSwitch(base.DefineConstants));
this.AddReferencesToCommandLine(commandLine);
base.AddResponseFileCommands(commandLine);
if (ResponseFiles != null)
{
foreach (ITaskItem item in ResponseFiles)
{
commandLine.AppendSwitchIfNotNull("@", item.ItemSpec);
}
}
if (ContentFiles != null)
{
foreach (var file in ContentFiles)
{
commandLine.AppendSwitchIfNotNull("/contentfile:", file.ItemSpec);
}
}
if (NoneFiles != null)
{
foreach (var file in NoneFiles)
{
commandLine.AppendSwitchIfNotNull("/nonefile:", file.ItemSpec);
}
}
if (SkcPlugins != null)
{
foreach (var file in SkcPlugins)
{
commandLine.AppendSwitchIfNotNull("/plugin:", file.ItemSpec);
}
}
if (SkcRebuild)
commandLine.AppendSwitch("/rebuild");
if (UseBuildService)
{
Log.LogMessage("CurrentDirectory is: " + Directory.GetCurrentDirectory());
commandLine.AppendSwitchIfNotNull("/dir:", Directory.GetCurrentDirectory());
}
commandLine.AppendSwitchIfNotNull("/TargetFrameworkVersion:", TargetFrameworkVersion);
}
private void AddReferencesToCommandLine(CommandLineBuilderExtension commandLine)
{
if ((base.References != null) && (base.References.Length != 0))
{
foreach (ITaskItem item in base.References)
{
string metadata = item.GetMetadata("Aliases");
if ((metadata == null) || (metadata.Length == 0))
{
commandLine.AppendSwitchIfNotNull("/reference:", item.ItemSpec);
}
else
{
foreach (string str2 in metadata.Split(new char[] { ',' }))
{
string str3 = str2.Trim();
if (str2.Length != 0)
{
if (str3.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1)
{
throw new ArgumentException("Csc.AssemblyAliasContainsIllegalCharacters" + item.ItemSpec + str3);
}
if (string.Compare("global", str3, StringComparison.OrdinalIgnoreCase) == 0)
{
commandLine.AppendSwitchIfNotNull("/reference:", item.ItemSpec);
}
else
{
throw new NotImplementedException("TODO: Implement");
//commandLine.AppendSwitchAliased("/reference:", str3, item.ItemSpec);
}
}
}
}
}
}
}
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
base.LogEventsFromTextOutput(singleLine, messageImportance);
}
protected override MessageImportance StandardOutputLoggingImportance
{
get
{
return MessageImportance.High;
}
}
[Output]
public ITaskItem OutputGeneratedFile { get; set; }
private string GetTemporaryResponseFile(string responseFileCommands, out string responseFileSwitch)
{
string path = null;
responseFileSwitch = null;
if (!string.IsNullOrEmpty(responseFileCommands))
{
try
{
path = Path.GetTempFileName();
}
catch (IOException exception)
{
throw new IOException("Shared.FailedCreatingTempFile", exception);
}
using (StreamWriter writer = new StreamWriter(path, false, this.ResponseFileEncoding))
{
writer.Write(responseFileCommands);
}
responseFileSwitch = this.GetResponseFileSwitch(path);
}
return path;
}
public bool UseHostCompilerIfAvailable { get; set; }
public string TargetFrameworkVersion { get; set; }
public bool UseBuildService { get; set; }
public bool SkcRebuild { get; set; }
string OutputGeneratedDir;
string AssemblyFilenameWithoutExtension;
public override bool Execute()
{
var outputAssembly = OutputAssembly.ItemSpec;
OutputGeneratedDir = Path.GetDirectoryName(outputAssembly);
AssemblyFilenameWithoutExtension = Path.GetFileNameWithoutExtension(outputAssembly);
OutputAssembly.ItemSpec = Path.Combine(OutputGeneratedDir, Path.GetFileName(outputAssembly));
if (UseBuildService)
{
var args = new CompilerToolArgs();
AddResponseFileCommands2(args);
var res = new CompilerServiceClient().Compile(new CompileRequest { Args = args });
foreach (var s in res.Output)
{
LogEventsFromTextOutput(s, MessageImportance.High);
}
return res.ExitCode == 0;
}
else
{
var success = base.Execute();
return success;
}
}
protected override bool CallHostObjectToExecute()
{
return base.CallHostObjectToExecute();
}
protected override string ToolName
{
get
{
return "skc.exe";
}
}
void BaseAddResponseFileCommands(CompilerToolArgs args)
{
if (this.OutputAssembly == null && this.Sources != null && this.Sources.Length > 0 && this.ResponseFiles == null)
{
try
{
this.OutputAssembly = new TaskItem(Path.GetFileNameWithoutExtension(this.Sources[0].ItemSpec));
}
catch (ArgumentException ex)
{
throw new ArgumentException(ex.Message, "Sources");
}
if (string.Compare(this.TargetType, "library", StringComparison.OrdinalIgnoreCase) == 0)
{
ITaskItem expr_79 = this.OutputAssembly;
expr_79.ItemSpec += ".dll";
}
else
{
if (string.Compare(this.TargetType, "module", StringComparison.OrdinalIgnoreCase) == 0)
{
ITaskItem expr_A9 = this.OutputAssembly;
expr_A9.ItemSpec += ".netmodule";
}
else
{
ITaskItem expr_C6 = this.OutputAssembly;
expr_C6.ItemSpec += ".exe";
}
}
}
// commandLine.AppendSwitchIfNotNull("/addmodule:", this.AddModules, ",");
// commandLine.AppendSwitchWithInteger("/codepage:", base.Bag, "CodePage");
// this.ConfigureDebugProperties();
// commandLine.AppendPlusOrMinusSwitch("/debug", base.Bag, "EmitDebugInformation");
// commandLine.AppendSwitchIfNotNull("/debug:", this.DebugType);
// commandLine.AppendPlusOrMinusSwitch("/delaysign", base.Bag, "DelaySign");
// commandLine.AppendSwitchWithInteger("/filealign:", base.Bag, "FileAlignment");
// commandLine.AppendSwitchIfNotNull("/keycontainer:", this.KeyContainer);
// commandLine.AppendSwitchIfNotNull("/keyfile:", this.KeyFile);
// commandLine.AppendSwitchIfNotNull("/linkresource:", this.LinkResources, new string[]
//{
// "LogicalName",
// "Access"
//});
// commandLine.AppendWhenTrue("/nologo", base.Bag, "NoLogo");
// commandLine.AppendWhenTrue("/nowin32manifest", base.Bag, "NoWin32Manifest");
// commandLine.AppendPlusOrMinusSwitch("/optimize", base.Bag, "Optimize");
args.Output = OutputAssembly.ItemSpec;
//commandLine.AppendSwitchIfNotNull("/out:", this.OutputAssembly);
// commandLine.AppendSwitchIfNotNull("/subsystemversion:", this.SubsystemVersion);
// commandLine.AppendSwitchIfNotNull("/resource:", this.Resources, new string[]
//{
// "LogicalName",
// "Access"
//});
args.Target = TargetType;
//commandLine.AppendSwitchIfNotNull("/target:", this.TargetType);
//commandLine.AppendPlusOrMinusSwitch("/warnaserror", base.Bag, "TreatWarningsAsErrors");
//commandLine.AppendWhenTrue("/utf8output", base.Bag, "Utf8Output");
//commandLine.AppendSwitchIfNotNull("/win32icon:", this.Win32Icon);
//commandLine.AppendSwitchIfNotNull("/win32manifest:", this.Win32Manifest);
args.Files.AddRange(Sources.Select(t => t.ItemSpec).ToList());
//commandLine.AppendFileNamesIfNotNull(this.Sources, " ");
}
protected void AddResponseFileCommands2(CompilerToolArgs args)
{
if (OutputGeneratedFile != null && !String.IsNullOrEmpty(OutputGeneratedFile.ItemSpec))
args.OutputGeneratedFile = OutputGeneratedFile.ItemSpec;
args.define = this.GetDefineConstantsSwitch(base.DefineConstants);
this.AddReferencesToCommandLine2(args);
BaseAddResponseFileCommands(args);
if (ResponseFiles != null)
{
foreach (ITaskItem item in ResponseFiles)
{
throw new Exception();
//commandLine.AppendSwitchIfNotNull("@", item.ItemSpec);
}
}
if (ContentFiles != null)
{
foreach (var file in ContentFiles)
{
args.ContentFiles.Add(file.ItemSpec);
}
}
if (NoneFiles != null)
{
foreach (var file in NoneFiles)
{
args.NoneFiles.Add(file.ItemSpec);
}
}
if (SkcPlugins != null)
{
foreach (var file in SkcPlugins)
{
args.Plugins.Add(file.ItemSpec);
}
}
if (SkcRebuild)
args.rebuild = true;
if (UseBuildService)
{
args.CurrentDirectory = Directory.GetCurrentDirectory();
}
args.TargetFrameworkVersion = TargetFrameworkVersion;
}
private void AddReferencesToCommandLine2(CompilerToolArgs args)
{
if ((base.References != null) && (base.References.Length != 0))
{
foreach (ITaskItem item in base.References)
{
string metadata = item.GetMetadata("Aliases");
if ((metadata == null) || (metadata.Length == 0))
{
args.References.Add(item.ItemSpec);
}
else
{
foreach (string str2 in metadata.Split(new char[] { ',' }))
{
string str3 = str2.Trim();
if (str2.Length != 0)
{
if (str3.IndexOfAny(new char[] { ',', ' ', ';', '"' }) != -1)
{
throw new ArgumentException("Csc.AssemblyAliasContainsIllegalCharacters" + item.ItemSpec + str3);
}
if (string.Compare("global", str3, StringComparison.OrdinalIgnoreCase) == 0)
{
args.References.Add(item.ItemSpec);
}
else
{
throw new NotImplementedException("TODO: Implement");
//commandLine.AppendSwitchAliased("/reference:", str3, item.ItemSpec);
}
}
}
}
}
}
}
}
internal static class TokenChar
{
// Methods
internal static bool IsCombining(char c)
{
UnicodeCategory unicodeCategory = char.GetUnicodeCategory(c);
if ((unicodeCategory != UnicodeCategory.NonSpacingMark) && (unicodeCategory != UnicodeCategory.SpacingCombiningMark))
{
return false;
}
return true;
}
internal static bool IsConnecting(char c)
{
return (char.GetUnicodeCategory(c) == UnicodeCategory.ConnectorPunctuation);
}
internal static bool IsDecimalDigit(char c)
{
return (char.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber);
}
internal static bool IsFormatting(char c)
{
return (char.GetUnicodeCategory(c) == UnicodeCategory.Format);
}
internal static bool IsHexDigit(char c)
{
if ((((c < '0') || (c > '9')) && ((c < 'A') || (c > 'F'))) && ((c < 'a') || (c > 'f')))
{
return false;
}
return true;
}
internal static bool IsLetter(char c)
{
UnicodeCategory unicodeCategory = char.GetUnicodeCategory(c);
if ((((unicodeCategory != UnicodeCategory.UppercaseLetter) && (unicodeCategory != UnicodeCategory.LowercaseLetter)) && ((unicodeCategory != UnicodeCategory.TitlecaseLetter) && (unicodeCategory != UnicodeCategory.ModifierLetter))) && ((unicodeCategory != UnicodeCategory.OtherLetter) && (unicodeCategory != UnicodeCategory.LetterNumber)))
{
return false;
}
return true;
}
internal static bool IsNewLine(char c)
{
if (((c != '\r') && (c != '\n')) && (c != '\u2028'))
{
return (c == '\u2029');
}
return true;
}
internal static bool IsOctalDigit(char c)
{
return ((c >= '0') && (c <= '7'));
}
}
}