Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tools/compilembed/program.cs

raw
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace compilembed
9 {
10 // Reference:
11 // https://os.mbed.com/handbook/Compile-API
12
13 class Program
14 {
15 private const string userNameOption = "-un";
16 private const string passwordOption = "-pwd";
17 private const string repoOption = "-r";
18 private const string platformOption = "-plat";
19 private const string downloadOutputLocationOption = "-o";
20
21 static void Main(string[] args)
22 {
23 MBEDOnlineCompile onlineCompile;
24 string userName = string.Empty;
25 string password = string.Empty;
26 string repo = string.Empty;
27 string platform = string.Empty;
28 string downloadOutputPath = string.Empty;
29
30 for (int i = 0; i < args.Length; i++)
31 {
32 if (args[i] == userNameOption)
33 {
34 i++;
35 if (i < args.Length)
36 {
37 userName = args[i];
38 }
39 }
40
41 if (args[i] == passwordOption)
42 {
43 i++;
44 if (i < args.Length)
45 {
46 password = args[i];
47 }
48 }
49
50 if (args[i] == repoOption)
51 {
52 i++;
53 if (i < args.Length)
54 {
55 repo = args[i];
56 }
57 }
58
59 if (args[i] == platformOption)
60 {
61 i++;
62 if (i < args.Length)
63 {
64 platform = args[i];
65 }
66 }
67
68 if (args[i] == downloadOutputLocationOption)
69 {
70 i++;
71 if (i < args.Length)
72 {
73 downloadOutputPath = args[i];
74 }
75 }
76 }
77
78 if (string.IsNullOrEmpty(userName) ||
79 string.IsNullOrEmpty(password) ||
80 string.IsNullOrEmpty(repo) ||
81 string.IsNullOrEmpty(platform))
82 {
83 System.Console.WriteLine("Usage:");
84 System.Console.WriteLine(string.Format("-{0:10} UserName to be used to access the MBED online compiler", userNameOption));
85 System.Console.WriteLine(string.Format("-{0:10} Password to be used to access the MBED online compiler", passwordOption));
86 System.Console.WriteLine(string.Format("-{0:10} Repo to be compiled", repoOption));
87 System.Console.WriteLine(string.Format("-{0:10} Platform to be compiled", platformOption));
88 System.Console.WriteLine(string.Format("-{0:10} Path where the compiled binary should be saved on (If not provided, file is not downloaded).", downloadOutputPath));
89
90 Environment.ExitCode = 2;
91 }
92 else
93 {
94 onlineCompile = new MBEDOnlineCompile(userName, password);
95
96 System.Console.WriteLine("Starting compile ...");
97 onlineCompile.StartCompile(platform, null, repo);
98
99 ICollection<string> messages = new List<string>();
100 bool failed = false;
101
102 while (!onlineCompile.PollStatus(messages, out failed))
103 {
104 foreach (string msg in messages)
105 {
106 System.Console.WriteLine(msg);
107 }
108
109 messages.Clear();
110 }
111
112 if (failed)
113 {
114 System.Console.WriteLine("Compile FAILED!");
115 Environment.ExitCode = 1;
116 }
117 else
118 {
119 if (!String.IsNullOrWhiteSpace(downloadOutputPath))
120 {
121 Console.WriteLine("Downloading compiled binary into '{0}' ...", downloadOutputPath);
122
123 try
124 {
125 onlineCompile.DownloadBin(downloadOutputPath);
126 }
127 catch (Exception ex)
128 {
129 Console.WriteLine("Failed downloading binary file: {0}", ex.ToString());
130 }
131 }
132
133 System.Console.WriteLine("Done.");
134 }
135 }
136 }
137 }
138 }