forked from PowerShell/PSScriptAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildCoreClr.ps1
112 lines (92 loc) · 3.22 KB
/
buildCoreClr.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
param(
[switch]$Build,
[switch]$Uninstall,
[switch]$Install,
[ValidateSet("net451", "netstandard1.6")]
[string]$Framework = "netstandard1.6",
[ValidateSet("Debug", "Release", "PSv3Debug", "PSv3Release")]
[string]$Configuration = "Debug"
)
if ($Configuration -match "PSv3" -and $Framework -eq "netstandard1.6")
{
throw ("{0} configuration is not applicable to {1} framework" -f $Configuration,$Framework)
}
Function Test-DotNetRestore
{
param(
[string] $projectPath
)
Test-Path (Join-Path $projectPath 'project.lock.json')
}
$solutionDir = Split-Path $MyInvocation.InvocationName
if (-not (Test-Path "$solutionDir/global.json"))
{
throw "Not in solution root"
}
$itemsToCopyBinaries = @("$solutionDir\Engine\bin\$Configuration\$Framework\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
"$solutionDir\Rules\bin\$Configuration\$Framework\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll")
$itemsToCopyCommon = @("$solutionDir\Engine\PSScriptAnalyzer.psd1",
"$solutionDir\Engine\PSScriptAnalyzer.psm1",
"$solutionDir\Engine\ScriptAnalyzer.format.ps1xml",
"$solutionDir\Engine\ScriptAnalyzer.types.ps1xml")
$destinationDir = "$solutionDir\out\PSScriptAnalyzer"
$destinationDirBinaries = $destinationDir
if ($Framework -eq "netstandard1.6")
{
$destinationDirBinaries = "$destinationDir\coreclr"
}
elseif ($Configuration -match 'PSv3') {
$destinationDirBinaries = "$destinationDir\PSv3"
}
if ($build)
{
if (-not (Test-DotNetRestore((Join-Path $solutionDir Engine))))
{
throw "Please restore project Engine"
}
.\New-StronglyTypedCsFileForResx.ps1 Engine
Push-Location Engine\
dotnet build --framework $Framework --configuration $Configuration
Pop-Location
if (-not (Test-DotNetRestore((Join-Path $solutionDir Rules))))
{
throw "Please restore project Rules"
}
.\New-StronglyTypedCsFileForResx.ps1 Rules
Push-Location Rules\
dotnet build --framework $Framework --configuration $Configuration
Pop-Location
Function CopyToDestinationDir($itemsToCopy, $destination)
{
if (-not (Test-Path $destination))
{
New-Item -ItemType Directory $destination -Force
}
foreach ($file in $itemsToCopy)
{
Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Verbose -Force
}
}
CopyToDestinationDir $itemsToCopyCommon $destinationDir
CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries
# Copy Settings File
Copy-Item -Path "$solutionDir\Engine\Settings" -Destination $destinationDir -Force -Recurse -Verbose
# copy newtonsoft dll if net451 framework
if ($Framework -eq "net451")
{
copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries -Verbose
}
}
$modulePath = "$HOME\Documents\WindowsPowerShell\Modules";
$pssaModulePath = Join-Path $modulePath PSScriptAnalyzer
if ($uninstall)
{
if ((Test-Path $pssaModulePath))
{
Remove-Item -Recurse $pssaModulePath -Verbose
}
}
if ($install)
{
Copy-Item -Recurse -Path "$destinationDir" -Destination "$modulePath\." -Verbose -Force
}