-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (54 loc) · 1.81 KB
/
Copy pathProgram.cs
File metadata and controls
62 lines (54 loc) · 1.81 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
using System;
using System.IO;
using System.Text;
using Telegram.Generators;
internal static class Program
{
private static int Main(string[] args)
{
string schema = null;
string output = null;
string parsers = null;
for (var i = 0; i < args.Length - 1; i++)
{
switch (args[i])
{
case "--schema":
schema = args[++i];
break;
case "--out":
output = args[++i];
break;
case "--parsers":
parsers = args[++i];
break;
}
}
if (schema == null || output == null)
{
Console.Error.WriteLine("usage: --schema <td_api.tl> --out <directory> [--parsers Reader|Pointer|Both]");
return 1;
}
try
{
var text = SchemaWriter.Write(File.ReadAllText(schema), parsers);
Directory.CreateDirectory(output);
var path = Path.Combine(output, "TdDotNetApi.g.cs");
// Only when it differs: this is a 6 MB compiler input, and restamping it on a build
// where the scheme did not change costs a full recompile.
if (!File.Exists(path) || File.ReadAllText(path) != text)
{
// With the BOM, so the file is byte for byte what AddSource writes on the Roslyn
// path and the two modes stay comparable.
File.WriteAllText(path, text, new UTF8Encoding(true));
}
return 0;
}
catch (Exception ex)
{
// MSBuild reads this back as the Exec failure, so the message is the whole report.
Console.Error.WriteLine(ex.Message);
return 1;
}
}
}