Skip to content

Commit b7ccb5c

Browse files
author
Alex Earl
committed
Revert "Rework msbuild invocation"
This reverts commit f9af6d4.
1 parent f9af6d4 commit b7ccb5c

1 file changed

Lines changed: 63 additions & 88 deletions

File tree

build.ps1

Lines changed: 63 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ param(
1111
)
1212

1313
$ErrorActionPreference = "Stop"
14-
$global:BUILDROOT = Get-Location
14+
$BUILDROOT = Get-Location
1515

1616
# Find MSBuild
1717
Write-Host "Locating MSBuild..."
@@ -21,34 +21,14 @@ if (-not (Test-Path $vswhere)) {
2121
exit 1
2222
}
2323

24-
$global:MSBUILD = & $vswhere -latest -products * `
25-
-requires Microsoft.Component.MSBuild `
26-
-find "MSBuild\**\Bin\MSBuild.exe" | Select-Object -First 1
24+
$MSBUILD = & $vswhere -products * -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" | Select-Object -First 1
2725

28-
if (-not $global:MSBUILD) {
26+
if (-not $MSBUILD) {
2927
Write-Error "MSBuild not found"
3028
exit 1
3129
}
3230

33-
$vsPath = & $vswhere -latest -products * `
34-
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
35-
-property installationPath | Select-Object -First 1
36-
37-
$global:VSINSTALLDIR = $vsPath
38-
if (-not $global:VSINSTALLDIR) {
39-
Write-Error "Visual Studio with VC tools not found"
40-
exit 1
41-
}
42-
43-
$global:VSDEVCMD = Join-Path $global:VSINSTALLDIR 'Common7\Tools\VsDevCmd.bat'
44-
45-
if (-not (Test-Path $global:VSDEVCMD)) {
46-
Write-Error "VsDevCmd.bat not found at $global:VSDEVCMD"
47-
exit 1
48-
}
49-
50-
Write-Host "MSBUILD=${global:MSBUILD}"
51-
Write-Host "VSDEVCMD=${global:VSDEVCMD}"
31+
Write-Host "MSBUILD=$MSBUILD"
5232

5333
# Determine version
5434
if ([string]::IsNullOrEmpty($Version)) {
@@ -70,85 +50,80 @@ if ([string]::IsNullOrEmpty($Version)) {
7050
Write-Host "Target version is $Version"
7151

7252
# Helper function to run MSBuild with error checking
73-
function Invoke-MSBuild {
74-
param(
75-
[string[]]$ProjectPaths,
76-
[string]$Arch,
77-
[string]$Platform,
78-
[string]$Configuration,
79-
[string]$Target = $null,
80-
[string]$Verbosity = "minimal"
81-
)
82-
83-
if (-not $Arch) {
84-
switch ($Platform) {
85-
"Win32" { $Arch = "x86" }
86-
"x64" { $Arch = "x64" }
87-
default {
88-
Write-Error "Unable to infer dev shell architecture for platform '$Platform'"
89-
exit 1
90-
}
91-
}
92-
}
93-
94-
$devCmdArgs = "-no_logo -arch=$Arch"
95-
$parts = @()
96-
$parts += "call `"$global:VSDEVCMD`" $devCmdArgs"
97-
98-
foreach ($projectPath in $ProjectPaths) {
99-
$parts += "&& `"$global:MSBUILD`" `"$projectPath`" /m /nologo /verbosity:$Verbosity /p:Configuration=$Configuration /p:Platform=$Platform"
100-
if ($Target) {
101-
$parts += " /t:$Target"
102-
}
103-
}
104-
$cmdLine = $parts -join ' '
105-
106-
Write-Host "Running MSBuild for platform=$Platform arch=$Arch target=$Target"
107-
& $env:ComSpec /d /s /c $cmdLine
108-
if ($LASTEXITCODE -ne 0) {
109-
Write-Error "MSBuild failed with exit code $LASTEXITCODE"
110-
exit $LASTEXITCODE
111-
}
112-
}
53+
function Invoke-MSBuild {
54+
param(
55+
[string]$Project,
56+
[string]$Platform,
57+
[string]$Target = $null,
58+
[string]$Verbosity = "minimal"
59+
)
60+
61+
$args = @(
62+
$Project,
63+
"/p:Configuration=$Configuration",
64+
"/p:Platform=$Platform",
65+
"/verbosity:$Verbosity",
66+
"/nologo"
67+
)
68+
69+
if ($Target) {
70+
$args = @("/t:$Target") + $args
71+
}
72+
73+
Write-Host "Running: & '$MSBUILD' $($args -join ' ')"
74+
& $MSBUILD @args
75+
if ($LASTEXITCODE -ne 0) {
76+
Write-Error "MSBuild failed with exit code $LASTEXITCODE"
77+
exit $LASTEXITCODE
78+
}
79+
}
11380

