Skip to content

Commit f667247

Browse files
authored
Merge pull request #209 from aaronfranke/format-ci
Add file formatting checks to CI
2 parents 74358e9 + ff82d6f commit f667247

File tree

6 files changed

+77
-6
lines changed

6 files changed

+77
-6
lines changed

.azure-pipelines/build_jobs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
# Use the specified version of Python from the tool cache
120120
- task: UsePythonVersion@0
121121
inputs:
122-
versionSpec: '3.9'
122+
versionSpec: '3.9'
123123
- task: PythonScript@0
124124
displayName: Move artifact contents
125125
inputs:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2020 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
jobs:
4+
- job: check_file_format
5+
displayName: 'Check file formatting'
6+
pool:
7+
vmImage: 'ubuntu-20.04'
8+
container: khronosgroup/docker-images:openxr-sdk
9+
steps:
10+
- script: sudo apt-get install -qq dos2unix recode
11+
displayName: Install dependencies
12+
- script: ./file_format.sh
13+
displayName: File formatting checks (file_format.sh)
14+
15+
- script: git diff --patch --exit-code > file_format.patch
16+
displayName: Save changes as diff
17+
- script: echo "The following files need file formatting:"; sed -n -e "s/^diff.* b\///p" file_format.patch
18+
condition: failed()
19+
- task: PublishPipelineArtifact@1
20+
displayName: Publish diff
21+
condition: failed()
22+
inputs:
23+
path: $(System.DefaultWorkingDirectory)/file_format.patch
24+
artifact: file_format_changes

file_format.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2020 The Khronos Group Inc.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# This script ensures proper POSIX text file formatting and a few other things.
6+
# This is supplementary to clang-format.
7+
8+
# We need dos2unix and recode.
9+
if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
10+
printf "Install 'dos2unix' and 'recode' to use this script.\n"
11+
fi
12+
13+
set -e -uo pipefail
14+
IFS=$'\n\t'
15+
16+
# Loops through all text files tracked by Git.
17+
git grep -zIl '' |
18+
while IFS= read -rd '' f; do
19+
# Exclude some files.
20+
if [[ "$f" == "external"* ]]; then
21+
continue
22+
elif [[ "$f" == "src/external"* ]]; then
23+
continue
24+
fi
25+
# Ensure that files are UTF-8 formatted.
26+
recode UTF-8 "$f" 2> /dev/null
27+
# Ensure that files have LF line endings and do not contain a BOM.
28+
dos2unix "$f" 2> /dev/null
29+
# Remove trailing space characters and ensures that files end
30+
# with newline characters. -l option handles newlines conveniently.
31+
perl -i -ple 's/\s*$//g' "$f"
32+
done
33+
34+
# If no patch has been generated all is OK, clean up, and exit.
35+
if git diff --exit-code > patch.patch; then
36+
printf "Files in this commit comply with the formatting rules.\n"
37+
rm -f patch.patch
38+
exit 0
39+
fi
40+
41+
# A patch has been created, notify the user, clean up, and exit.
42+
printf "\n*** The following differences were found between the code "
43+
printf "and the formatting rules:\n\n"
44+
cat patch.patch
45+
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
46+
rm -f patch.patch
47+
exit 1

specification/registry/xr.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,7 @@ maintained in the default branch of the Khronos OpenXR GitHub project.
35503550

35513551
<type name="XrEventDataDisplayRefreshRateChangedFB"/>
35523552
<enum offset="0" extends="XrStructureType" name="XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB"/>
3553-
3553+
35543554
<command name="xrEnumerateDisplayRefreshRatesFB"/>
35553555
<command name="xrGetDisplayRefreshRateFB"/>
35563556
<command name="xrRequestDisplayRefreshRateFB"/>
@@ -3592,14 +3592,14 @@ maintained in the default branch of the Khronos OpenXR GitHub project.
35923592
<enum value="&quot;XR_HTC_extension_107&quot;" name="XR_HTC_extension_107_EXTENSION_NAME"/>
35933593
</require>
35943594
</extension>
3595-
3595+
35963596
<extension name="XR_HTC_extension_108" number="108" type="instance" supported="disabled">
35973597
<require>
35983598
<enum value="1" name="XR_HTC_extension_108_SPEC_VERSION"/>
35993599
<enum value="&quot;XR_HTC_extension_108&quot;" name="XR_HTC_extension_108_EXTENSION_NAME"/>
36003600
</require>
36013601
</extension>
3602-
3602+
36033603
<extension name="XR_FB_color_space" number="109" type="instance" supported="openxr">
36043604
<require>
36053605
<enum value="1" name="XR_FB_color_space_SPEC_VERSION"/>

specification/scripts/docgenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def genStructBody(self, typeinfo, typeName):
291291
body += ';\n'
292292
body += '} ' + typeName + ';'
293293
return body
294-
294+
295295
def genStruct(self, typeinfo, typeName, alias):
296296
"""Generate struct."""
297297
OutputGenerator.genStruct(self, typeinfo, typeName, alias)

src/scripts/validation_layer_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def outputValidationSourceNextChainFunc(self):
501501
continue
502502
if struct_tuple.protect_value:
503503
next_chain_info += '#if %s\n' % struct_tuple.protect_string
504-
504+
505505
next_chain_info += self.writeIndent(2)
506506
next_chain_info += 'case %s:\n' % cur_value.name
507507
next_chain_info += self.writeIndent(3)

0 commit comments

Comments
 (0)