Skip to content

Commit bf6e0ea

Browse files
committed
Squash infrastructure changes before reformatting from scratch again
1 parent cf96df5 commit bf6e0ea

File tree

6 files changed

+268
-0
lines changed

6 files changed

+268
-0
lines changed

.clang-format

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Microsoft
4+
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: AlwaysBreak
7+
AlignConsecutiveAssignments: false
8+
AlignEscapedNewlines: DontAlign
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AllowShortBlocksOnASingleLine: false
13+
AllowShortLambdasOnASingleLine: Inline
14+
AlwaysBreakBeforeMultilineStrings: true
15+
AlwaysBreakTemplateDeclarations: MultiLine
16+
BinPackArguments: false
17+
BinPackParameters: false
18+
BraceWrapping:
19+
AfterCaseLabel: true
20+
AfterUnion: true
21+
BeforeLambdaBody: true
22+
SplitEmptyFunction: false
23+
SplitEmptyRecord: false
24+
SplitEmptyNamespace: false
25+
BreakBeforeBinaryOperators: None
26+
BreakBeforeTernaryOperators: true
27+
BreakConstructorInitializers: AfterColon
28+
BreakStringLiterals: false
29+
CommentPragmas: '^ IWYU pragma:'
30+
CompactNamespaces: true
31+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
32+
ConstructorInitializerIndentWidth: 4
33+
ContinuationIndentWidth: 4
34+
Cpp11BracedListStyle: false
35+
DerivePointerAlignment: false
36+
DisableFormat: false
37+
FixNamespaceComments: true
38+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
39+
IncludeBlocks: Regroup
40+
IndentCaseLabels: false
41+
IncludeCategories:
42+
- Regex: '^"(stdafx.h|pch.h|precomp.h)"$'
43+
Priority: -1
44+
IndentWrappedFunctionNames: false
45+
KeepEmptyLinesAtTheStartOfBlocks: true
46+
MacroBlockBegin: '^BEGIN_COM_MAP$|^BEGIN_CONNECTION_POINT_MAP$|^BEGIN_HELPER_NODEMAP$|^BEGIN_MODULE$|^BEGIN_MSG_MAP$|^BEGIN_OBJECT_MAP$|^BEGIN_TEST_CLASS$|^BEGIN_TEST_METHOD$|^BEGIN_TEST_METHOD_PROPERTIES$'
47+
MacroBlockEnd: '^END_COM_MAP$|^END_CONNECTION_POINT_MAP$|^END_HELPER_NODEMAP$|^END_MODULE$|^END_MSG_MAP$|^END_OBJECT_MAP$|^END_TEST_CLASS$|^END_TEST_METHOD$|^END_TEST_METHOD_PROPERTIES$'
48+
MaxEmptyLinesToKeep: 1
49+
NamespaceIndentation: All
50+
ObjCBlockIndentWidth: 2
51+
ObjCSpaceAfterProperty: false
52+
ObjCSpaceBeforeProtocolList: true
53+
PackConstructorInitializers: NextLineOnly
54+
PenaltyBreakBeforeFirstCallParameter: 19
55+
PenaltyBreakComment: 300
56+
PenaltyBreakFirstLessLess: 120
57+
PenaltyBreakString: 2000
58+
PenaltyExcessCharacter: 2
59+
PointerAlignment: Left
60+
SortIncludes: false
61+
SpaceAfterCStyleCast: false
62+
SpaceBeforeAssignmentOperators: true
63+
SpaceBeforeParens: ControlStatements
64+
SpaceInEmptyParentheses: false
65+
SpacesBeforeTrailingComments: 1
66+
SpacesInAngles: Never
67+
SpacesInContainerLiterals: true
68+
SpacesInCStyleCastParentheses: false
69+
SpacesInParentheses: false
70+
SpacesInSquareBrackets: false
71+
Standard: Latest
72+
73+
AttributeMacros: [
74+
CALLBACK,
75+
]
76+
77+
StatementMacros: [
78+
_Acquires_exclusive_lock_,
79+
_Acquires_lock_,
80+
_Acquires_nonreentrant_lock_,
81+
_Acquires_shared_lock_,
82+
_Analysis_assume_smart_lock_acquired_,
83+
_Analysis_assume_smart_lock_released_,
84+
_Create_lock_level_,
85+
_Detaches_lock_,
86+
_Function_class_,
87+
_Global_cancel_spin_lock_,
88+
_Global_critical_region_,
89+
_Global_interlock_,
90+
_Global_priority_region_,
91+
_Has_lock_kind_,
92+
_Has_lock_level_,
93+
_IRQL_always_function_max_,
94+
_IRQL_always_function_min_,
95+
_IRQL_raises_,
96+
_IRQL_requires_,
97+
_IRQL_requires_max_,
98+
_IRQL_requires_min_,
99+
_IRQL_requires_same_,
100+
_IRQL_restores_,
101+
_IRQL_restores_global_,
102+
_IRQL_saves_,
103+
_IRQL_saves_global_,
104+
_Lock_level_order_,
105+
_Moves_lock_,
106+
_Must_inspect_result_,
107+
_No_competing_thread_,
108+
_Post_same_lock_,
109+
_Post_writable_byte_size_,
110+
_Pre_satisfies_,
111+
_Releases_exclusive_lock_,
112+
_Releases_lock_,
113+
_Releases_nonreentrant_lock_,
114+
_Releases_shared_lock_,
115+
_Replaces_lock_,
116+
_Requires_exclusive_lock_held_,
117+
_Requires_lock_held_,
118+
_Requires_lock_not_held_,
119+
_Requires_no_locks_held_,
120+
_Requires_shared_lock_held_,
121+
_Ret_maybenull_,
122+
_Ret_range_,
123+
_Struct_size_bytes_,
124+
_Success_,
125+
_Swaps_locks_,
126+
_Use_decl_annotations_,
127+
_When_,
128+
129+
DECLARE_ORDINAL_MAP,
130+
DECLARE_PROCNAME_MAP,
131+
DEFINE_ORDINAL_ENTRIES,
132+
DEFINE_ORDINAL_ENTRIES_ALTNAME,
133+
DEFINE_ORDINAL_ENTRIES_APISET,
134+
DEFINE_ORDINAL_MAP,
135+
DEFINE_PROCNAME_ENTRIES,
136+
DEFINE_PROCNAME_ENTRIES_ALTNAME,
137+
DEFINE_PROCNAME_ENTRIES_APISET,
138+
DEFINE_PROCNAME_MAP,
139+
DLOENTRY,
140+
DLOENTRY_APISET,
141+
DLPENTRY,
142+
DLPENTRY_APISET,
143+
144+
RpcEndExcept,
145+
146+
ActivatableClass,
147+
ActivatableClassWithFactory,
148+
ActivatableClassWithFactoryEx,
149+
ActivatableStaticOnlyFactory,
150+
ActivatableStaticOnlyFactoryEx,
151+
CoCreatableClass,
152+
CoCreatableClassWithFactory,
153+
CoCreatableClassWithFactoryEx,
154+
155+
TEST_CASE,
156+
SECTION,
157+
]
158+
159+
TypenameMacros: [
160+
IFACEMETHOD,
161+
STDMETHOD,
162+
STDAPI_,
163+
]

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,51 @@ on:
77
- master
88

