Repository navigation
Expand file tree
/
Copy pathProjectSystem.rx
More file actions
3683 lines (3507 loc) · 180 KB
/
Copy pathProjectSystem.rx
File metadata and controls
3683 lines (3507 loc) · 180 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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Loads a .rxp project and runs its build tasks.
Package Robix.Build
Explain {
Description: "Load a .rxp project and run its build tasks."
};
Import Robix.Core;
Import Robix.Syntax;
Import Robix.Runtime;
Private Extern Function ClockMillis() -> Int;
Private Extern Function ParallelRun(String script) -> String;
Private Extern Function ToolPath(String name) -> String;
Private Extern Function ParallelTool(String tool, String script) -> String;
Private Extern Function UnicodeTerminal() -> Bool;
Private Extern Function HostSystem() -> String;
Private Extern Function HostArchitecture() -> String;
Public Class ProjectNode {
Public String Kind;
Public String Name;
Public String Text;
Public Bool Found;
Public Int Line;
Public Int column;
Public List<ProjectNode> children;
Public Constructor() {
This.Kind = "";
This.Name = "";
This.Text = "";
This.Found = True;
This.Line = 1;
This.column = 1;
This.children = List<ProjectNode>();
}
}
Public Class ProjectDiagnosticBag {
Private DiagnosticBag items;
Public Constructor() {
This.items = DiagnosticBag();
}
Public Function Add(String message) -> Void
Explain {
Description: "Record a project-system diagnostic.";
Input: message = "Error message";
Processing: "Store a fallback project diagnostic.";
Output: "No return value.";
} {
This.items.Error("RX200", message, 1, 1);
}
Public Function AddAt(String code, String message, Int line, Int column, String expected, String actual, String correction) -> Void
Explain {
Description: "Record a project diagnostic with source context.";
Input: code = "Stable diagnostic code", message = "Error message", line = "1-based source line", column = "1-based source column", expected = "Expected value", actual = "Actual value", correction = "Suggested repair";
Processing: "Store an error using the shared diagnostic model.";
Output: "No return value.";
} {
This.items.TypeError(code, message, line, column, expected, actual, correction);
}
Public Function Count() -> Int
Explain {
Description: "Return the number of project diagnostics.";
Input: None;
Processing: "Read the diagnostic count.";
Output: "The number of stored diagnostics.";
} {
Return This.items.Count();
}
Public Function ErrorCount() -> Int
Explain {
Description: "Return the number of project errors.";
Input: None;
Processing: "Count diagnostics with error severity.";
Output: "The number of errors.";
} {
Return This.items.ErrorCount();
}
Public Function All() -> List<Diagnostic>
Explain {
Description: "Return all project diagnostics.";
Input: None;
Processing: "Read the diagnostics in insertion order.";
Output: "The structured diagnostics.";
} {
Return This.items.All();
}
Public Function Clear() -> Void
Explain {
Description: "Clear diagnostics before parsing another project file.";
Input: None;
Processing: "Remove all stored diagnostics.";
Output: "No return value.";
} {
This.items.Truncate(0);
}
}
Public Class ProjectEngine {
Private String sourceText;
Private Int position;
Private Int line;
Private Int column;
Private ProjectDiagnosticBag diagnostics;
Private List<String> variableNames;
Private List<String> variableValues;
Private List<String> packageSourcePaths;
Private List<ProjectNode> functions;
Private String configuration;
Private String target;
Private Bool configurationExplicit;
Private Bool targetExplicit;
Private Bool verbose;
Private Bool noCache;
Private Bool dryRun;
Private Bool locked;
Private Bool restoreComplete;
Private String filter;
Private String testFile;
Private String testTarget;
Private String testScope;
Private String projectPath;
Private String projectDirectory;
Private Bool warningsAsErrors;
Private Int compiledCount;
Private Bool consoleEnabled;
Private Int consolePort;
Private Bool stopOnFailure;
Private Bool writeReport;
Private Bool updateSnapshots;
Private Bool failedOnly;
Private Bool parallel;
Private Bool parallelExplicit;
Private Bool debugSymbols;
Private Int started;
Public Constructor() {
This.sourceText = "";
This.position = 0;
This.line = 1;
This.column = 1;
This.diagnostics = ProjectDiagnosticBag();
This.variableNames = List<String>();
This.variableValues = List<String>();
This.packageSourcePaths = List<String>();
This.functions = List<ProjectNode>();
This.configuration = "Debug";
This.target = "";
This.configurationExplicit = False;
This.targetExplicit = False;
This.verbose = False;
This.noCache = False;
This.dryRun = False;
This.locked = False;
This.restoreComplete = False;
This.filter = "";
This.testFile = "";
This.testTarget = "";
This.testScope = "";
This.projectPath = "";
This.projectDirectory = ".";
This.warningsAsErrors = False;
This.compiledCount = 0;
This.consoleEnabled = True;
This.consolePort = 0;
This.stopOnFailure = False;
This.writeReport = False;
This.updateSnapshots = False;
This.failedOnly = False;
This.parallel = False;
This.parallelExplicit = False;
This.debugSymbols = False;
This.started = 0;
}
Public Function Run(List<String> args) -> ExecutionResult
Explain {
Description: "Build, run, test, or inspect the Robix project in the working directory.";
Input: args = "A task name and optional --Configuration, --Target, --Verbose, --NoCache, --DryRun, --Filter, --File, --Function, and --Class options";
Processing: "Find the .rxp file, parse it, and execute the requested task. The default task is Build.";
Output: "Success when the task finishes, or an execution error when the project is invalid.";
} {
This.started = ClockMillis();
This.restoreComplete = False;
This.ReadOptions(args);
String command = This.CommandOf(args);
If (command == "Help") {
This.PrintHelp();
Return This.Report(ExitCode.Success, "");
}
If (command == "Version") {
Print("{accent}Robix{/} {muted}0.0.48{/}");
Return This.Report(ExitCode.Success, "");
}
String projectPath = This.FindProject();
If (projectPath == "" && command == "Test" && This.testFile != "") {
If (!This.RunCompanionTests(ProjectNode())) {
This.PrintDiagnostics();
Return This.Report(ExitCode.ErrorExecution, "Tests failed.");
}
Return This.Report(ExitCode.Success, "Tests passed.");
}
If (projectPath == "") {
This.diagnostics.AddAt("RX201", "No .rxp project file was found.", 1, 1, "a project file", "missing", "Create a .rxp file in the current directory.");
This.PrintDiagnostics();
Return This.Report(ExitCode.InvalidArguments, "A .rxp project is required.");
}
This.projectPath = projectPath;
This.projectDirectory = This.ParentDirectory(projectPath);
ProjectNode root = This.ParseFile(Files.ReadText(projectPath));
If (This.diagnostics.Count() > 0) {
This.PrintDiagnostics();
Return This.Report(ExitCode.ErrorExecution, "The project file is invalid.");
}
This.CollectVariables(root);
This.Resolve(root);
This.ApplySettings(This.ProjectOf(root));
This.ExpandConditionals(This.ProjectOf(root));
This.ApplySettings(This.ProjectOf(root));
String problem = This.Validate(root);
If (problem != "") {
This.PrintDiagnostics();
Return This.Report(ExitCode.ErrorExecution, problem);
}
If (command == "List" || command == "Tasks") {
This.PrintTasks(root);
Return This.Report(ExitCode.Success, "");
}
If (command == "Task") {
command = This.TaskName(args);
If (command == "") {
This.diagnostics.AddAt("RX202", "Task requires a task name.", 1, 1, "a declared task name", "missing", "Run Robix Tasks to list available tasks.");
This.PrintDiagnostics();
Return This.Report(ExitCode.InvalidArguments, "A task name is required.");
}
}
If (command == "Info") {
This.PrintInfo(root);
Return This.Report(ExitCode.Success, "");
}
If (command == "Check") {
Return This.Report(ExitCode.Success, "Project check passed.");
}
If (command == "Test") {
ProjectNode configuredTests = This.FindChild(This.ProjectOf(root), "Tests");
Bool passed = False;
If (configuredTests.Found) { passed = This.RunDiscoveredTests(root); }
Else { passed = This.RunCompanionTests(root); }
If (!passed) {
This.PrintDiagnostics();
Return This.Report(ExitCode.ErrorExecution, "Tests failed.");
}
Return This.Report(ExitCode.Success, "Tests passed.");
}
If (command == "Rebuild") {
This.ExecuteTask(root, "Clean");
command = "Build";
}
If (command == "") {
command = "Build";
}
Bool ok = This.ExecuteTask(root, This.CanonicalTask(command));
If (!ok) {
This.PrintDiagnostics();
Return This.Report(ExitCode.ErrorExecution, "The task failed.");
}
Return This.Report(ExitCode.Success, "Task " + This.CanonicalTask(command) + " completed.");
}
Public Function DiagnosticsOf() -> List<Diagnostic>
Explain {
Description: "Return the structured diagnostics produced by this project engine.";
Input: None;
Processing: "Read the project's diagnostic collection.";
Output: "The structured diagnostics.";
} {
Return This.diagnostics.All();
}
Public Function ErrorCount() -> Int
Explain {
Description: "Return the number of project errors.";
Input: None;
Processing: "Read the project diagnostic count.";
Output: "The number of errors.";
} {
Return This.diagnostics.ErrorCount();
}
Private Function ReadOptions(List<String> args) -> Void {
Int index = 0;
While (index < args.Count()) {
String arg = args[index];
If (arg == "--Verbose") {
This.verbose = True;
}
If (arg == "--NoCache") {
This.noCache = True;
}
If (arg == "--DryRun") {
This.dryRun = True;
}
If (arg.ToLower() == "--locked") {
This.locked = True;
}
If (arg == "--console=off") { This.consoleEnabled = False; }
If (arg == "--console=on") { This.consoleEnabled = True; }
If (arg.StartsWith("--port=")) { This.consolePort = ParseInteger(arg.Substring(7)); }
If (arg == "--Configuration" && index + 1 < args.Count()) {
index = index + 1;
This.configuration = args[index];
This.configurationExplicit = True;
}
If (arg == "--Target" && index + 1 < args.Count()) {
index = index + 1;
This.target = args[index];
This.targetExplicit = True;
}
If (arg == "--Filter" && index + 1 < args.Count()) {
index = index + 1;
This.filter = args[index];
}
If (arg == "--File" && index + 1 < args.Count()) {
index = index + 1;
This.testFile = args[index];
}
If (arg == "--Function" && index + 1 < args.Count()) {
index = index + 1;
This.testTarget = args[index];
This.testScope = "function";
}
If (arg == "--Class" && index + 1 < args.Count()) {
index = index + 1;
This.testTarget = args[index];
This.testScope = "class";
}
String lower = arg.ToLower();
If (lower == "--stoponfailure") { This.stopOnFailure = True; }
If (lower == "--report") { This.writeReport = True; }
If (lower == "--updatesnapshots") { This.updateSnapshots = True; }
If (lower == "--failed") { This.failedOnly = True; }
If (lower == "--parallel") { This.parallel = True; This.parallelExplicit = True; }
If (lower == "--sequential") { This.parallel = False; This.parallelExplicit = True; }
index = index + 1;
}
Var positionals = List<String>();
Int cursor = 0;
While (cursor < args.Count()) {
String arg = args[cursor];
If (arg == "--Configuration" || arg == "--Filter" || arg == "--File" || arg == "--Function" || arg == "--Class" || arg == "--Target") {
cursor = cursor + 1;
} Else If (!arg.StartsWith("--")) {
positionals.Add(arg);
}
cursor = cursor + 1;
}
If (positionals.Count() >= 2 && This.testFile == "") {
This.testFile = positionals[1];
}
If (positionals.Count() >= 3 && This.testTarget == "") {
This.testTarget = positionals[2];
}
This.DefineVariable("Configuration", This.configuration);
}
Private Function ApplySettings(ProjectNode project) -> Void {
ProjectNode defaults = This.FindChild(project, "Defaults");
ProjectNode compilation = This.FindChild(project, "Compilation");
If (!This.configurationExplicit) {
String configured = This.Property(defaults, "Environment");
If (configured == "") { configured = This.Property(defaults, "Configuration"); }
If (configured != "") { This.configuration = configured; }
}
String configuration = This.NormalizeConfiguration(This.configuration);
If (configuration != "") { This.configuration = configuration; }
String profileName = This.Property(defaults, "Environment");
If (This.configurationExplicit || profileName == "") { profileName = This.configuration; }
ProjectNode profile = This.FindChild(This.FindChild(project, "Environments"), profileName);
If (!profile.Found) { profile = This.FindChild(This.FindChild(project, "Configurations"), profileName); }
If (profile.Found) {
String selectedConfiguration = This.Property(profile, "Configuration");
If (selectedConfiguration == "") { selectedConfiguration = This.Property(profile, "BasedOn"); }
String optimization = This.Property(profile, "Optimization");
If (optimization == "" && !This.configurationExplicit) { optimization = This.Property(compilation, "Optimization"); }
If (selectedConfiguration == "") {
String level = optimization.ToLower();
If (level == "none") { selectedConfiguration = "Debug"; }
If (level == "balanced") { selectedConfiguration = "Development"; }
If (level == "speed" || level == "maximum") { selectedConfiguration = "Release"; }
}
If (selectedConfiguration != "") {
This.configuration = This.NormalizeConfiguration(selectedConfiguration);
}
String symbols = This.Property(profile, "DebugSymbols").ToLower();
If (symbols == "") { symbols = This.Property(compilation, "DebugSymbols").ToLower(); }
If (symbols == "true") { This.debugSymbols = True; }
Else If (symbols == "false") { This.debugSymbols = False; }
Else { This.debugSymbols = This.configuration != "Release"; }
} Else {
String optimization = "";
If (!This.configurationExplicit) { optimization = This.Property(compilation, "Optimization").ToLower(); }
If (optimization == "none") { This.configuration = "Debug"; }
If (optimization == "balanced") { This.configuration = "Development"; }
If (optimization == "speed" || optimization == "maximum") { This.configuration = "Release"; }
String symbols = This.Property(compilation, "DebugSymbols").ToLower();
If (symbols == "true") { This.debugSymbols = True; }
Else If (symbols == "false") { This.debugSymbols = False; }
Else { This.debugSymbols = This.configuration != "Release"; }
}
If (!This.targetExplicit) {
This.target = This.Property(defaults, "Target");
If (This.target == "") {
String platform = This.Property(defaults, "Platform");
String architecture = This.Property(defaults, "Architecture");
If (platform != "" && architecture != "") { This.target = platform + architecture; }
}
If (This.target == "") { This.target = This.Property(compilation, "DefaultTarget"); }
If (This.target == "") { This.target = This.HostTarget(); }
}
String normalized = This.NormalizeTarget(This.target);
If (normalized != "") { This.target = normalized; }
This.DefineVariable("Configuration", This.configuration);
This.DefineVariable("Target", This.target);
This.DefineVariable("Platform", This.TargetPlatform(This.target));
This.DefineVariable("Architecture", This.TargetArchitecture(This.target));
This.DefineVariable("Always", "true");
This.DefineVariable("Never", "false");
If (!This.parallelExplicit) {
String parallel = This.Property(compilation, "Parallel");
This.parallel = parallel == "true" || parallel == "True";
}
}
Private Function NormalizeConfiguration(String configuration) -> String {
String lower = configuration.ToLower();
If (lower == "debug") { Return "Debug"; }
If (lower == "release") { Return "Release"; }
If (lower == "development") { Return "Development"; }
Return configuration;
}
Private Function HostTarget() -> String {
String system = HostSystem();
String architecture = HostArchitecture();
If (system == "Windows" && architecture == "ARM64") { Return "WindowsARM64"; }
If (system == "Windows") { Return "WindowsX64"; }
If (system == "MacOS" && architecture == "ARM64") { Return "MacOSARM64"; }
If (system == "MacOS") { Return "MacOSX64"; }
If (architecture == "ARM64") { Return "LinuxARM64"; }
Return "LinuxX64";
}
Private Function NormalizeTarget(String target) -> String {
String lower = target.ToLower();
If (lower == "windowsx86" || lower == "windows-x86") { Return "WindowsX86"; }
If (lower == "windowsx64" || lower == "windows-x64") { Return "WindowsX64"; }
If (lower == "windowsarm64" || lower == "windows-arm64") { Return "WindowsARM64"; }
If (lower == "linuxx64" || lower == "linux-x64") { Return "LinuxX64"; }
If (lower == "linuxarm64" || lower == "linux-arm64") { Return "LinuxARM64"; }
If (lower == "macosx64" || lower == "macos-x64") { Return "MacOSX64"; }
If (lower == "macosarm64" || lower == "macos-arm64") { Return "MacOSARM64"; }
If (lower == "webwasm32" || lower == "web-wasm32") { Return "WebWASM32"; }
If (lower == "webjavascript" || lower == "web-javascript") { Return "WebJavaScript"; }
If (lower == "baremetalx64" || lower == "bare-metal-x64") { Return "BareMetalX64"; }
If (lower == "baremetalarm64" || lower == "bare-metal-arm64") { Return "BareMetalARM64"; }
If (lower == "baremetalriscv64" || lower == "bare-metal-riscv64") { Return "BareMetalRISCV64"; }
Return target;
}
Private Function TargetPlatform(String target) -> String {
If (target.StartsWith("Windows")) { Return "Windows"; }
If (target.StartsWith("Linux")) { Return "Linux"; }
If (target.StartsWith("MacOS")) { Return "MacOS"; }
If (target.StartsWith("Web")) { Return "Web"; }
If (target.StartsWith("BareMetal")) { Return "BareMetal"; }
Return "";
}
Private Function TargetArchitecture(String target) -> String {
If (target.EndsWith("X86")) { Return "X86"; }
If (target.EndsWith("X64")) { Return "X64"; }
If (target.EndsWith("ARM64")) { Return "ARM64"; }
If (target.EndsWith("RISCV64")) { Return "RISCV64"; }
If (target.EndsWith("WASM32")) { Return "WASM32"; }
If (target.EndsWith("JavaScript")) { Return "JavaScript"; }
Return "";
}
Private Function CommandOf(List<String> args) -> String {
Int index = 0;
While (index < args.Count()) {
String arg = args[index];
If (!arg.StartsWith("--")) {
Return This.CommandWord(arg);
}
If (arg == "--Configuration" || arg == "--Filter" || arg == "--File" || arg == "--Function" || arg == "--Class" || arg == "--Target") {
index = index + 1;
}
index = index + 1;
}
Return "";
}
Private Function CommandWord(String word) -> String {
String lower = word.ToLower();
If (lower.Length() == 0) { Return ""; }
String letters = "abcdefghijklmnopqrstuvwxyz";
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String first = lower.Substring(0, 1);
Int at = letters.IndexOf(first);
If (at >= 0) { first = upper.Substring(at, 1); }
If (lower.Length() == 1) { Return first; }
Return first + lower.Substring(1);
}
Private Function CanonicalTask(String command) -> String {
String word = This.CommandWord(command);
If (word == "Build" || word == "Clean" || word == "Run" || word == "Test" || word == "Restore" || word == "Publish" || word == "Pack" || word == "Check") { Return word; }
Return command;
}
Private Function FindProject() -> String {
If (Files.Exists("Robix.rxp")) { Return "Robix.rxp"; }
Var matches = List<String>();
For relative In Directory.Names(".") {
If (relative.EndsWith(".rxp") && !relative.Contains("/")) {
matches.Add(relative);
}
}
If (matches.Count() == 0) {
Return "";
}
Return matches[0];
}
Private Function ParentDirectory(String path) -> String {
Int slash = path.LastIndexOf("/");
If (slash < 0) {
Return ".";
}
Return path.Substring(0, slash);
}
Private Function DefineVariable(String name, String value) -> Void {
Int index = 0;
While (index < This.variableNames.Count()) {
If (This.variableNames[index] == name) {
This.variableValues[index] = value;
Return;
}
index = index + 1;
}
This.variableNames.Add(name);
This.variableValues.Add(value);
}
Private Function LookupVariable(String name) -> String {
Int index = 0;
While (index < This.variableNames.Count()) {
If (This.variableNames[index] == name) {
Return This.variableValues[index];
}
index = index + 1;
}
Return "";
}
Private Function HasVariable(String name) -> Bool {
Int index = 0;
While (index < This.variableNames.Count()) {
If (This.variableNames[index] == name) {
Return True;
}
index = index + 1;
}
Return False;
}
Private Function CollectVariables(ProjectNode root) -> Void {
This.CollectFrom(root);
This.DefineVariable("Configuration", This.configuration);
}
Private Function CollectFrom(ProjectNode node) -> Void {
If (node.Name == "Variables") {
For item In node.children {
If (item.Kind == "Property") {
This.DefineVariable(item.Name, item.Text);
}
}
}
If (node.Kind == "Function") {
This.functions.Add(node);
}
For child In node.children {
This.CollectFrom(child);
}
}
Private Function Resolve(ProjectNode node) -> Void {
If (node.Kind == "Property" || node.Kind == "Item" || node.Kind == "Call" || node.Kind == "Function") {
node.Text = This.ResolveText(node.Text);
}
If (node.Kind == "Project" && This.HasVariable(node.Name)) {
node.Name = This.LookupVariable(node.Name);
}
For child In node.children {
This.Resolve(child);
}
}
Private Function ExpandConditionals(ProjectNode node) -> Void {
If (node.Kind == "Function") { Return; }
Var expanded = List<ProjectNode>();
For child In node.children {
If (child.Kind == "If") {
If (This.ConditionMatches(child.Text)) {
For branch In child.children { expanded.Add(branch); }
}
} Else {
expanded.Add(child);
}
}
node.children = expanded;
For child In node.children { This.ExpandConditionals(child); }
}
Private Function ResolveText(String text) -> String {
If (This.HasVariable(text)) {
Return This.LookupVariable(text);
}
ProjectNode call = This.FindFunction(text);
If (call.Found) {
Return call.Text;
}
Return text;
}
Private Function FindFunction(String name) -> ProjectNode {
For item In This.functions {
If (item.Name == name) {
Return item;
}
}
ProjectNode missing = ProjectNode();
missing.Found = False;
Return missing;
}
Private Function Validate(ProjectNode root) -> String {
ProjectNode project = This.FindChild(root, "Project");
If (!project.Found && root.Kind == "Project") {
project = root;
}
If (!project.Found) {
Return This.ValidationError(root, "RX201", "A Project block is required.", "a Project block", "missing", "Add a Project block to the file.");
}
String formatVersion = This.Property(project, "FormatVersion");
If (formatVersion != "" && formatVersion != "1.0") {
Return This.ValidationError(This.FindProperty(project, "FormatVersion"), "RX201", "Project format version '" + formatVersion + "' is not supported.", "1.0", formatVersion, "Set FormatVersion to \"1.0\" or remove it to use the current format.");
}
For child In project.children {
If (child.Kind == "Property" && !This.KnownProjectProperty(child.Name)) {
Return This.ValidationError(child, "RX201", "Unknown project property '" + child.Name + "'.", "a recognized project property", child.Name, "Correct the property name or move it into a supported section.");
}
If (child.Kind != "Property" && !This.KnownProjectSection(child.Kind)) {
Return This.ValidationError(child, "RX201", "Unknown project section '" + child.Kind + "'.", "a recognized project section", child.Kind, "Correct the section name or remove the unsupported section.");
}
}
String projectType = This.Property(project, "Type");
If (projectType == "") {
projectType = "Executable";
}
If (!This.KnownType(projectType)) {
Return This.ValidationError(This.FindProperty(project, "Type"), "RX201", "Unknown project type '" + projectType + "'.", "a supported project type", projectType, "Choose Executable, Library, or another supported type.");
}
String profilesError = This.ValidateProfiles(project);
If (profilesError != "") { Return profilesError; }
String compilationError = This.ValidateCompilation(project);
If (compilationError != "") { Return compilationError; }
String sourceError = This.ValidateSourceSettings(project);
If (sourceError != "") { Return sourceError; }
String testsError = This.ValidateTestsSettings(project);
If (testsError != "") { Return testsError; }
String compilerError = This.ValidateCompilerSettings(project);
If (compilerError != "") { Return compilerError; }
String dependencyError = This.ValidateDependencies(project);
If (dependencyError != "") { Return dependencyError; }
String legacyOutputError = This.ValidateLegacyOutput(project);
If (legacyOutputError != "") { Return legacyOutputError; }
String tasksError = This.ValidateTasks(project);
If (tasksError != "") { Return tasksError; }
If (This.configuration != "Debug" && This.configuration != "Release" && This.configuration != "Development") {
Return This.ValidationError(This.FindChild(project, "Defaults"), "RX201", "Configuration '" + This.configuration + "' is not supported by the compiler.", "Debug, Release, or Development", This.configuration, "Choose a supported configuration.");
}
Var unsupportedSections = List<String>();
unsupportedSections.Add("Conditions");
unsupportedSections.Add("Environments");
unsupportedSections.Add("Linking");
unsupportedSections.Add("Resources");
unsupportedSections.Add("Signing");
unsupportedSections.Add("Publishing");
unsupportedSections.Add("Advanced");
unsupportedSections.Add("Workspace");
unsupportedSections.Add("Workspaces");
For sectionName In unsupportedSections {
ProjectNode unsupported = This.FindChild(project, sectionName);
If (unsupported.Found) {
Return This.ValidationError(unsupported, "RX201", "Project section '" + sectionName + "' is not implemented yet.", "a supported project section", sectionName, "Remove the unsupported section.");
}
}
String copyError = This.ValidateCopySections(project);
If (copyError != "") { Return copyError; }
String directoriesError = This.ValidateDirectories(project);
If (directoriesError != "") { Return directoriesError; }
String packageSourcesError = This.ValidatePackageSources(project);
If (packageSourcesError != "") { Return packageSourcesError; }
ProjectNode dependencies = This.FindChild(project, "Dependencies");
For dependency In dependencies.children {
If (dependency.Kind != "Package") {
Return This.ValidationError(dependency, "RX204", "Dependency kind '" + dependency.Kind + "' is not implemented.", "Package", dependency.Kind, "Declare a Package dependency.");
}
String packageName = dependency.Name;
String version = This.Property(dependency, "Version");
If (version == "") { version = "1.0.0"; }
If (!This.ValidPackageName(packageName)) {
Return This.ValidationError(dependency, "RX204", "Invalid package name '" + packageName + "'.", "a valid package identifier", packageName, "Use letters, digits, dots, hyphens, or underscores.");
}
If (!This.ValidPackageVersion(version)) {
Return This.ValidationError(This.FindProperty(dependency, "Version"), "RX204", "Invalid package version '" + version + "' for '" + packageName + "'.", "a numeric version such as 1.0.0", version, "Use a valid package version.");
}
}
If (This.target == "" || This.TargetPlatform(This.target) == "" || This.TargetArchitecture(This.target) == "") {
Return This.ValidationError(This.FindChild(project, "Defaults"), "RX201", "Unknown target '" + This.target + "'.", "a supported target", This.target, "Choose WindowsX64 or LinuxX64.");
}
String platform = This.TargetPlatform(This.target);
String architecture = This.TargetArchitecture(This.target);
If (!This.AllowedTarget(This.FindChild(project, "Platforms"), platform) ||
!This.AllowedTarget(This.FindChild(project, "Architectures"), architecture)) {
Return This.ValidationError(project, "RX201", "Target '" + This.target + "' is excluded by the project platform or architecture settings.", "an included platform and architecture", This.target, "Update Platforms.Include/Exclude or Architectures.Include/Exclude.");
}
ProjectNode configuredTargets = This.FindChild(This.FindChild(project, "Compilation"), "Targets");
If (!This.AllowedTarget(configuredTargets, This.target)) {
Return This.ValidationError(configuredTargets, "RX201", "Target '" + This.target + "' is not listed in Compilation.Targets.", "a target listed in Compilation.Targets", This.target, "Add this target to Compilation.Targets.");
}
If (This.target != "WindowsX64" && This.target != "LinuxX64") {
Return This.ValidationError(This.FindChild(project, "Defaults"), "RX203", "Target '" + This.target + "' is recognized but its compiler backend is not implemented.", "WindowsX64 or LinuxX64", This.target, "Select a target with an implemented backend.");
}
ProjectNode outputs = This.FindChild(project, "Outputs");
ProjectNode defaults = This.FindChild(project, "Defaults");
String defaultOutput = This.Property(defaults, "Output");
Bool defaultOutputFound = defaultOutput == "";
For output In outputs.children {
If (!This.ConditionEnabled(output)) { Continue; }
If (output.Kind != "Executable" && output.Kind != "Library") {
Return This.ValidationError(output, "RX203", "Output kind '" + output.Kind + "' is not implemented.", "Executable or Library", output.Kind, "Use a supported output kind.");
}
String format = This.Property(output, "Format");
If (format != "" && format != "Native") {
Return This.ValidationError(This.FindProperty(output, "Format"), "RX203", "Output format '" + format + "' is not implemented.", "Native", format, "Remove Format or set it to Native.");
}
If (output.Kind == "Library") {
String entry = This.LibraryEntry(project, output);
If (entry == "") { Return This.ValidationError(output, "RX203", "Library output '" + This.NamedOutput(output, "") + "' requires an Entry.", "an .rx source entry", "missing", "Set Entry or map a Files.File library source to this output."); }
String libraryOutput = This.Property(output, "Output");
If (libraryOutput.EndsWith("/") || libraryOutput.EndsWith("\\")) {
Return This.ValidationError(This.FindProperty(output, "Output"), "RX203", "Library Output must name a file, not a directory.", "a library file path", libraryOutput, "Set Output to a complete destination file path.");
}
}
For setting In output.children {
If (setting.Name != "Entry" && setting.Name != "Format" && setting.Name != "Output" && setting.Name != "Type" && setting.Name != "Name" && setting.Name != "When") {
Return This.ValidationError(setting, "RX203", "Output property '" + setting.Name + "' is not implemented.", "Entry, Format, Output, Type, Name, or When", setting.Name, "Remove the unsupported output property.");
}
If (setting.Name == "Type" && output.Kind == "Library") {
Return This.ValidationError(setting, "RX203", "Static and shared library modes are not implemented by the current compiler.", "a compiler-supported library unit", setting.Text, "Remove Type or use the package-unit output supported by Robixc.");
}
If (setting.Name == "Type" && output.Kind == "Executable" && setting.Text != "Native") {
Return This.ValidationError(setting, "RX203", "Executable type '" + setting.Text + "' is not implemented.", "Native", setting.Text, "Set Type to Native or remove the property.");
}
}
If (output.Kind == "Executable" && This.NamedOutput(output, "") == defaultOutput) { defaultOutputFound = True; }
}
If (!defaultOutputFound) {
Return This.ValidationError(This.FindProperty(defaults, "Output"), "RX203", "Defaults.Output '" + defaultOutput + "' does not name an executable output.", "the name of an executable output", defaultOutput, "Update Defaults.Output or remove it.");
}
If (!This.IsApplication(project) && outputs.Found && outputs.children.Count() == 0) {
Return This.ValidationError(outputs, "RX203", "This project has no supported executable output.", "at least one supported output", "none", "Declare an executable or library output.");
}
ProjectNode compiler = This.FindChild(project, "Compiler");
String safety = This.Property(compiler, "TypeSafety");
If (safety == "") {
compiler = This.FindChild(project, "Build");
safety = This.Property(compiler, "TypeSafety");
}
If (safety != "" && safety != "Strict") {
Return This.ValidationError(This.FindProperty(compiler, "TypeSafety"), "RX201", "Type checking is always strict. TypeSafety cannot be '" + safety + "'.", "Strict", safety, "Set TypeSafety to Strict or remove the property.");
}
Return "";
}
Private Function KnownProjectProperty(String name) -> Bool {
String known = "|FormatVersion|Type|Version|Template|Description|Author|Company|License|Homepage|ProductName|Copyright|Repository|ProjectId|Guid|ApplicationId|MinimumRobixVersion|MinimumOperatingSystem|Tags|Visibility|Entry|Source|";
Return known.Contains("|" + name + "|");
}
Private Function KnownProjectSection(String name) -> Bool {
String known = "|Defaults|Platforms|Architectures|Source|Files|Group|Outputs|Compilation|Linking|Dependencies|PackageSources|Tasks|Tests|Assets|Copy|Environments|Configurations|Directories|Output|Compiler|Build|Testing|Variables|Function|Conditions|Resources|Signing|Publishing|Advanced|Workspace|Workspaces|";
Return known.Contains("|" + name + "|");
}
Private Function ValidateProfiles(ProjectNode project) -> String {
Var sectionNames = List<String>();
sectionNames.Add("Environments");
sectionNames.Add("Configurations");
For sectionName In sectionNames {
ProjectNode section = This.FindChild(project, sectionName);
For profile In section.children {
For setting In profile.children {
If (setting.Name != "Configuration" && setting.Name != "BasedOn" && setting.Name != "Optimization" && setting.Name != "DebugSymbols" && setting.Name != "Description") {
Return This.ValidationError(setting, "RX201", sectionName + " setting '" + setting.Name + "' is not implemented.", "Configuration, BasedOn, Optimization, DebugSymbols, or Description", setting.Name, "Remove the unsupported profile setting.");
}
If (setting.Name == "Optimization") {
String optimization = setting.Text.ToLower();
If (optimization != "none" && optimization != "balanced" && optimization != "speed" && optimization != "maximum") {
Return This.ValidationError(setting, "RX201", "Optimization '" + setting.Text + "' is not supported.", "None, Balanced, Speed, or Maximum", setting.Text, "Choose a supported optimization level.");
}
}
If (setting.Name == "DebugSymbols" && setting.Text.ToLower() != "true" && setting.Text.ToLower() != "false") {
Return This.ValidationError(setting, "RX201", "DebugSymbols must be true or false.", "true or false", setting.Text, "Set DebugSymbols to true or false.");
}
}
}
}
ProjectNode defaults = This.FindChild(project, "Defaults");
For setting In defaults.children {
If (setting.Name != "Configuration" && setting.Name != "Environment" && setting.Name != "Target" && setting.Name != "Platform" && setting.Name != "Architecture" && setting.Name != "Output") {
Return This.ValidationError(setting, "RX201", "Defaults setting '" + setting.Name + "' is not implemented.", "Configuration, Environment, Target, Platform, Architecture, or Output", setting.Name, "Remove the unsupported default setting.");
}
}
String environment = This.Property(defaults, "Environment");
If (environment != "" &&
!This.FindChild(This.FindChild(project, "Environments"), environment).Found &&
!This.FindChild(This.FindChild(project, "Configurations"), environment).Found) {
Return This.ValidationError(This.FindProperty(defaults, "Environment"), "RX201", "Environment '" + environment + "' is not declared.", "a declared Environments or Configurations profile", environment, "Declare the profile or remove Defaults.Environment.");
}
For sectionName In sectionNames {
ProjectNode section = This.FindChild(project, sectionName);
For profile In section.children {
String name = profile.Name;
If (name != "Debug" && name != "Development" && name != "Release" &&
This.Property(profile, "Configuration") == "" &&
This.Property(profile, "BasedOn") == "" &&
This.Property(profile, "Optimization") == "") {
Return This.ValidationError(profile, "RX201", "Profile '" + name + "' does not select a build configuration.", "Configuration, BasedOn, or Optimization", "missing", "Set Configuration, BasedOn, or Optimization on the profile.");
}
String selected = This.Property(profile, "Configuration");
ProjectNode selectedSetting = This.FindProperty(profile, "Configuration");
If (selected == "") {
selected = This.Property(profile, "BasedOn");
selectedSetting = This.FindProperty(profile, "BasedOn");
}
If (selected != "" && selected != "Debug" && selected != "Development" && selected != "Release") {
Return This.ValidationError(selectedSetting, "RX201", "Profile '" + name + "' selects unsupported configuration '" + selected + "'.", "Debug, Development, or Release", selected, "Select a supported compiler configuration.");
}
}
}
Return "";
}
Private Function ValidateSourceSettings(ProjectNode project) -> String {
ProjectNode source = This.FindChild(project, "Source");
For setting In source.children {
If (setting.Name != "Include" && setting.Name != "Exclude" && setting.Name != "Entry") {
Return This.ValidationError(setting, "RX201", "Source setting '" + setting.Name + "' is not implemented.", "Include, Exclude, or Entry", setting.Name, "Remove the unsupported source setting.");
}
}
ProjectNode files = This.FindChild(project, "Files");
For item In files.children {
If (item.Kind == "File") {
String role = This.Property(item, "Type");
If (role != "" && role != "Executable" && role != "Library" && role != "Module" && role != "Generated" && role != "Test") {
Return This.ValidationError(item, "RX203", "File role '" + role + "' is not implemented.", "Executable, Library, Module, Generated, or Test", role, "Use a Robix source role or remove the declaration.");
}
For setting In item.children {
If (setting.Name != "Type" && setting.Name != "Output" && setting.Name != "Entry" && setting.Name != "When") {
Return This.ValidationError(setting, "RX203", "File setting '" + setting.Name + "' is not implemented.", "Type, Output, Entry, or When", setting.Name, "Remove the unsupported file setting.");
}
If (setting.Name == "Entry" && setting.Text.ToLower() != "true" && setting.Text.ToLower() != "false") {
Return This.ValidationError(setting, "RX203", "File Entry must be true or false.", "true or false", setting.Text, "Use Entry: true to select this file as the project entry.");
}
}
} Else If (item.Name != "Include" && item.Name != "Exclude") {
Return This.ValidationError(item, "RX203", "Files child '" + item.Name + "' is not implemented.", "Include, Exclude, or File", item.Name, "Use a supported Files declaration.");
}
}
For group In project.children {
If (group.Kind != "Group") { Continue; }
String role = This.Property(group, "Type");
If (role != "" && role != "Test" && role != "Executable" && role != "Library" && role != "Module" && role != "Generated") {
Return This.ValidationError(group, "RX203", "File group role '" + role + "' is not implemented.", "Test, Executable, Library, Module, or Generated", role, "Use a supported Robix source role.");
}
For setting In group.children {
If (setting.Name != "Type" && setting.Name != "Include" && setting.Name != "Exclude" && setting.Name != "When") {
Return This.ValidationError(setting, "RX203", "File group setting '" + setting.Name + "' is not implemented.", "Type, Include, Exclude, or When", setting.Name, "Remove the unsupported group setting.");
}
}
}
Return "";
}
Private Function ValidateTestsSettings(ProjectNode project) -> String {
ProjectNode tests = This.FindChild(project, "Tests");
For setting In tests.children {
If (setting.Name != "Include" && setting.Name != "Exclude" && setting.Name != "RunAfterBuild") {
Return This.ValidationError(setting, "RX205", "Tests property '" + setting.Name + "' is not implemented.", "Include, Exclude, or RunAfterBuild", setting.Name, "Remove the unsupported test property.");
}
If (setting.Name == "RunAfterBuild" && setting.Text.ToLower() != "true" && setting.Text.ToLower() != "false") {
Return This.ValidationError(setting, "RX205", "Tests.RunAfterBuild must be true or false.", "true or false", setting.Text, "Set RunAfterBuild to true or false.");
}
}
Return "";
}
Private Function ValidateCompilerSettings(ProjectNode project) -> String {
Var sectionNames = List<String>();
sectionNames.Add("Compiler");
sectionNames.Add("Build");
For sectionName In sectionNames {
ProjectNode compiler = This.FindChild(project, sectionName);
For setting In compiler.children {
If (setting.Name != "TypeSafety" && setting.Name != "WarningsAsErrors") {
Return This.ValidationError(setting, "RX201", "Compiler setting '" + setting.Name + "' is not implemented.", "TypeSafety or WarningsAsErrors", setting.Name, "Remove the unsupported compiler setting.");
}
If (setting.Name == "WarningsAsErrors" && setting.Text.ToLower() != "true" && setting.Text.ToLower() != "false") {
Return This.ValidationError(setting, "RX201", "WarningsAsErrors must be true or false.", "true or false", setting.Text, "Set WarningsAsErrors to true or false.");
}
}
}
Return "";
}
Private Function ValidateDependencies(ProjectNode project) -> String {
ProjectNode dependencies = This.FindChild(project, "Dependencies");
For dependency In dependencies.children {
For setting In dependency.children {
If (setting.Name != "Version") {
Return This.ValidationError(setting, "RX204", "Dependency property '" + setting.Name + "' is not implemented for '" + dependency.Name + "'.", "Version", setting.Name, "Remove the unsupported dependency property.");
}
}
}
Return "";
}
Private Function ValidateLegacyOutput(ProjectNode project) -> String {
ProjectNode output = This.FindChild(project, "Output");
For setting In output.children {
If (setting.Name != "Directory" && setting.Name != "IntermediateDirectory" && setting.Name != "Name") {
Return This.ValidationError(setting, "RX203", "Output setting '" + setting.Name + "' is not implemented.", "Directory, IntermediateDirectory, or Name", setting.Name, "Remove the unsupported output setting.");
}
}
ProjectNode testing = This.FindChild(project, "Testing");
For setting In testing.children {
If (setting.Name != "Source") {
Return This.ValidationError(setting, "RX205", "Testing setting '" + setting.Name + "' is not implemented.", "Source", setting.Name, "Remove the unsupported testing setting.");
}
}
Return "";
}
Private Function ValidateCompilation(ProjectNode project) -> String {
ProjectNode compilation = This.FindChild(project, "Compilation");
For setting In compilation.children {
If (setting.Name == "Targets" || setting.Kind == "Targets") {
For target In setting.children {
If (target.Name == "Include" || target.Name == "Exclude") { Continue; }
String targetName = This.NormalizeTarget(target.Text);
If (targetName == "" || This.TargetPlatform(targetName) == "" || This.TargetArchitecture(targetName) == "") {
Return This.ValidationError(target, "RX201", "Compilation target '" + target.Text + "' is invalid.", "a supported target identifier", target.Text, "Use a target such as WindowsX64 or LinuxX64.");
}
}
Continue;
}
If (setting.Name != "CrossCompile" && setting.Name != "DefaultTarget" && setting.Name != "Parallel" && setting.Name != "Optimization" && setting.Name != "DebugSymbols" && setting.Name != "Intermediate") {
Return This.ValidationError(setting, "RX201", "Compilation setting '" + setting.Name + "' is not implemented.", "CrossCompile, DefaultTarget, Parallel, Optimization, DebugSymbols, Intermediate, or Targets", setting.Name, "Remove the unsupported compilation setting.");
}
If ((setting.Name == "CrossCompile" || setting.Name == "Parallel" || setting.Name == "DebugSymbols") &&
setting.Text.ToLower() != "true" && setting.Text.ToLower() != "false") {
Return This.ValidationError(setting, "RX201", setting.Name + " must be true or false.", "true or false", setting.Text, "Set the property to true or false.");
}
If (setting.Name == "Optimization") {
String optimization = setting.Text.ToLower();