-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (75 loc) · 3.04 KB
/
Copy pathProgram.cs
File metadata and controls
89 lines (75 loc) · 3.04 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
using VcxprojSimplifier;
bool debug = false;
bool replace_original = false;
int nb_errors = 0;
foreach (var arg in args)
{
if (arg.Equals("--debug", StringComparison.Ordinal))
{
debug = true;
continue;
}
if (arg.Equals("--go", StringComparison.Ordinal))
{
replace_original = true;
continue;
}
if (debug && replace_original)
{
Console.WriteLine("--debug and --go shall not be used together");
return -1;
}
if (!Path.Exists(arg))
{
continue;
}
// We try to factorize the conditions in adjacent MSbuild items.
// For this, we use several techniques that will:
// * split elements into smaller elements, and conversely, merge elements with same conditions together
// * move the conditions around
// * find sets of identical elements (except for the condition) that can be expressed as a single element
// In each step, extra care is taken to ensure that the meaning of the project stays the same.
// However:
// * Comments could move or become invalid
// * Some element attributes containing line breaks will have them replaced with spaces.
// * The absence of bugs is not guaranteed. Check the diff!
try
{
Transformations msbuild_project_xml = new(arg, debug);
msbuild_project_xml.SplitKnownElements();
msbuild_project_xml.MoveConditionsToLowerElements(singlePass: false);
while (
msbuild_project_xml.DeduplicateElementsWithUnifiableConditions() ||
msbuild_project_xml.MoveConditionsToUpperElements())
{
msbuild_project_xml.RemoveEmptyNodes();
msbuild_project_xml.PartitionElementsBySubelementConditions();
}
msbuild_project_xml.MoveConditionsToLowerElements(singlePass: false);
while (
msbuild_project_xml.JoinAdjacentElementsWithSameConditions() ||
msbuild_project_xml.DeduplicateElementsWithUnifiableConditions() ||
msbuild_project_xml.MoveConditionsToUpperElements())
{
msbuild_project_xml.RemoveEmptyNodes();
msbuild_project_xml.PartitionElementsBySubelementConditions();
}
msbuild_project_xml.MoveConditionsToLowerElements(singlePass: true);
while (
msbuild_project_xml.JoinAdjacentElementsWithSameConditions() ||
msbuild_project_xml.DeduplicateElementsWithUnifiableConditions() ||
msbuild_project_xml.MoveConditionsToUpperElements())
{
msbuild_project_xml.RemoveEmptyNodes();
msbuild_project_xml.PartitionElementsBySubelementConditions();
}
msbuild_project_xml.SaveTo(arg + (replace_original ? "" : ".simplified"));
Console.WriteLine($"MSBuild project {arg} processed successfully");
}
catch (Exception ex)
{
Console.WriteLine($"File {arg}: could not process\n.-------\n{ex}\n-------");
nb_errors++;
}
}
return nb_errors;