forked from PowerShell/PSScriptAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildCoreClr.ps1
102 lines (83 loc) · 3.1 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
param(
[switch]$Build,
[switch]$Uninstall,
[switch]$Install,
[ValidateSet("net451", "netstandard2.0")]
[string]$Framework = "netstandard2.0",
[ValidateSet("Debug", "Release", "PSv3Debug", "PSv3Release", "PSv4Release")]
[string]$Configuration = "Debug"
)
if ($Configuration -match "PSv3" -and $Framework -eq "netstandard2.0")
{
throw ("{0} configuration is not applicable to {1} framework" -f $Configuration,$Framework)
}
Write-Progress "Building ScriptAnalyzer"
$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 "netstandard2.0")
{
$destinationDirBinaries = "$destinationDir\coreclr"
}
elseif ($Configuration -match 'PSv3') {
$destinationDirBinaries = "$destinationDir\PSv3"
}
elseif ($Configuration -match 'PSv4') {
$destinationDirBinaries = "$destinationDir\PSv4"
}
if ($build)
{
Write-Progress "Building Engine"
Push-Location Engine\
dotnet build Engine.csproj --framework $Framework --configuration $Configuration
Pop-Location
Write-Progress "Building for framework $Framework, configuration $Configuration"
Push-Location Rules\
dotnet build Rules.csproj --framework $Framework --configuration $Configuration
Pop-Location
Function CopyToDestinationDir($itemsToCopy, $destination)
{
if (-not (Test-Path $destination))
{
$null = New-Item -ItemType Directory $destination -Force
}
foreach ($file in $itemsToCopy)
{
Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Force
}
}
Write-Progress "Copying files to $destinationDir"
CopyToDestinationDir $itemsToCopyCommon $destinationDir
CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries
# Copy Settings File
Copy-Item -Path "$solutionDir\Engine\Settings" -Destination $destinationDir -Force -Recurse
# copy newtonsoft dll if net451 framework
if ($Framework -eq "net451")
{
copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
}
}
$modulePath = "$HOME\Documents\WindowsPowerShell\Modules";
$pssaModulePath = Join-Path $modulePath PSScriptAnalyzer
if ($uninstall)
{
if ((Test-Path $pssaModulePath))
{
Remove-Item -Recurse $pssaModulePath
}
}
if ($install)
{
Write-Progress "Installing to $modulePath"
Copy-Item -Recurse -Path "$destinationDir" -Destination "$modulePath\." -Force
}