-
Notifications
You must be signed in to change notification settings - Fork 3
/
syncProj.cs
2195 lines (1831 loc) · 87.8 KB
/
syncProj.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Collections;
using System.Reflection;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
class Dictionary2<TKey, TValue> : Dictionary<TKey, TValue>
{
new public TValue this[TKey name]
{
get
{
if (!ContainsKey(name))
{
TValue v = default(TValue);
Type t = typeof(TValue);
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>))
v = (TValue)Activator.CreateInstance(t);
Add(name, v);
}
return base[name];
}
set {
base[name] = value;
}
}
}
/// <summary>
/// Info about updated files.
/// </summary>
public class UpdateInfo
{
bool immidiatePrint = false;
/// <summary>
/// Last update information of files which were updated or planned to be updated.
/// </summary>
static public UpdateInfo lastUpdateInfo = null;
/// <summary>
/// true if testing is in progress
/// </summary>
static public bool bTesting = false;
public UpdateInfo()
{
UpdateInfo alreadyUpdated = lastUpdateInfo;
lastUpdateInfo = this;
// If test is in progres, we collect all information into same class instance.
if (alreadyUpdated != null && bTesting)
{
lastUpdateInfo.filesUpdated.AddRange(alreadyUpdated.filesUpdated);
lastUpdateInfo.filesUpToDate.AddRange(alreadyUpdated.filesUpToDate);
}
}
public UpdateInfo(bool _immidiatePrint): this()
{
immidiatePrint = _immidiatePrint;
}
/// <summary>
/// Files which were updated.
/// </summary>
public List<String> filesUpdated = new List<string>();
/// <summary>
/// Files which are up-to-date
/// </summary>
public List<String> filesUpToDate = new List<string>();
/// <summary>
/// Adds file which was updated.
/// </summary>
/// <param name="path">File path to be updated</param>
/// <param name="bWasSaved">true if file was saved, false if file is up-to-date</param>
public void MarkFileUpdated(String path, bool bWasSaved)
{
path = Path.GetFullPath(path);
if (!bWasSaved)
{
filesUpToDate.Add(path);
}
else
{
filesUpdated.Add(path);
}
if (!immidiatePrint)
return;
if( bWasSaved)
Console.WriteLine("File updated: " + Exception2.getPath(path));
}
/// <summary>
/// Prints summary about update
/// </summary>
[ExcludeFromCodeCoverage]
public void DisplaySummary()
{
// When testing is in progress we don't want detailed information on what was updated as what was not updated, as long as
// summary accessed files is the same.
if (!Exception2.g_bReportFullPath)
{
Console.WriteLine((filesUpdated.Count + filesUpToDate.Count) + " files updated");
return;
}
if (filesUpToDate.Count != 0)
Console.Write(filesUpToDate.Count + " files are up-to-date. ");
if (filesUpdated.Count != 0)
{
if (filesUpdated.Count == 1)
{
Console.WriteLine("File updated: " + filesUpdated[0]);
}
else
{
if (filesUpdated.Count < 3)
{
Console.WriteLine("Files updated: " + String.Join(", ", filesUpdated.Select(x => Path.GetFileName(x))));
}
else
{
Console.WriteLine(filesUpdated.Count + " files updated");
}
}
}
else
{
Console.WriteLine();
}
} //DisplaySummary
};
/// <summary>
/// Let's make system flexible enough that we can load projects and solutions independently of file format.
/// </summary>
[XmlInclude(typeof(Solution)), XmlInclude(typeof(Project))]
public class SolutionOrProject
{
public object solutionOrProject;
public String path;
public SolutionOrProject(String _path)
{
String header = "";
using (StreamReader sr = new StreamReader(_path, true))
{
header += sr.ReadLine();
header += sr.ReadLine();
sr.Close();
}
if (header.Contains("Microsoft Visual Studio Solution File"))
solutionOrProject = Solution.LoadSolution(_path);
else if (header.Contains("<SolutionOrProject"))
LoadCache(_path);
else
solutionOrProject = Project.LoadProject(null, _path);
path = _path;
}
public SolutionOrProject()
{
}
public void SaveCache(String path)
{
XmlSerializer ser = new XmlSerializer(typeof(SolutionOrProject), typeof(SolutionOrProject).GetNestedTypes());
using (var ms = new MemoryStream())
{
ser.Serialize(ms, this);
String outS = Encoding.UTF8.GetString(ms.ToArray());
File.WriteAllText(path, outS);
}
} //Save
static public SolutionOrProject LoadCache(String path)
{
XmlSerializer ser = new XmlSerializer(typeof(SolutionOrProject), typeof(SolutionOrProject).GetNestedTypes());
using (var s = File.OpenRead(path))
{
SolutionOrProject prj = (SolutionOrProject)ser.Deserialize(s);
return prj;
}
}
/// <summary>
/// Walks through list of items, locates value using fieldName, identifies how many configuration lines we will need
/// and inserts lines into lines2dump.
/// </summary>
/// <param name="proj">Project which hosts configuration list.</param>
/// <param name="list">List to get values from</param>
/// <param name="fieldName">Field name to scan </param>
/// <param name="lines2dump">Lines which shall be created / updated.</param>
/// <param name="valueToLine">value to config line translator function. Function can return null if no lines needs to be provided.</param>
/// <param name="forceDefaultValue">If value cannot be configured in style - enabled/disable (one kind of flag only - enable) - specify here default value</param>
static void ConfigationSpecificValue(Project proj,
IList list,
String fieldName,
Dictionary2<String, List<String>> lines2dump,
Func<String, String> valueToLine,
String forceDefaultValue = null
)
{
if (list.Count == 0)
return;
Type itemType = list[0].GetType();
FieldInfo fi = itemType.GetField(fieldName);
// Value to it's repeatability.
Dictionary2<String, int> weigths = new Dictionary2<string, int>();
bool bCheckPlatformsVariation = proj.getPlatforms().Count > 1;
bool bCheckConfigurationNameVariation = proj.getConfigurationNames().Count > 1;
String defaultValue = forceDefaultValue;
//-----------------------------------------
// Collect all values for comparison.
//-----------------------------------------
String[] values = new string[list.Count];
for (int i = 0; i < list.Count; i++)
{
Object o = fi.GetValue(list[i]);
if (o == null) continue;
String value = o.ToString();
values[i] = value;
}
if (defaultValue == null)
{
//---------------------------------------------------------------------
// Select generic value, which is repeated in most of configurations.
//---------------------------------------------------------------------
for (int i = 0; i < list.Count; i++)
{
Object o = fi.GetValue(list[i]);
if (o == null) continue;
String value = o.ToString();
weigths[value]++;
}
if (weigths.Values.Count != 0)
{
int maxWeight = weigths.Values.Max();
List<String> maxValues = weigths.Where(x => x.Value == maxWeight).Select(x => x.Key).ToList();
if (maxValues.Count == 1)
defaultValue = maxValues[0];
} //if
} //if
weigths.Clear();
//---------------------------------------------------------------------
// Select by config or by platform specific values repeated in most of
// configuration, and which are not satisfied by defaultValue if any.
//---------------------------------------------------------------------
Dictionary<String, String> confKeyToValue = new Dictionary<string, string>();
Dictionary<String, bool> confKeyUseValue = new Dictionary<string, bool>();
for (int i = 0; i < values.Length; i++)
{
String value = values[i];
if (value == null) continue;
String[] configNamePlatform = proj.configurations[i].Split('|');
//
// We try to match by configuration name or by platform name, but we must have all values identical for
// same configuration or platform - if they are not, then we reset weights counter.
//
foreach ( String confKey in new String[] { "c" + configNamePlatform[0], "p" + configNamePlatform[1] })
{
if (confKeyUseValue.ContainsKey(confKey))
{
if (!confKeyUseValue[confKey]) //Disallowed to use, values not identical.
continue;
if (confKeyToValue[confKey] != value) // Are values identical - if not then disable selection of same config again.
{
confKeyUseValue[confKey] = false;
weigths.Remove(confKey);
continue;
}
if (defaultValue == null || value != defaultValue)
weigths[confKey]++; // Increment usage count if not default value
}
else {
confKeyUseValue[confKey] = true; // Let's hope that all values will match.
confKeyToValue[confKey] = value;
if (defaultValue == null || value != defaultValue)
weigths[confKey]++; // Increment usage count if not default value
}
}
} //for
// if we have some configuration defined, try to add to it.
foreach (var kv in lines2dump)
weigths[kv.Key]++;
// Remove all single repeated entries ( Can list them separately )
foreach (var k in weigths.Where(x => x.Value <= 1).Select(x => x.Key).ToList())
weigths.Remove(k);
// Configuration name "" (global), "c|p<Name>" (specific to configuration name or to platform)
// "m<ConfigName>|<PlatformName>" - configuration & platform specific item.
Dictionary<String, String> configToValue = new Dictionary<string, string>();
//---------------------------------------------------------------------
// Finally collect all single entries values, to see if defaultValue
// and by config or by platform matches are needed anymore.
//---------------------------------------------------------------------
for (int i = 0; i < list.Count; i++)
{
Object o = fi.GetValue(list[i]);
if (o == null) continue;
String value = o.ToString();
String[] configNamePlatform = proj.configurations[i].Split('|');
String configName = configNamePlatform[0];
String platform = configNamePlatform[1];
if (configToValue.ContainsKey("") && configToValue[""] == value)
continue;
bool matched = false;
foreach (var cvpair in configToValue)
{
matched = cvpair.Key.StartsWith("c") && cvpair.Key.Substring(1) == configName && cvpair.Value == value;
if (matched) break;
matched = cvpair.Key.StartsWith("p") && cvpair.Key.Substring(1) == platform && cvpair.Value == value;
if (matched) break;
}
if (matched)
continue;
if (defaultValue != null && defaultValue == value) // We have default value, and our default value matches our value.
{
configToValue[""] = value; // Rule by default value.
continue;
}
bool bCheckConfigurationName = bCheckConfigurationNameVariation;
if (configToValue.ContainsKey("c" + configName))
{
if (configToValue["c" + configName] == value)
continue;
bCheckConfigurationName = false;
}
if (bCheckConfigurationName && weigths.ContainsKey("c" + configName) )
{
configToValue["c" + configName] = value;
continue;
}
bool bCheckPlatform = bCheckPlatformsVariation;
if (configToValue.ContainsKey("p" + platform))
{
if (configToValue["p" + platform] == value)
continue;
bCheckPlatform = false;
}
if (bCheckPlatform && weigths.ContainsKey("p" + platform))
{
configToValue["p" + platform] = value;
continue;
}
configToValue["m" + proj.configurations[i]] = value;
} //for
foreach (var cvpair in configToValue)
{
String line = valueToLine(cvpair.Value);
if (String.IsNullOrEmpty(line))
continue;
lines2dump[cvpair.Key].Add(line);
}
} //ConfigationSpecificValue
//
// Parameters used in script generation functions
//
static bool bCsScript = false; // set to true when generating C# script, false if .lua script
static String brO = " ", brC = "";
static String arO = " { ", arC = " }";
static String head = "";
static String comment = "-- ";
static String lf = "\r\n";
/// <summary>
/// Tries to determine correct path of syncProj.exe
/// </summary>
/// <param name="inDir">Folder in which script is located</param>
/// <param name="pathToSyncProjExe">Initial proposal where it can be stored</param>
/// <returns>Path to syncProj.exe</returns>
static public String getSyncProjExeLocation( String inDir, String pathToSyncProjExe = null)
{
// Let's try to locate where syncProj.exe is located if not provided or does not exists.
String inPath = pathToSyncProjExe;
if (inPath != null)
{
if (!Path.IsPathRooted(inPath))
inPath = Path.Combine(inDir, pathToSyncProjExe);
if (!File.Exists(inPath))
inPath = null;
}
if (inPath == null) // If path does not exists or not specified, try to autoprobe
{
String exePath = Assembly.GetExecutingAssembly().Location; // If it was executed from syncProj.exe, then this is the path.
//
// With C# script it's bit much more complex. syncProj.exe was copied under temp folder because of
// copy local = true.
//
// For example path could be:
//
// C:\Users\<user>\AppData\Local\Temp\CSSCRIPT\89105968.shell\Debug\bin\<script>.dll
//
// And it's not possible to determine where that exe was copied from, except locate
// script project, load it, and parse hint path out of there.
//
if (exePath.Contains("\\CSSCRIPT\\"))
{
String mainExe = Assembly.GetEntryAssembly().Location;
String csScriptName = Path.GetFileNameWithoutExtension(mainExe);
String csProject = Path.Combine(Path.GetDirectoryName(mainExe), "..\\..", csScriptName + " (script).csproj");
if (File.Exists(csProject))
try
{
Project p = Project.LoadProject(null, csProject);
exePath = p.files.Where(x => x.includeType == IncludeType.Reference && x.relativePath == "syncproj").Select(x => x.HintPath).FirstOrDefault();
inPath = Path2.makeRelative(exePath, inDir);
}
catch { }
} //if-else
if (inPath == null)
inPath = Path2.makeRelative(exePath, inDir);
if (inPath != null)
pathToSyncProjExe = inPath;
} //if
return pathToSyncProjExe;
}
/// <summary>
/// Builds solution or project .lua/.cs scripts
/// </summary>
/// <param name="uinfo">Information about updates peformed (to print out summary)</param>
/// <param name="path">Full path from where project was loaded.</param>
/// <param name="solutionOrProject">Solution or project</param>
/// <param name="bProcessProjects">true to process sub-project, false not</param>
/// <param name="format">lua or cs</param>
/// <param name="outFile">Output filename without extension</param>
/// <param name="outPrefix">Output prefix (To add before project name)</param>
static public void UpdateProjectScript(UpdateInfo uinfo, String path, object solutionOrProject, String outFile, String format, bool bProcessProjects, String outPrefix)
{
bCsScript = (format == "cs");
if (bCsScript)
{
brO = "("; brC = ");";
arO = "( "; arC = " );";
head = " ";
comment = "// ";
}
else
{
brO = " "; brC = "";
arO = " { "; arC = " }";
head = "";
comment = "-- ";
}
String fileName = outFile;
if( fileName == null ) fileName = Path.GetFileNameWithoutExtension(path);
if (outPrefix != "") fileName = outPrefix + fileName;
Solution sln = solutionOrProject as Solution;
if (sln != null) // Visual studio MFC wizard can generate solution name = project name - we try here to separate solution from projects by using suffix.
fileName += "_sln";
String outDir = Path.GetDirectoryName(path);
String outPath = Path.Combine(outDir, fileName + "." + format);
StringBuilder o = new StringBuilder();
Project proj = solutionOrProject as Project;
String pathToSyncProjExe = "";
//
// C# script header
//
if (bCsScript)
{
pathToSyncProjExe = Path2.makeRelative(Assembly.GetExecutingAssembly().Location, Path.GetDirectoryName(Path.GetFullPath(path)));
o.AppendLine("//css_ref " + pathToSyncProjExe);
o.AppendLine("using System;");
o.AppendLine();
o.AppendLine("class Builder: SolutionProjectBuilder");
o.AppendLine("{");
o.AppendLine(" static void Main(String[] args)");
o.AppendLine(" {");
o.AppendLine(" try {");
}
o.AppendLine("");
head = " " + " " + " ";
if (sln != null)
{
// ---------------------------------------------------------------------------------
// Building solution
// ---------------------------------------------------------------------------------
o.AppendLine(head + "solution" + brO + "\"" + fileName + "\"" + brC);
o.AppendLine(head + " " + ((format == "lua") ? comment : "") + "vsver" + brO + sln.fileFormatVersion + brC);
if(sln.VisualStudioVersion != null)
o.AppendLine(head + " " + "VisualStudioVersion" + brO + "\"" + sln.VisualStudioVersion + "\"" + brC);
if (sln.MinimumVisualStudioVersion != null)
o.AppendLine(head + " " + "MinimumVisualStudioVersion" + brO + "\"" + sln.MinimumVisualStudioVersion + "\"" + brC);
if (sln.SolutionGuid != null)
o.AppendLine(head + " " + "uuid" + brO + "\"" + sln.SolutionGuid.Substring(1, sln.SolutionGuid.Length -2) + "\"" + brC);
o.AppendLine(head + " configurations" + arO + " " + String.Join(",", sln.configurations.Select(x => "\"" + x.Split('|')[0] + "\"").Distinct()) + arC);
o.AppendLine(head + " platforms" + arO + String.Join(",", sln.configurations.Select(x => "\"" + x.Split('|')[1] + "\"").Distinct()) + arC);
o.AppendLine(head + " solutionScript(\"" + fileName + ".cs" + "\");");
//
// Packaging projects cannot include custom build steps, we include them from solution update.
//
foreach( Project p in sln.projects )
{
if( !p.bIsPackagingProject )
continue;
String name = Path.GetFileNameWithoutExtension( p.RelativePath );
String dir = Path.GetDirectoryName( p.RelativePath );
String fileInclude = name;
if( outPrefix != "" ) fileInclude = outPrefix + name;
fileInclude = Path.Combine( dir, fileInclude + "." + format );
fileInclude = fileInclude.Replace("\\", "\\\\");
o.AppendLine(head + " projectScript(\"" + fileInclude + "\");");
}
String wasInSubGroup = "";
List<String> groupParts = new List<string>();
foreach (Project p in sln.projects)
{
if (p.IsSubFolder())
continue;
if(bProcessProjects && !p.bDefinedAsExternal)
UpdateProjectScript(uinfo, p.getFullPath(), p, null, format, false, outPrefix);
// Defines group / in which sub-folder we are.
groupParts.Clear();
Project pScan = p.parent;
for (; pScan != null; pScan = pScan.parent)
// Solution root does not have project name
if (pScan.ProjectName!= null )
groupParts.Insert(0, pScan.ProjectName);
String newGroup = String.Join("/", groupParts);
if (wasInSubGroup != newGroup)
{
o.AppendLine();
o.AppendLine(head + " group" + brO + "\"" + newGroup + "\"" + brC);
}
wasInSubGroup = newGroup;
// Define project
String name = Path.GetFileNameWithoutExtension(p.getFullPath());
String dir = Path.GetDirectoryName(p.RelativePath);
o.AppendLine();
if (!p.bDefinedAsExternal && bProcessProjects)
{
String fileInclude = name;
if (outPrefix != "") fileInclude = outPrefix + name;
// o.AppendLine(head + " " + comment + "Project '" + fileInclude + "'");
fileInclude = Path.Combine(dir, fileInclude + "." + format);
if (format == "lua")
{
fileInclude = fileInclude.Replace("\\", "/");
o.AppendLine(head + " include \"" + fileInclude + "\"");
}
else {
fileInclude = fileInclude.Replace("\\", "\\\\");
o.AppendLine(head + " invokeScript(\"" + fileInclude + "\");");
} //if-else
}
else
{
o.AppendLine(head + " externalproject" + brO + "\"" + name + "\"" + brC);
o.AppendLine(head + " location" + brO + "\"" + dir.Replace("\\", "/") + "\"" + brC);
o.AppendLine(head + " uuid" + brO + "\"" + p.ProjectGuid.Substring(1, p.ProjectGuid.Length - 2) + "\"" + brC);
o.AppendLine(head + " language" + brO + "\"" + p.getLanguage() + "\"" + brC);
o.AppendLine(head + " kind" + brO + "\"SharedLib\"" + brC);
} //if-else
//
// Define dependencies of project.
//
if (p.ProjectDependencies != null)
{
o.AppendLine();
foreach (String projDepGuid in p.ProjectDependencies)
{
Project depp = sln.projects.Where(x => x.ProjectGuid == projDepGuid).FirstOrDefault();
if (depp == null)
continue;
o.AppendLine(head + " dependson" + brO + "\"" + outPrefix + depp.ProjectName + "\"" + brC);
} //foreach
} //if
} //foreach
}
else {
// ---------------------------------------------------------------------------------
// Building project
// ---------------------------------------------------------------------------------
List<FileInfo> projReferences = proj.files.Where(x => x.includeType == IncludeType.ProjectReference).ToList();
// ---------------------------------------------------------------------------------
// Dump project references, pass 1.
// ---------------------------------------------------------------------------------
if (projReferences.Count != 0 && format == "lua")
{
foreach (FileInfo fi in projReferences)
{
String projPath = fi.relativePath;
String projName = Path.GetFileNameWithoutExtension(projPath);
String projDir = Path.GetDirectoryName(projPath);
o.AppendLine(head + "externalproject" + brO + "\"" + projName + "\"" + brC);
o.AppendLine(head + " location" + brO + "\"" + projDir.Replace("\\", "/") + "\"" + brC);
o.AppendLine(head + " uuid" + brO + "\"" + fi.Project.Substring(1, fi.Project.Length - 2) + "\"" + brC);
o.AppendLine(head + " kind \"SharedLib\"");
o.AppendLine();
}
}
// ---------------------------------------------------------------------------------
// Building project
// ---------------------------------------------------------------------------------
o.AppendLine(head + "project" + brO + "\"" + fileName + "\"" + brC);
if (format == "lua")
o.AppendLine(head + " location \".\"");
o.AppendLine(head + " configurations" + arO + " " + String.Join(",", proj.configurations.Select(x => "\"" + x.Split('|')[0] + "\"").Distinct()) + arC);
o.AppendLine(head + " platforms" + arO + String.Join(",", proj.configurations.Select(x => "\"" + x.Split('|')[1] + "\"").Distinct()) + arC);
if(proj.ProjectGuid != null)
o.AppendLine(head + " uuid" + brO + "\"" + proj.ProjectGuidShort + "\"" + brC);
if (format != "lua")
o.AppendLine(head + " vsver" + brO + proj.fileFormatVersion + brC);
// Packaging projects cannot have custom build step at this moment
if( bCsScript && !proj.bIsPackagingProject)
o.AppendLine(head + " projectScript(\"" + fileName + ".cs" + "\");");
// ---------------------------------------------------------------------------------
// Dump project references, pass 2.
// ---------------------------------------------------------------------------------
if (format == "lua")
{
foreach (FileInfo fi in projReferences)
{
String projPath = fi.relativePath;
String projName = Path.GetFileNameWithoutExtension(projPath);
o.AppendLine(head + " links " + arO + "\"" + projName + "\"" + arC);
}
}
else
{
foreach (FileInfo fi in projReferences)
o.AppendLine(head + " referencesProject(\"" + fi.relativePath.Replace("\\", "/") + "\", \"" + fi.Project.Substring(1, fi.Project.Length - 2) + "\");");
}
// ---------------------------------------------------------------------------------
// Assembly references
// ---------------------------------------------------------------------------------
List<FileInfo> asmReferences = proj.files.Where(x => x.includeType == IncludeType.Reference).ToList();
asmReferences.Sort(delegate (FileInfo f1, FileInfo f2)
{
int r = f1.GetSortTag() - f2.GetSortTag();
if (r != 0)
return r;
return f1.relativePath.CompareTo(f2.relativePath);
}
);
bool bOpenedJustNow = false;
bool bOpened = false;
int sortTag = -1;
for( int iAsmRef = 0; iAsmRef < asmReferences.Count; iAsmRef++)
{
FileInfo fi = asmReferences[iAsmRef];
FileInfo nextFi = (iAsmRef+1 < asmReferences.Count) ? asmReferences[iAsmRef+1]: null;
String name = fi.relativePath;
if (!String.IsNullOrEmpty(fi.HintPath))
name = fi.HintPath;
if (!bOpened)
{
o.Append(head + " references(");
sortTag = fi.GetSortTag();
bOpened = true;
bOpenedJustNow = true;
}
else {
bOpenedJustNow = false;
}
bool bClose = nextFi == null || fi.GetSortTag() != nextFi.GetSortTag();
if (!(bOpenedJustNow && bClose))
{
o.AppendLine();
o.Append(head + " ");
}
o.Append("\"" + name + "\"");
if (bClose)
{
bOpened = false;
if (!bOpenedJustNow)
{
o.AppendLine();
o.Append(head + " ");
}
String args = fi.GetCopyFlagsAsCallParameters();
if (args != "")
o.Append(",");
o.AppendLine(args + ");");
}
else
{
o.Append(",");
}
}
Dictionary2<String, List<String>> lines2dump = new Dictionary2<string, List<string>>();
foreach (var p in proj.projectConfig)
if (p.SubSystem == ESubSystem.Console && p.ConfigurationType == EConfigurationType.Application)
p.ConfigurationType = EConfigurationType.ConsoleApplication;
ConfigationSpecificValue(proj, proj.projectConfig, "ConfigurationType", lines2dump, (s) => {
String ctype = typeof(EConfigurationType).GetMember(s)[0].GetCustomAttribute<FunctionNameAttribute>().tag;
if (format == "lua")
{
return "kind" + brO + "\"" + ctype + "\"" + brC;
}
else
{
String os = proj.getOs();
String r = "kind" + brO + "\"" + ctype + "\"";
if ( os != null ) r += ",\"" + os + "\"";
r += brC;
return r;
}
} );
proj.projectConfig.Where(x => x.ConfigurationType == EConfigurationType.ConsoleApplication).ToList().ForEach(x => x.ConfigurationType = EConfigurationType.Application);
if( !proj.bIsPackagingProject )
{
ConfigationSpecificValue(proj, proj.projectConfig, "UseDebugLibraries", lines2dump, (s) => {
return "symbols" + brO + "\"" + ((s == "True") ? "on" : "off") + "\"" + brC;
});
ConfigationSpecificValue(proj, proj.projectConfig, "AssemblyDebug", lines2dump, (s) => {
String v = s.ToLower();
if (v == "false") return null;
return "AssemblyDebug" + brO + v + brC;
});
}
if (proj.Keyword == EKeyword.AntPackage || proj.Keyword == EKeyword.Android)
{
// If we have at least one api level set, we figure out the rest (defaults), and then we set up api level correctlt everywhere.
bool bUsesApiLevel = proj.projectConfig.Where(x => x.AndroidAPILevel != null).FirstOrDefault() != null;
for (int i = 0; i < proj.configurations.Count; i++)
if (proj.projectConfig[i].AndroidAPILevel == null)
proj.projectConfig[i].AndroidAPILevel = Configuration.getAndroidAPILevelDefault(proj.configurations[i]);
ConfigationSpecificValue(proj, proj.projectConfig, "AndroidAPILevel", lines2dump, (s) => {
return "androidapilevel" + brO + "\"" + s + "\"" + brC;
});
ConfigationSpecificValue(proj, proj.projectConfig, "UseOfStl", lines2dump, (s) =>
{
List<String> descriptions = Configuration.UseOfStl_getSupportedValues();
List<String> values = typeof(EUseOfStl).GetEnumNames().ToList();
int index = values.IndexOf(s);
String value;
if (index == -1)
value = s;
else
value = descriptions[index];
return "useofstl" + brO + "\"" + value + "\"" + brC;
});
ConfigationSpecificValue( proj, proj.projectConfig, "ThumbMode", lines2dump, ( s ) =>
{
if( s == "NotSpecified" ) s = ""; else s = "EThumbMode." + s;
return "thumbmode" + brO + s + brC;
});
}
if (proj.Keyword == EKeyword.MFCProj)
o.AppendLine(head + " flags" + brO + "\"MFC\"" + brC);
if(proj.CLRSupport != ECLRSupport.None)
o.AppendLine(head + " commonLanguageRuntime" + brO + "ECLRSupport." + proj.CLRSupport.ToString() + brC);
if (!String.IsNullOrEmpty(proj.WindowsTargetPlatformVersion))
o.AppendLine(head + " systemversion" + brO + "\"" + proj.WindowsTargetPlatformVersion + "\"" + brC);
if (!String.IsNullOrEmpty(proj.TargetFrameworkVersion))
o.AppendLine(head + " TargetFrameworkVersion" + brO + "\"" + proj.TargetFrameworkVersion + "\"" + brC);
ConfigationSpecificValue(proj, proj.projectConfig, "PlatformToolset", lines2dump, (s) => {
return "toolset" + brO + "\"" + s + "\"" + brC;
});
if (!proj.bIsPackagingProject)
{
ConfigationSpecificValue(proj, proj.projectConfig, "CharacterSet", lines2dump, (s) => {
String r = typeof(ECharacterSet).GetMember(s)[0].GetCustomAttribute<FunctionNameAttribute>().tag;
return "characterset" + brO + "\"" + r + "\"" + brC;
});
ConfigationSpecificValue(proj, proj.projectConfig, "CLRSupport", lines2dump, (s) => {
if (s == "None") return null;
return "commonLanguageRuntime" + brO + "ECLRSupport." + s + brC;
});
}
ConfigationSpecificValue(proj, proj.projectConfig, "UseOfMfc", lines2dump, (s) => {
if (s == "Static")
return "flags" + brO + "\"StaticRuntime\"" + brC;
return null;
}, "Dynamic");
ConfigationSpecificValue(proj, proj.projectConfig, "OutDir", lines2dump, (s) => { return "targetdir" + brO + "\"" + s.Replace("\\", "\\\\") + "\"" + brC; });
ConfigationSpecificValue(proj, proj.projectConfig, "IntDir", lines2dump, (s) => {
// '!' is needed for premake to disallow to invent folder structure by itself.
return "objdir" + brO + "\"" + s.Replace("\\", "\\\\") + ((bCsScript) ? "": "!") + "\"" + brC;
});
ConfigationSpecificValue(proj, proj.projectConfig, "TargetName", lines2dump, (s) => { return "targetname" + brO + "\"" + s + "\"" + brC; });
ConfigationSpecificValue(proj, proj.projectConfig, "TargetExt", lines2dump, (s) => { return "targetextension" + brO + "\"" + s + "\"" + brC; });
if (!proj.bIsPackagingProject)
ConfigationSpecificValue(proj, proj.projectConfig, "Optimization", lines2dump, (s) => {
String r = typeof(EOptimization).GetMember(s)[0].GetCustomAttribute<FunctionNameAttribute>().tag;
return "optimize" + brO + "\"" + r + "\"" + brC;
});
// Can be used only to enabled, for .lua - ConfigationSpecificValue should be changed to operate on some default (false) value.
ConfigationSpecificValue(proj, proj.projectConfig, "WholeProgramOptimization", lines2dump, (s) => {
if(s == "UseLinkTimeCodeGeneration" )
return "flags" + arO + "\"LinkTimeOptimization\"" + arC;
return "";
});
foreach (String step in new String[] { "PreBuild", "PreLink", "PostBuild" })
{
ConfigationSpecificValue(proj, proj.projectConfig, step + "Event", lines2dump, (s) =>
{
BuildEvent bevent = XmlSerializer2.FromString<BuildEvent>(s);
if (bevent.Command == "") return "";
if (!bCsScript && step == "PreLink")
return "";
if (bCsScript)
return step.ToLower() + "commands" + arO + csQuoteString(bevent.Command) + arC;
else
return step.ToLower() + "commands" + arO + luaQuoteString(bevent.Command) + arC;
});
}
UpdateConfigurationEntries(proj, proj.projectConfig, lines2dump);
bool bFiltersActive = false;
WriteLinesToDump(o, lines2dump, ref bFiltersActive, null);
List<FileInfo> files2dump = proj.files.Where(x => x.includeType != IncludeType.ProjectReference && x.includeType != IncludeType.Reference).ToList();
// Sort files by path, so it would be easier to check what is included and what is not included.
files2dump.Sort(delegate (FileInfo f1, FileInfo f2) { return String.Compare(f1.relativePath, f2.relativePath); });
//
// Dump files array.
//
if (files2dump.Count != 0)
{
o.AppendLine(head + " files" + arO);
bool first = true;
foreach (FileInfo fi in files2dump)
{
if (!first) o.AppendLine(",");
first = false;
o.Append(head + " \"" + fi.relativePath.Replace("\\", "/") + "\"");
}
o.AppendLine();
o.AppendLine(head + " " + arC);
} //if
foreach (FileInfo fi in proj.files)
{
lines2dump.Clear();
// Enable custom build steps for files which has custom build step defined.
bool bHasCustomBuildStep = fi.fileConfig.Where(x => x.customBuildRule != null).FirstOrDefault() != null;
if (bHasCustomBuildStep)
fi.includeType = IncludeType.CustomBuild;
UpdateConfigurationEntries(proj, fi.fileConfig, lines2dump, fi.includeType, fi.relativePath);
WriteLinesToDump(o, lines2dump, ref bFiltersActive, fi.relativePath );
}
} //if-else
o.AppendLine();
//
// C# script trailer
//
if (bCsScript)
{