Skip to content

Commit 49a5a5c

Browse files
committed
Try moving validation to a script file instead of inline so that paths relative to the script are easy to manage
1 parent 9d70407 commit 49a5a5c

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$VSDevCmd = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere" -latest -find Common7\tools\VSDevCmd.bat
2+
if (!$VSDevCmd) { exit 1 }
3+
Write-Host "Using VSDevCmd: ${VSDevCmd}"
4+
& $VSDevCmd;
5+
6+
$originalLocation = Get-Location
7+
Set-Location $PSScriptRoot\..\..\
8+
9+
& .\find_clang_format.cmd
10+
if ($LASTEXITCODE -ne 0) {
11+
exit $LASTEXITCODE
12+
}
13+
14+
& git clang-format origin/master --binary "$env:CLANG_FORMAT" --style file -- cppwinrt/*.h cppwinrt/*.cpp fast_fwd/*.h fast_fwd/*.cpp prebuild/*.h prebuild/*.cpp scratch/*.h scratch/*.cpp strings/*.h strings/*.cpp test/*.h test/*.cpp vsix/*.h vsix/*.cpp
15+
16+
if ($LASTEXITCODE -ne 0) {
17+
Write-Host ::error ERROR: This branch contains changes that have not been formatted with `'clang-format`'
18+
Write-Host NOTE: To resolve this issue, you can run `'clang-format`' in the following ways:
19+
Write-Host * Run ``build_test_all.cmd`` which will run `'clang-format`' on _all_ source files. This script is
20+
Write-Host simpler to run, however there`'s a chance it may touch additional files you never changed due to you having
21+
Write-Host a mis-matched version of `'clang-format`'. This may require you to manually revert changes made by
22+
Write-Host `'clang-format`' to the locations where you made no code changes.
23+
Write-Host
24+
Write-Host For more information, please see https://github.com/microsoft/cppwinrt?tab=readme-ov-file#formatting
25+
Write-Host
26+
Write-Host NOTE: As an additional note, given that different versions of `'clang-format`' may have different behaviors, this
27+
Write-Host may be a false positive. If you believe that to be the case ^`(e.g. none of the above resulted in modifications
28+
Write-Host to the code you have changed^`), please note this in your PR.
29+
exit 1
30+
}
31+
32+
Set-Location $originalLocation

.github/workflows/ci.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,7 @@ jobs:
1313
steps:
1414
- name: Check Formatting
1515
run: |
16-
if (!(Test-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat")) {
17-
Write-Host ERROR: Could not locate 'vcvars' batch file. This script is intended to be run from a build machine
18-
exit 1
19-
}
20-
21-
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
22-
23-
$repoRoot = "$env:GITHUB_WORKSPACE\.."
24-
Write-Host "The root of the repository is $repoRoot"
25-
26-
& $repoRoot\find_clang_format.cmd
27-
if ($LASTEXITCODE -ne 0) {
28-
exit $LASTEXITCODE
29-
}
30-
31-
& git clang-format origin/master --binary "$env:CLANG_FORMAT" --style file -- $repoRoot/cppwinrt/*.h $repoRoot/cppwinrt/*.cpp $repoRoot/fast_fwd/*.h $repoRoot/fast_fwd/*.cpp $repoRoot/prebuild/*.h $repoRoot/prebuild/*.cpp $repoRoot/scratch/*.h $repoRoot/scratch/*.cpp $repoRoot/strings/*.h $repoRoot/strings/*.cpp $repoRoot/test/*.h $repoRoot/test/*.cpp $repoRoot/vsix/*.h $repoRoot/vsix/*.cpp
32-
33-
if ($LASTEXITCODE -ne 0) {
34-
Write-Host ::error ERROR: This branch contains changes that have not been formatted with `'clang-format`'
35-
Write-Host NOTE: To resolve this issue, you can run `'clang-format`' in the following ways:
36-
Write-Host * Run ``build_test_all.cmd`` which will run `'clang-format`' on _all_ source files. This script is
37-
Write-Host simpler to run, however there`'s a chance it may touch additional files you never changed due to you having
38-
Write-Host a mis-matched version of `'clang-format`'. This may require you to manually revert changes made by
39-
Write-Host `'clang-format`' to the locations where you made no code changes.
40-
Write-Host
41-
Write-Host For more information, please see https://github.com/microsoft/cppwinrt?tab=readme-ov-file#formatting
42-
Write-Host
43-
Write-Host NOTE: As an additional note, given that different versions of `'clang-format`' may have different behaviors, this
44-
Write-Host may be a false positive. If you believe that to be the case ^`(e.g. none of the above resulted in modifications
45-
Write-Host to the code you have changed^`), please note this in your PR.
46-
exit 1
47-
}
16+
cmd /c "powershell CheckClangFormatting.ps1"
4817
4918
test-msvc-cppwinrt-build:
5019
name: '${{ matrix.compiler }}: Build (${{ matrix.arch }}, ${{ matrix.config }})'

0 commit comments

Comments
 (0)