-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.cs
More file actions
582 lines (544 loc) · 29.1 KB
/
new.cs
File metadata and controls
582 lines (544 loc) · 29.1 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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
namespace Creator_PostBuild
{
class Program
{
const string version = "2.11";
class parseResult_c
{
public object output;
public string message;
public int error;
public bool writeOutput;
public parseResult_c(object output, string message, int error, bool writeOutput)
{
this.output = output;
this.message = message;
this.error = error;
this.writeOutput = writeOutput;
}
public parseResult_c(string message, int error, bool writeOutput)
{
this.message = message;
this.error = error;
this.writeOutput = writeOutput;
}
}
static void Main(string[] args)
{
if (args.Contains("-v") || args.Contains("-version"))
{
Console.WriteLine("version: " + version);
return;
}
Console.WriteLine(
"*****************************************************\r\n" +
"* Creator PostBuild tool " + version + " *\r\n" +
"* The source code of this tool can be found at *\r\n" +
"* https://github.com/RolfNoot/CreatorPostBuild01 *\r\n" +
"* (c) Rolf / Onethinx *\r\n" +
"*****************************************************\r\n"
);
if (args.Length == 0)
{
Console.WriteLine("Error, arguments needed! Run 'Creator_PostBuild.exe -h' for help");
Environment.Exit(1);
}
if (args.Contains("-h") || args.Contains("-help"))
{
Console.WriteLine(
"Run this tool the PSoC Creator project directory\r\n" +
"OPTIONS:\r\n" +
"-v2 : mandatory, v2 for this version. Returns error if v2 not matches.\r\n" +
"-targetOTX : parses cyfitter_cfg.c to cyfitter_otx_cfg.c\r\n" +
" removes the linker file from the linker options.\r\n" +
" parses cy_ble_clk.h to remove SFLASH->RADIO_LDO_TRIMS.\r\n" +
"-keepMain : keep the references to the main project sourcefiles."
);
return;
}
if (!args.Contains("-v2"))
{
Console.WriteLine("Error, arguments not met!\r\nAdapt buildfile for use with this version and fix arguments.");
Environment.Exit(1);
}
bool targetOTX = false;
bool keepMain = false;
if (args.Contains("-targetOTX")) targetOTX = true;
if (args.Contains("-keepMain")) keepMain = true;
string fileExportIDE = Environment.CurrentDirectory + @"\Export\PSoCCreatorExportIDE.xml";
if (!File.Exists(fileExportIDE)) fileExportIDE = Environment.CurrentDirectory + @"\Export\PSoCCreatorExportIDECortexM4.xml";
string fileCyFitter = Environment.CurrentDirectory + @"\Generated_Source\PSoC6\cyfitter_cfg.c";
string fileCyFitterNew = Environment.CurrentDirectory + @"\Generated_Source\PSoC6\cyfitter_cfg_otx.c";
string fileCyBLEclk = Environment.CurrentDirectory + @"\Generated_Source\PSoC6\pdl\middleware\ble\cy_ble_clk.c";
string fileMesonBuild = Environment.CurrentDirectory + @"\..\meson.build";
Console.WriteLine("\r\nTarget file: " + fileExportIDE);
parseResult_c parseXMLfileResult = parseXMLfile(fileExportIDE, keepMain);
xmlResult xmlOut = parseXMLfileResult.output as xmlResult;
if (parseXMLfileResult.message != "") Console.WriteLine(parseXMLfileResult.message);
if (parseXMLfileResult.error == 0)
if (parseXMLfileResult.writeOutput) MergeIncludeFoldersFromOptions(xmlOut, xmlOut.compilerOptions);
{
File.WriteAllLines("sourceFiles.txt", xmlOut.sourceFiles);
File.WriteAllLines("headerIncludeDirs.txt", xmlOut.includeFolders);
File.WriteAllLines("librarySources.txt", xmlOut.libraryFiles);
}
if (parseXMLfileResult.error != 0) Environment.Exit(parseXMLfileResult.error);
if (targetOTX) // Parse of CyFitter File into new file for OTX if needed
{
Console.WriteLine("\r\nTarget file: " + fileCyFitter);
parseResult_c parseCyFitterResult = parseCyFitterCfg(fileCyFitter, xmlOut);
if (parseCyFitterResult.message != "") Console.WriteLine(parseCyFitterResult.message);
if (parseCyFitterResult.writeOutput) File.WriteAllLines(fileCyFitterNew, parseCyFitterResult.output as List<string>);
if (parseCyFitterResult.error != 0) Environment.Exit(parseCyFitterResult.error);
Console.WriteLine("\r\nTarget file: " + fileCyBLEclk);
parseResult_c parseCyBLEclkResult = parseCyBLEclk(fileCyBLEclk);
if (parseCyBLEclkResult.message != "") Console.WriteLine(parseCyBLEclkResult.message);
if (parseCyBLEclkResult.writeOutput) File.WriteAllLines(fileCyBLEclk, parseCyBLEclkResult.output as List<string>);
if (parseCyBLEclkResult.error != 0) Environment.Exit(parseCyBLEclkResult.error);
}
Console.WriteLine("\r\nTarget file: " + fileMesonBuild);
parseResult_c parseMesonBuildResult = parseMesonBuild(fileMesonBuild, xmlOut, targetOTX);
if (parseMesonBuildResult.message != "") Console.WriteLine(parseMesonBuildResult.message);
if (parseMesonBuildResult.writeOutput) File.WriteAllLines(fileMesonBuild, parseMesonBuildResult.output as List<string>);
if (parseMesonBuildResult.error != 0) Environment.Exit(parseMesonBuildResult.error);
}
class xmlResult
{
public string devicePart = "";
public string assemblerOptions = "";
public string compilerOptions = "";
public string linkerOptions = "";
public string linkerFile = "";
public string prebuild = "";
public string postbuild = "";
public string SVDfile = "";
public List<string> sourceFiles = new List<string>();
public List<string> includeFolders = new List<string>();
public List<string> libraryFiles = new List<string>();
}
private static parseResult_c parseXMLfile(string filenname, bool keepMain)
{
if (!File.Exists(filenname)) return new parseResult_c("Error, can not find Export XML file!\r\nPlease set Project >> Export to IDE >> Makefile", 1, false);
parseResult_c parseResult = new parseResult_c("Done!", 0, true);
xmlResult xmlOut = new xmlResult();
parseResult.output = xmlOut;
PSoCCreatorIdeExport xmlSource;
PSoCCreatorIdeExportToolchain[] xmlToolchains;
PSoCCreatorIdeExportToolchain xmlGCCtool;
PSoCCreatorIdeExportProject xmlProject;
try // to get data from XML, error when fails
{
XmlSerializer ser = new XmlSerializer(typeof(PSoCCreatorIdeExport));
using (XmlReader reader = XmlReader.Create(filenname))
{
xmlSource = (PSoCCreatorIdeExport)ser.Deserialize(reader);
}
xmlToolchains = xmlSource.Toolchains;
xmlGCCtool = xmlToolchains.ToList().Find(x => x.Name == "ARM GCC Generic");
xmlProject = xmlSource.Project;
}
catch (Exception e) { return new parseResult_c("Error: " + e.Message, 1, false); }
try // to get device part, warning when fails
{
xmlOut.devicePart = xmlSource.Device.Part;
}
catch (Exception e) { parseResult.message = String.Format("Warning, device part not found!\r\n{0}\r\n{1}", e.Message, parseResult.message); }
try // to get assembler options, warning when fails
{
var xmlAssembler = xmlGCCtool.Tool.ToList().Find(x => x.Name == "assembler");
xmlOut.assemblerOptions = xmlAssembler.Options;
}
catch (Exception e) { parseResult.message = String.Format("Warning, assembler options not found!\r\n{0}\r\n{1}", e.Message, parseResult.message); }
try // to get compiler options, warning when fails
{
var xmlCompiler = xmlGCCtool.Tool.ToList().Find(x => x.Name == "compiler");
xmlOut.compilerOptions = xmlCompiler.Options;
}
catch (Exception e) { parseResult.message = String.Format("Warning, compiler options not found!\r\n{0}\r\n{1}", e.Message, parseResult.message); }
try // to get linker options, warning when fails
{
var xmlLinker = xmlGCCtool.Tool.ToList().Find(x => x.Name == "linker");
xmlOut.linkerOptions = xmlLinker.Options;
}
catch (Exception e) { parseResult.message = String.Format("Warning, linker options not found!\r\n{0}\r\n{1}", e.Message, parseResult.message); }
try // to get prebuild command, ignore when fails
{
var xmlPrebuild = xmlGCCtool.Tool.ToList().Find(x => x.Name == "prebuild");
xmlOut.prebuild = xmlPrebuild.Command;
}
catch { }
try // to get postbuild command, ignore when fails
{
var xmlPostbuild = xmlGCCtool.Tool.ToList().Find(x => x.Name == "postbuild");
xmlOut.postbuild = xmlPostbuild.Command;
}
catch { }
try // to get SVD file, ignore when fails
{
xmlOut.SVDfile = xmlProject.CMSIS_SVD_File;
}
catch { }
try // to get linker file, warning when fails
{
var xmlLinkerFile = xmlProject.LinkerFiles.ToList().Find(x => x.Toolchain == "ARM GCC Generic");
xmlOut.linkerFile = xmlLinkerFile.Value;
}
catch (Exception e) { parseResult.message = String.Format("Warning,linker file not found!\r\n{0}\r\n{1}", e.Message, parseResult.message); }
try // to get source files, error when fails
{
var r = xmlProject.Folders;
var xmlStrictFolders = r.Where(x => x.BuildType == "STRICT");
List<PSoCCreatorIdeExportProjectFolderFilesFile> sourceFiles = new List<PSoCCreatorIdeExportProjectFolderFilesFile>();
foreach (var xmlSources in xmlStrictFolders.Skip(keepMain ? 0 : 1))
{
if (xmlSources.Files.File != null)
{
sourceFiles.AddRange(xmlSources.Files.File.Where(x => x.BuildType == "BUILD" && x.Toolchain == ""));
sourceFiles.AddRange(xmlSources.Files.File.Where(x => x.BuildType == "BUILD" && x.Toolchain.Contains("ARM GCC Generic")));
}
}
foreach (var fileObj in sourceFiles)
{
string file = (string)fileObj.Value;
string fileExtension = Path.GetExtension(file).ToLower();
switch (fileExtension)
{
case ".h":
string path = Path.GetDirectoryName(file);
if (!xmlOut.includeFolders.Contains(path)) xmlOut.includeFolders.Add(path);
break;
case ".c":
case ".s":
xmlOut.sourceFiles.Add(file);
break;
case ".a":
xmlOut.libraryFiles.Add(file);
break;
}
}
}
catch (Exception e) { return new parseResult_c("Error: " + e.Message, 1, false); }
return parseResult;
}
private static void MergeIncludeFoldersFromOptions(xmlResult xmlOut, string options)
{
foreach (string line in fixAndStripOptions(options, false))
{
if (line.StartsWith("-I"))
{
string folder = line.Substring(2).Replace('/', '\\').Trim(new char[] { ' ', '\\' });
if (!xmlOut.includeFolders.Contains(folder))
xmlOut.includeFolders.Add(folder);
}
}
}
//private static parseResult_c parseXMLfile2(string cFileName, out string devicePart)
//{
// devicePart = null;
// if (!File.Exists(cFileName)) return new parseResult_c("Error, can not find target file!", 1, false);
// string[] cFile = File.ReadAllLines(cFileName);
// parseResult_c parseResult = new parseResult_c("Done!", 0, true);
// int idx;
// foreach (string cline in cFile)
// {
// if ((idx = cline.IndexOf("Device Part=\"")) >= 0)
// {
// string line = cline.Substring(idx + 13);
// if ((idx = line.IndexOf('\"')) > 0) devicePart = line.Substring(0, idx);
// }
// else if ((idx = cline.IndexOf("<File BuildType=\"BUILD\"")) >= 0)
// {
// if ((cline.IndexOf("Toolchain=\"\"", idx) >= 0 || cline.IndexOf("Toolchain=\"ARM GCC Generic\"", idx) >= 0) && (idx = cline.IndexOf("\">")) >= 0)
// {
// string line = cline.Substring(idx + 2);
// if ((idx = line.IndexOf("</File>")) < 1) return new parseResult_c("PARSE ERROR in XML file.\r\n", 1, false);
// line = line.Substring(0, idx).Replace('\\', '/');
// if (line == "main.c") continue;
// if (line.ToLower().EndsWith(".c") || line.ToLower().EndsWith(".s")) parseResult.lines1.Add(line);
// else if (line.ToLower().EndsWith(".h"))
// {
// if ((idx = line.LastIndexOf('/')) > 0)
// {
// line = line.Substring(0, idx + 1);
// if (!parseResult.lines2.Contains(line))
// parseResult.lines2.Add(line);
// }
// }
// else if (line.ToLower().EndsWith(".a")) parseResult.lines3.Add(line);
// }
// }
// }
// return parseResult;
//}
private static parseResult_c parseCyFitterCfg(string cFileName, xmlResult xmlOut)
{
if (!File.Exists(cFileName)) return new parseResult_c("Error, can not find target file!", 1, false);
string[] cFile = File.ReadAllLines(cFileName);
List<string> parseOut = new List<string>();
parseResult_c parseResult = new parseResult_c(parseOut, "Done!", 0, true);
bool copying = true;
int stopOverCnt = 0;
int startOverCnt = 0;
string stopInfo = "";
string startInfo = "";
for (int cnt = 0; cnt < cFile.Length; cnt++)
{
string cline = cFile[cnt];
// if (cline.Contains("Onethinx")) return new parseResult_c("File already parsed, no work to be done :-)", 0, false);
if ((stopOverCnt > 0) && (--stopOverCnt == 0))
{
parseOut.Add(stopInfo);
copying = false;
}
if ((startOverCnt > 0) && (--startOverCnt == 0))
{
parseOut.Add(startInfo);
copying = true;
}
if (cline == @"* This file is automatically generated by PSoC Creator.")
{
parseOut.Add(@"* This file was automatically generated by PSoC Creator and is updated");
parseOut.Add(@"* for the Onethinx Core module by Onethinx Creator PostBuild " + version);
continue;
}
else if (cline == @" status = Cy_SysClk_WcoEnable(500000u);")
{
string newline = @" status = CY_RET_SUCCESS; // Removed enabling of WCO as it is already enabled by the Onethinx Core: status = Cy_SysClk_WcoEnable(500000u);";
parseOut.Add(newline);
Console.WriteLine("Changed line " + cnt.ToString() + " to: " + newline);
continue;
}
else if (cline.StartsWith(@" Cy_SysLib_SetWaitStates")) { if (!copying) parseOut.Add(cline); }
//if (cline == @"static void ClockInit(void)")
//{
// Console.WriteLine("Found ClockInit() at line " + cnt + ", skipping code...");
// stopInfo = @" /* Removed Non UDB config code by OnethinxTool */";
// stopOverCnt = 2;
//}
//else
//if (cline == @" /* Configure peripheral clock dividers */")
//{
// Console.WriteLine("Found peripheral clock setting at line " + cnt + ", adding code...");
// copying = true;
//}
else if (cline == @"void Cy_SystemInit(void)")
{
Console.WriteLine("Found Cy_SystemInit() at line " + cnt + ", skipping code...");
//cline = @"void UDBInit(void)";
stopInfo =
@" CyDelay(1500); /* Failsafe guard: wrong clocksettings may brick the Onethinx module. Remove this delay in the release version. */" + "\r\n\r\n" +
@" /* Removed Onethinx Core conflicting code by Onethinx Creator PostBuild */" + "\r\n";
stopOverCnt = 2;
}
//else if (cline == @" /* Clock */")
//else if ((!copying) && (cline == @" /* Perform Trigger Mux configuration */"))
else if (cline == @" /* PMIC Control */")
{
startInfo = @" /* Resume non-conflicting code by Onethinx Creator PostBuild */";
startOverCnt = 3;
}
if (copying) parseOut.Add(cline);
else parseOut.Add(@" //" + cline);
}
if (copying == false) return new parseResult_c("PARSE ERROR, try clean/rebuild.\r\n", 1, false);
return parseResult;
}
private static parseResult_c parseCyBLEclk(string cFileName)
{
if (!File.Exists(cFileName)) return new parseResult_c("Target file not found.", 0, false);
string[] cFile = File.ReadAllLines(cFileName);
List<string> parseOut = new List<string>();
parseResult_c parseResult = new parseResult_c(parseOut, "Done!", 0, true);
for (int cnt = 0; cnt < cFile.Length; cnt++)
{
string cline = cFile[cnt];
// if (cline.Contains("Onethinx")) return new parseResult_c("File already parsed, no work to be done :-)", 0, false);
if (cline.Contains(@"SFLASH->RADIO_LDO_TRIMS != 0U"))
{
Console.WriteLine("Found SFLASH->RADIO_LDO_TRIMS at line " + cnt + ", changing code...");
cline = cline.Replace(@"SFLASH->RADIO_LDO_TRIMS != 0U", "false") + " // Changed from (SFLASH->RADIO_LDO_TRIMS != 0U) to (false) by Creator PostBuild for OTX-18";
}
parseOut.Add(cline);
}
return parseResult;
}
//private static parseResult_c parsePlatformDebugMake(string cFileName)
//{
// if (!File.Exists(cFileName)) return new parseResult_c("Error, can not find target file!\r\nPlease set Project >> Build Settings >> Target IDEs >> Makefile >> Generate", 1, false);
// string[] cFile = File.ReadAllLines(cFileName);
// parseResult_c parseResult = new parseResult_c("Done!", 0, true);
// for (int cnt = 0; cnt < cFile.Length; cnt++)
// {
// string cline = cFile[cnt];
// if (cline.StartsWith(@"ASFLAGS_CortexM4"))
// {
// int idx;
// while ((idx = cline.IndexOf(" -I")) > 0)
// {
// cline = cline.Substring(idx + 3);
// string dir = ((idx = cline.IndexOf(" -")) > 0)? cline.Substring(0, idx) : cline;
// parseResult.lines1.Add(dir);
// }
// break;
// }
// }
// return parseResult;
//}
private static parseResult_c parseMesonBuild(string cFileName, xmlResult xmlOut, bool targetOTX)
{
if (!File.Exists(cFileName)) return new parseResult_c("Not found. OK", 0, false);
string[] cFile = File.ReadAllLines(cFileName);
List<string> parseOut = new List<string>();
parseResult_c parseResult = new parseResult_c(parseOut, "Done!", 0, true);
string currentDirName = new DirectoryInfo(Environment.CurrentDirectory).Name + "/";
bool copying = true; int linesStripped = 0;
string minimumVersion = "";
for (int cnt = 0; cnt < cFile.Length; cnt++)
{
string cline = cFile[cnt];
if (cline.Contains("Creator_PostBuild_Minumum_Version")) minimumVersion = cline;
if (cline.Contains("_SourceFiles_End") ||
cline.Contains("_IncludeHeaderDirs_End") ||
cline.Contains("_IncludeFolders_End") ||
cline.Contains("_LibSources_End") ||
cline.Contains("_AssemblerOptions_End") ||
cline.Contains("_CompilerOptions_End") ||
cline.Contains("_LinkerOptions_End")
) copying = true;
if (copying) parseOut.Add(cline);
if (linesStripped > 0 && --linesStripped == 0) copying = true;
if (cline.Contains("Creator_PostBuild_SourceFiles_Start"))
{
foreach (string line in xmlOut.sourceFiles)
{
string file = currentDirName + line.Replace('\\', '/');
parseOut.Add("\t'" + file + "',");
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_IncludeFolders_Start"))
{
foreach (string line in xmlOut.includeFolders)
{
string folder = currentDirName + ((line == ".") ? "" : line.Replace('\\', '/'));
parseOut.Add("\t'" + folder + "',");
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_LibSources_Start"))
{
foreach (string line in xmlOut.libraryFiles)
{
// parseOut.Add("\t'" + currentDirName + ((line == ".") ? "" : line) + "',");
if (!File.Exists(line))
{
return new parseResult_c("Error: Library " + line + " not found!\r\nPlease enable 'Project >> Export to IDE >> Makefile' setting", 1, false);
}
string lib = Path.GetFileNameWithoutExtension(line);
string libFolder = Path.GetDirectoryName(line).Replace('\\', '/');
parseOut.Add(String.Format("\tdeclare_dependency( dependencies : cc.find_library('{0}', dirs : [CREATOR_DIR + '/{1}']) ),", lib, libFolder));
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_AssemblerOptions_Start"))
{
foreach (string line in fixAndStripOptions(xmlOut.assemblerOptions, true))
{
parseOut.Add("\t'" + line + "',");
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_CompilerOptions_Start"))
{
foreach (string line in fixAndStripOptions(xmlOut.compilerOptions,true ))
{
parseOut.Add("\t'" + line + "',");
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_LinkerOptions_Start"))
{
foreach (string line in fixAndStripOptions(xmlOut.linkerOptions, true))
{
//if (!targetOTX || (!line.StartsWith("-L") && !line.StartsWith("-T"))) // if OTX found, do not add -L and -T options
// parseOut.Add("\t'" + line + "',");
if (line.StartsWith("-L") || line.StartsWith("-T")) // check for folder references
{
if (!targetOTX) parseOut.Add("\t'" + line.Replace('\\', '/') + "',"); // Reformat and add when not using OTX target
}
else parseOut.Add("\t'" + line + "',");
}
copying = false;
}
else if (cline.Contains("Creator_PostBuild_devicePart_Line"))
{
parseOut.Add("devicePart = '" + xmlOut.devicePart + "'");
copying = false; linesStripped = 1;
}
else if (cline.Contains("Creator_PostBuild_linkerFile"))
{
parseOut.Add("linkerFile = '" + xmlOut.linkerFile.Replace('\\', '/') + "'");
copying = false; linesStripped = 1;
}
else if (cline.Contains("Creator_PostBuild_SVDfile_Line"))
{
parseOut.Add("SVDfile = '" + xmlOut.SVDfile + "'");
copying = false; linesStripped = 1;
}
else if (cline.Contains("Creator_PostBuild_prePostBuild_Lines"))
{
parseOut.Add("preBuildCommands = '" + xmlOut.prebuild + "'");
parseOut.Add("postBuildCommands = '" + xmlOut.postbuild + "'");
copying = false; linesStripped = 2;
}
else if (cline.Contains("Creator_PostBuild_Version_Line"))
{
parseOut.Add("creatorPostBuildVersion = '" + version + "'");
copying = false; linesStripped = 1;
}
else if (cline.Contains("Creator_PostBuild_DateTime_Line"))
{
parseOut.Add("creatorGeneratedDateTime = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
copying = false; linesStripped = 1;
}
else if (cline.Contains("Creator_PostBuild_Directory_Line"))
{
parseOut.Add("creatorDirectory = '" + new DirectoryInfo(Environment.CurrentDirectory).Name + "'");
copying = false; linesStripped = 1;
}
}
if (copying == false) return new parseResult_c("PARSE ERROR, check meson.build insert syntax.\r\n", 1, false);
if (minimumVersion == "") return new parseResult_c("Error: Creator_PostBuild_Minumum_Version not found!\r\nUse updated meson.build template.\r\n", 1, false);
var result = Regex.Matches(minimumVersion, "['\"](\\d*\\.\\d*)['\"]");
try
{
if (float.Parse(result[0].Groups[1].Value) > float.Parse(version))
return new parseResult_c("Error: Creator_PostBuild Minumum Version not met. Update meson.build.\r\n", 1, false);
}
catch
{
return new parseResult_c("Error: Creator_PostBuild_Minumum_Version insert error, check syntax.\r\n", 1, false);
}
return parseResult;
}
static List<string> fixAndStripOptions(string options, bool stripIncludes)
{
List<string> optionsOut = new List<string>();
options = Regex.Replace(options, @"(\s-[A-Z])\s", "$1");
string[] optionsArray = Regex.Split(options, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); // Split options by whitespace, unless quoted
foreach (string line in optionsArray)
{
if ((!line.StartsWith("-I") || !stripIncludes) && !line.Contains("${")) // Only maintain options not including PSoC Creator referred files/locations
optionsOut.Add(line);
}
return optionsOut;
}
}
}