99
jobs:
10+
check-formatting:
11+
name: 'Check Formatting of Changes'
12+
runs-on: windows-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
# Force a non-shallow checkout, so that clang-format can access source history to compare against
17+
# See https://github.com/actions/checkout for more details.
18+
fetch-depth: 0
19+
20+
- name: Find vcvars64.bat
21+
run: |
22+
$vcvars64 = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere" -latest -find VC\Auxiliary\Build\vcvars64.bat
23+
if (!$vcvars64) { exit 1 }
24+
Write-Host "Using vcvars64: ${vcvars64}"
25+
Add-Content $env:GITHUB_ENV "vcvars64=$vcvars64"
26+
27+
- name: Check Formatting
28+
shell: cmd
29+
run: |
30+
call "%vcvars64%"
31+
32+
call .\find_clang_format.cmd
33+
if %ERRORLEVEL% neq 0 (
34+
exit /b %ERRORLEVEL%
35+
)
36+
37+
git clang-format origin/master --binary "%CLANG_FORMAT%" --style file -- cppwinrt/*.h cppwinrt/*.cpp fast_fwd/*.h fast_fwd/*.cpp natvis/*.h natvis/*.cpp prebuild/*.h prebuild/*.cpp scratch/*.h scratch/*.cpp strings/*.h strings/*.cpp test/*.h test/*.cpp vsix/*.h vsix/*.cpp
38+
39+
if %ERRORLEVEL% neq 0 (
40+
echo ::error::This branch contains changes that have not been formatted with 'clang-format',
41+
echo NOTE: To resolve this issue, you can run 'clang-format' in the following ways:
42+
echo * Run build_test_all.cmd which will run 'clang-format' on _all_ source files. This script is
43+
echo simpler to run, however there's a chance it may touch additional files you never changed due to you having
44+
echo a mis-matched version of 'clang-format'. This may require you to manually revert changes made by
45+
echo 'clang-format' to the locations where you made no code changes.
46+
echo.
47+
echo For more information, please see https://github.com/microsoft/cppwinrt?tab=readme-ov-file#formatting
48+
echo.
49+
echo NOTE: As an additional note, given that different versions of 'clang-format' may have different behaviors, this
50+
echo may be a false positive. If you believe that to be the case ^(e.g. none of the above resulted in modifications
51+
echo to the code you have changed^), please note this in your PR.
52+
exit /b 1
53+
)
54+
1055
test-msvc-cppwinrt-build:
1156
name: '${{ matrix.compiler }}: Build (${{ matrix.arch }}, ${{ matrix.config }})'
1257
strategy:

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ a dev command prompt at the root of the repo _after_ following the above build i
3434
* Run `build_prior_projection.cmd` in the dev command prompt as well
3535
* Run `prepare_versionless_diffs.cmd` which removes version stamps on both current and prior projection
3636
* Use a directory-level differencing tool to compare `_build\$(arch)\$(flavor)\winrt` and `_reference\$(arch)\$(flavor)\winrt`
37+
38+
## Formatting
39+
40+
This project has adopted `clang-format` as the tool for formatting our code.
41+
Please note that the `.clang-format` at the root of the repo is a copy from the internal Windows repo with few additions.
42+
In general, please do not modify it.
43+
If you find that a macro is causing bad formatting of code, you can add that macro to one of the corresponding arrays in the `.clang-format` file (e.g. `AttributeMacros`, etc.), format the code, and submit a PR.
44+
45+
> _NOTE: Different versions of `clang-format` may format the same code differently.
46+
In an attempt to maintain consistency between changes, we've standardized on using the version of `clang-format` that ships with the latest version of Visual Studio.
47+
If you have LLVM installed and added to your `PATH`, the version of `clang-format` that gets picked up by default may not be the one we expect.
48+
49+
Before submitting a PR to the cppwinrt repo we ask that you first run `clang-format` on your changes.
50+
There is a CI check in place that will fail the build for your PR if you have not run `clang-format`.
51+
`clang-format` will run automatically as part of `build_test_all.cmd`, so if you use that script this
52+
should happen automatically.

build_test_all.cmd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@echo off
2+
setlocal
3+
setlocal EnableDelayedExpansion
24

35
set target_platform=%1
46
set target_configuration=%2
@@ -9,13 +11,36 @@ if "%target_platform%"=="" set target_platform=x64
911
if "%target_configuration%"=="" set target_configuration=Release
1012
if "%target_version%"=="" set target_version=1.2.3.4
1113

14+
:: Automatically run clang-format on all .cpp and .h files under the specified directories before building.
15+
call "%~dp0/find_clang_format.cmd"
16+
if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
17+
18+
set DIRS=cppwinrt fast_fwd natvis prebuild scratch strings test vsix
19+
set EXTS=.cpp .h
20+
for %%d in (%DIRS%) do call :format_files %~dp0%%d
21+
goto :post_format
22+
23+
:format_files
24+
for %%e in (%EXTS%) do (
25+
for /R %1 %%f in (*%%e) do call :run_clang_format "%%f"
26+
)
27+
goto :eof
28+
29+
:run_clang_format
30+
"%CLANG_FORMAT%" -style=file -i %1
31+
goto :eof
32+
33+
:post_format
34+
35+
:: NuGet restore all solutions before building
1236
if not exist ".\.nuget" mkdir ".\.nuget"
1337
if not exist ".\.nuget\nuget.exe" powershell -Command "$ProgressPreference = 'SilentlyContinue' ; Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile .\.nuget\nuget.exe"
1438

1539
call .nuget\nuget.exe restore cppwinrt.sln"
1640
call .nuget\nuget.exe restore natvis\cppwinrtvisualizer.sln
1741
call .nuget\nuget.exe restore test\nuget\NugetTest.sln
1842

43+
:: Build all solutions in order
1944
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:fast_fwd
2045

2146
call msbuild /p:Configuration=%target_configuration%,Platform=%target_platform%,Deployment=Component;CppWinRTBuildVersion=%target_version% natvis\cppwinrtvisualizer.sln
@@ -37,4 +62,5 @@ call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platfor
3762
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_module_lock_none
3863
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\old_tests\test_old
3964

65+
:: Run tests after building
4066
call run_tests.cmd %target_platform% %target_configuration%

find_clang_format.cmd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@echo off
2+
:: NOTE: No 'setlocal' since we're "returning" the definition of "CLANG_FORMAT" to the caller
3+
4+
:: Clang format's behavior has changed over time, meaning that different machines with different versions of LLVM
5+
:: installed may get different formatting behavior. In an attempt to ensure consistency, we use the clang-format.exe
6+
:: that ships with Visual Studio. There may still be issues if two different machines have different versions of Visual
7+
:: Studio installed, however this will hopefully improve things
8+
set CLANG_FORMAT=%VCINSTALLDIR%\Tools\Llvm\bin\clang-format.exe
9+
if not exist "%CLANG_FORMAT%" (
10+
set CLANG_FORMAT=
11+
echo ERROR: clang-format.exe not found at %%VCINSTALLDIR%%\Tools\Llvm\bin\clang-format.exe
12+
echo ERROR: Ensure that this script is being run from a Visual Studio command prompt
13+
exit /B 1
14+
)

strings/base_extern.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
// clang-format off
3+
24
__declspec(selectany) int32_t(__stdcall* winrt_to_hresult_handler)(void* address) noexcept {};
35
__declspec(selectany) winrt::hstring(__stdcall* winrt_to_message_handler)(void* address) {};
46
__declspec(selectany) void(__stdcall* winrt_throw_hresult_handler)(uint32_t lineNumber, char const* fileName, char const* functionName, void* returnAddress, winrt::hresult const result) noexcept {};
@@ -109,3 +111,5 @@ extern "C"
109111
}
110112

111113
#undef WINRT_IMPL_LINK
114+
115+
// clang-format on

0 commit comments

Comments
 (0)