|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +# Run a Bash command line (passed to bash -lc) after initializing MSVC via |
| 20 | +# vcvarsall.bat. Locates Visual Studio using vswhere so CI works across |
| 21 | +# Enterprise, Community, Build Tools, and future image layouts. |
| 22 | + |
| 23 | +param( |
| 24 | + [Parameter(Mandatory = $true)] |
| 25 | + [string]$BashCommand |
| 26 | +) |
| 27 | + |
| 28 | +$ErrorActionPreference = "Stop" |
| 29 | + |
| 30 | +$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" |
| 31 | +if (-not (Test-Path -LiteralPath $vswhere)) { |
| 32 | + Write-Error "vswhere.exe not found: $vswhere" |
| 33 | + exit 1 |
| 34 | +} |
| 35 | + |
| 36 | +$installationPath = & $vswhere ` |
| 37 | + -latest -products * ` |
| 38 | + -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` |
| 39 | + -property installationPath |
| 40 | + |
| 41 | +if ([string]::IsNullOrWhiteSpace($installationPath)) { |
| 42 | + $installationPath = & $vswhere -latest -products * -property installationPath |
| 43 | +} |
| 44 | + |
| 45 | +if ([string]::IsNullOrWhiteSpace($installationPath)) { |
| 46 | + Write-Error "No Visual Studio installation with C++ tools found via vswhere." |
| 47 | + exit 1 |
| 48 | +} |
| 49 | + |
| 50 | +$vcvarsall = Join-Path $installationPath "VC\Auxiliary\Build\vcvarsall.bat" |
| 51 | +if (-not (Test-Path -LiteralPath $vcvarsall)) { |
| 52 | + Write-Error "vcvarsall.bat not found: $vcvarsall" |
| 53 | + exit 1 |
| 54 | +} |
| 55 | + |
| 56 | +cmd.exe /c "call `"$vcvarsall`" x64 && bash -lc `"$BashCommand`"" |
| 57 | +exit $LASTEXITCODE |
0 commit comments