11481
# Clean function
115-
function Invoke-Clean {
116-
Write-Host "### Cleaning the $Configuration build directory"
117-
Push-Location "$global:BUILDROOT\native"
118-
try {
119-
Invoke-MSBuild -ProjectPaths @("winp.vcxproj", "sendctrlc\sendctrlc.vcxproj", "..\native_test\testapp\testapp.vcxproj") -Platform "Win32" -Arch "x86" -Configuration $Configuration -Target "Clean"
120-
Invoke-MSBuild -ProjectPaths @("winp.vcxproj", "sendctrlc\sendctrlc.vcxproj", "..\native_test\testapp\testapp.vcxproj") -Platform "x64" -Arch "x64" -Configuration $Configuration -Target "Clean"
121-
} finally {
122-
Pop-Location
123-
}
124-
}
82+
function Invoke-Clean {
83+
Write-Host "### Cleaning the $Configuration build directory"
84+
Push-Location "$BUILDROOT\native"
85+
86+
Invoke-MSBuild "winp.vcxproj" "Win32" "Clean"
87+
Invoke-MSBuild "winp.vcxproj" "x64" "Clean"
88+
Invoke-MSBuild "sendctrlc\sendctrlc.vcxproj" "Win32" "Clean"
89+
Invoke-MSBuild "sendctrlc\sendctrlc.vcxproj" "x64" "Clean"
90+
Invoke-MSBuild "..\native_test\testapp\testapp.vcxproj" "Win32" "Clean"
91+
Invoke-MSBuild "..\native_test\testapp\testapp.vcxproj" "x64" "Clean"
92+
93+
Pop-Location
94+
}
12595

12696
# Build function
127-
function Invoke-Build {
128-
Write-Host "### Building the $Configuration configuration"
129-
Push-Location "$global:BUILDROOT\native"
130-
try {
131-
Invoke-MSBuild -ProjectPaths @("winp.vcxproj", "sendctrlc\sendctrlc.vcxproj", "..\native_test\testapp\testapp.vcxproj") -Platform "Win32" -Arch "x86" -Configuration $Configuration
132-
Invoke-MSBuild -ProjectPaths @("winp.vcxproj", "sendctrlc\sendctrlc.vcxproj", "..\native_test\testapp\testapp.vcxproj") -Platform "x64" -Arch "x64" -Configuration $Configuration
133-
} finally {
134-
Pop-Location
135-
}
136-
97+
function Invoke-Build {
98+
Write-Host "### Building the $Configuration configuration"
99+
Push-Location "$BUILDROOT\native"
100+
101+
Invoke-MSBuild "winp.vcxproj" "Win32"
102+
Invoke-MSBuild "winp.vcxproj" "x64"
103+
Invoke-MSBuild "sendctrlc\sendctrlc.vcxproj" "Win32"
104+
Invoke-MSBuild "sendctrlc\sendctrlc.vcxproj" "x64"
105+
106+
Write-Host "### Building test applications"
107+
Invoke-MSBuild "..\native_test\testapp\testapp.vcxproj" "Win32" $null "minimal"
108+
Invoke-MSBuild "..\native_test\testapp\testapp.vcxproj" "x64" $null "minimal"
109+
110+
Pop-Location
111+
137112
Write-Host "### Updating WinP resource files for the $Configuration build"
138-
Set-Location $global:BUILDROOT
139-
113+
Set-Location $BUILDROOT
114+
140115
$resourceDir = "src\main\resources"
141116
if (-not (Test-Path $resourceDir)) {
142117
New-Item -ItemType Directory -Path $resourceDir -Force | Out-Null
143118
}
144-
119+
145120
$filesToCopy = @(
146121
@{ Source = "native\$Configuration\winp.dll"; Dest = "$resourceDir\winp.dll" },
147122
@{ Source = "native\x64\$Configuration\winp.dll"; Dest = "$resourceDir\winp.x64.dll" },
148123
@{ Source = "native\sendctrlc\Win32\$Configuration\sendctrlc.exe"; Dest = "$resourceDir\sendctrlc.exe" },
149124
@{ Source = "native\sendctrlc\x64\$Configuration\sendctrlc.exe"; Dest = "$resourceDir\sendctrlc.x64.exe" }
150125
)
151-
126+
152127
foreach ($file in $filesToCopy) {
153128
if (-not (Test-Path $file.Source)) {
154129
Write-Error "Source file not found: $($file.Source)"

0 commit comments

Comments
 (0)