forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateBuilds.ps1
222 lines (175 loc) · 5.85 KB
/
GenerateBuilds.ps1
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
$header = @"
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="`$([MSBuild]::GetDirectoryNameOfFileAbove(`$(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
"@
$footer = @"
</ItemGroup>
<Import Project="`$([MSBuild]::GetDirectoryNameOfFileAbove(`$(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
"@
function WriteBuilds($allConfigs, $srcDir, $projName)
{
$configs = "";
# Sort via Target then OS
$ac = $allConfigs | sort target, os
foreach($c in $ac)
{
if ($c.relpath -eq $null) { continue }
$config = " <Project Include=`"$($c.relPath)`""
if ($c.os -ne $null -or $c.target -ne $null)
{
$config += ">`r`n";
if ($c.os -ne $null) { $config += " <OSGroup>$($c.os)</OSGroup>`r`n"; }
if ($c.target -ne $null) { $config += " <TargetGroup>$($c.target)</TargetGroup>`r`n"; }
$config += " </Project>`r`n"
}
else
{
$config += " />`r`n";
}
$configs += $config;
}
#Write-Host $($srcDir.FullName +"\"+ $projName + ".builds")
sc $($srcDir.FullName +"\"+ $projName + ".builds") $($header+$configs+$footer)
#Write-Host $($header+$configs+$footer)
}
function GetDefaultConfiguration($projectConfigs, $projName)
{
if ($projectConfigs -eq $null -or $projectConfigs.Count -eq 0)
{
Write-Host "No configurations in $projName";
return $null;
}
$defaultConfig = $projectConfigs[0];
if ($defaultConfig.os -ne $null -or $defaultConfig.target -ne $null)
{
$windowsConfig = $projectConfigs | ? { $_.os -eq "Windows_NT" }
if ($windowsConfig.Count -gt 0)
{
$defaultConfig = $windowsConfig[0];
}
}
return $defaultConfig;
}
function WriteDefaultConfiguration($defaultConfig, $proj, $pf)
{
if ($defaultConfig.os -ne $null -or $defaultConfig.target -ne $null)
{
$dc = "";
if ($defaultConfig.os -ne $null)
{
if ($defaultConfig.os -eq "Windows_NT")
{
$dc += "Windows_";
}
else
{
$dc += $defaultConfig.os + "_";
}
}
if ($defaultConfig.target -ne $null) { $dc += $defaultConfig.target + "_"; }
$dc += "Debug";
$projectConfigProperty = " <Configuration Condition=`"'`$(Configuration)'==''`">$dc</Configuration>";
$projectLines = $pf[0..1];
$pfContinue = 2;
if ($pf[2] -match "Import")
{
$projectLines += " <PropertyGroup>";
$projectLines += $projectConfigProperty;
$projectLines += " </PropertyGroup>"
}
else
{
if ($pf[3] -match "Configuration")
{
$pf[3] = $projectConfigProperty;
}
elseif ($pf[3] -match "Setting default TargetGroup" -and $pf[4] -match "TargetGroup")
{
$projectLines += " <PropertyGroup>";
$projectLines += $projectConfigProperty;
$projectLines += " </PropertyGroup>"
$pfContinue = 6;
}
else
{
Write-Host $($proj.FullName + " doesn't have a Configuration block!");
s $proj.FullName
}
}
$projectLines += $pf[$pfContinue..$pf.Length];
sc $proj.FullName $projectLines
}
}
function CleanupProjects($proj, $pf)
{
$writeFile = $false;
$lineCount
$filtered += $pf | ? {
$lineCount++;
if ($lineCount -gt 4 -and $_ -match "<Configuration ") { $writeFile = $true; return $false; }
if ($_ -match "<Platform ") { $writeFile = $true; return $false; }
if ($_ -match "<OutputType>Library</OutputType>") { $writeFile = $true; return $false; }
return $true;
};
if ($writeFile)
{
sc $proj.FullName $filtered
}
}
function GetConfigurations($projs, $srcDir, $projName)
{
$allConfigs = @();
foreach($proj in $projs)
{
$pf = gc $proj;
$pfcs = @();
#CleanupProjects $proj $pf
$pf | ? { $_ -match "'(?<osg>Windows|Linux|OSX|FreeBSD)?_?(?<tg>net\d\d\d?|netcore\d\d|netcore\d\daot|dnxcore\d\d|dotnet\d\d)?_?Debug\|AnyCPU'" } | % {
$os = $matches["osg"];
$target = $matches["tg"];
$relPath = $proj.FullName.Replace($srcDir.FullName+"\", "");
if ($target -match "netcore.+") { $os = "Windows" }
if ($os -eq "Windows") { $os = "Windows_NT" }
$ht = new-object System.Object
$ht | Add-Member -type NoteProperty -name os -value $os
$ht | Add-Member -type NoteProperty -name target -value $target
$ht | Add-Member -type NoteProperty -name relPath -value $relPath
$ht | Add-Member -type NoteProperty -name projName -value $projName
$ht | Add-Member -type NoteProperty -name sortKey -value $($os+"-"+$target+"_"+$relPath)
$pfcs += $ht;
}
$defaultConfig = GetDefaultConfiguration $pfcs $proj.FullName
WriteDefaultConfiguration $defaultConfig $proj $pf
$allConfigs += $pfcs;
}
return $allConfigs | sort target, os;
}
$srcDirs = dir d:\git\corefx2\src\*\src
foreach($srcDir in $srcDirs)
{
#$srcDir.FullName
$projs = dir $srcDir -r -i *.csproj
if($projs.Count -eq 0) { Write-Host "Skipping $srcDir because it has no csproj files."; continue; }
$projName = $srcDir.Parent.Name;
$allSrcConfigs = GetConfigurations $projs $srcDir $projName
$defaultConfig = GetDefaultConfiguration $allSrcConfigs $projName
$testsDir = $srcDir.Parent.FullName + "\tests";
if (Test-Path $testsDir)
{
$testProjs = dir $testsDir -r -i *.csproj
if ($defaultConfig.os -eq "Windows_NT")
{
#$testProjs | % { WriteDefaultConfiguration $defaultConfig $_ $(gc $_) }
}
}
#$testConfigs = GetConfigurations $testProjs $testsDir $projName
WriteBuilds $allSrcConfigs $srcDir $projName
$bfs = dir $srcDir -r -i *.builds
if ($bfs.Count -ne 1)
{
$projName + " contains " + $bfs.Count + " builds files!";
}
}