-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.ps1
More file actions
155 lines (132 loc) · 5.03 KB
/
build.ps1
File metadata and controls
155 lines (132 loc) · 5.03 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
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
# *** DO NOT EDIT THIS FILE DIRECTLY ***
# This file is auto-generated from src/PostSharp.Engineering.BuildTools/Resources/Build.ps1
# Edit the source version, then run `./Build.ps1 generate-scripts` to regenerate this file.
[CmdletBinding(PositionalBinding = $false)]
param(
[switch]$Interactive, # Opens an interactive PowerShell session
[switch]$StartVsmon, # Enable the remote debugger.
[switch]$NoCache, # Bypass the build cache for `eng`, and force a rebuild.
[Parameter(ValueFromRemainingArguments)]
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container.
)
####
# These settings are replaced by the generate-scripts command.
$EngPath = 'eng'
$ProductName = 'PostSharpDocumentation'
####
if ($StartVsmon)
{
$vsmonport = 4024
Write-Host "Starting Visual Studio Remote Debugger, listening at port $vsmonport." -ForegroundColor Cyan
$vsmonProcess = Start-Process -FilePath "C:\msvsmon\msvsmon.exe" `
-ArgumentList "/noauth","/anyuser","/silent","/port:$vsmonport","/timeout:2147483647" `
-NoNewWindow -PassThru
}
# Change the prompt and window title in Docker.
if ($env:RUNNING_IN_DOCKER)
{
function global:prompt
{
$host.UI.RawUI.WindowTitle = "[docker] " + (Get-Location).Path
"[docker] $( Get-Location )> "
}
}
if (-not $Interactive -or $BuildArgs)
{
# The generate-scripts command implies -NoCache
if ($BuildArgs -contains 'generate-scripts')
{
$NoCache = $true
}
# Change the working directory so we can use a global.json that is specific to eng.
$previousLocation = Get-Location
Set-Location (Join-Path $PSScriptRoot $EngPath "src")
try
{
# Build caching: check if we need to rebuild
$projectPath = Join-Path $PSScriptRoot $EngPath "src" "Build$ProductName.csproj"
# Find the output DLL by looking for the first DLL in bin/Debug/*/
$binDebugPath = Join-Path $PSScriptRoot $EngPath "src" "bin" "Debug"
$outputDll = $null
if (Test-Path $binDebugPath)
{
$outputDll = Get-ChildItem -Path $binDebugPath -Filter "Build$ProductName.dll" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 | ForEach-Object { $_.FullName }
}
$needsBuild = $false
if ($NoCache)
{
# Cache bypassed by -NoCache switch
$needsBuild = $true
}
elseif (-not $outputDll -or -not (Test-Path $outputDll))
{
# DLL doesn't exist, need to build
$needsBuild = $true
}
else
{
# Get the DLL's last write time
$dllTime = (Get-Item $outputDll).LastWriteTime
# Check files in $EngPath/src (non-recursive)
$engSrcFiles = Get-ChildItem -Path (Join-Path $PSScriptRoot $EngPath "src") -File -ErrorAction SilentlyContinue
# Check files in $EngPath (non-recursive)
$engFiles = Get-ChildItem -Path (Join-Path $PSScriptRoot $EngPath) -File -ErrorAction SilentlyContinue
# Check files in $ScriptRoot (non-recursive)
$rootFiles = Get-ChildItem -Path $PSScriptRoot -File -ErrorAction SilentlyContinue
# Combine all files and check if any are newer than the DLL
$allFiles = @($engSrcFiles) + @($engFiles) + @($rootFiles)
foreach ($file in $allFiles)
{
if ($file.LastWriteTime -gt $dllTime)
{
$needsBuild = $true
break
}
}
}
if ($needsBuild)
{
# Build is needed
Write-Host "Building Build$ProductName..." -ForegroundColor Cyan
& dotnet build $projectPath
if ($LASTEXITCODE -ne 0)
{
throw "Build failed with exit code $LASTEXITCODE"
}
# Re-find the output DLL after build
if (Test-Path $binDebugPath)
{
$outputDll = Get-ChildItem -Path $binDebugPath -Filter "Build$ProductName.dll" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 | ForEach-Object { $_.FullName }
}
# Update the DLL timestamp to mark the cache as valid
if ($outputDll -and (Test-Path $outputDll))
{
(Get-Item $outputDll).LastWriteTime = Get-Date
}
else
{
throw "Build succeeded but output DLL '$outputDll' not found."
}
}
# Run the project using dotnet exec (faster than dotnet run)
if (-not $outputDll -or -not (Test-Path $outputDll))
{
throw "Output DLL not found. Expected path: '$outputDll'."
}
& dotnet exec $outputDll $BuildArgs
if ($StartVsmon)
{
Write-Host ""
Write-Host "Killing vsmon.exe."
$vsmonProcess.Kill()
}
}
finally
{
Set-Location $previousLocation
}
}
if ($Interactive)
{
Write-Host "Entering interactive PowerShell." -ForegroundColor Green
}