Skip to content

Commit

Permalink
Merge pull request #209 from aaronfranke/format-ci
Browse files Browse the repository at this point in the history
Add file formatting checks to CI
  • Loading branch information
rpavlik authored Apr 2, 2021
2 parents 74358e9 + ff82d6f commit f667247
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/build_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
# Use the specified version of Python from the tool cache
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
versionSpec: '3.9'
- task: PythonScript@0
displayName: Move artifact contents
inputs:
Expand Down
24 changes: 24 additions & 0 deletions .azure-pipelines/check_file_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
jobs:
- job: check_file_format
displayName: 'Check file formatting'
pool:
vmImage: 'ubuntu-20.04'
container: khronosgroup/docker-images:openxr-sdk
steps:
- script: sudo apt-get install -qq dos2unix recode
displayName: Install dependencies
- script: ./file_format.sh
displayName: File formatting checks (file_format.sh)

- script: git diff --patch --exit-code > file_format.patch
displayName: Save changes as diff
- script: echo "The following files need file formatting:"; sed -n -e "s/^diff.* b\///p" file_format.patch
condition: failed()
- task: PublishPipelineArtifact@1
displayName: Publish diff
condition: failed()
inputs:
path: $(System.DefaultWorkingDirectory)/file_format.patch
artifact: file_format_changes
47 changes: 47 additions & 0 deletions file_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Copyright (c) 2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

# This script ensures proper POSIX text file formatting and a few other things.
# This is supplementary to clang-format.

# We need dos2unix and recode.
if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
printf "Install 'dos2unix' and 'recode' to use this script.\n"
fi

set -e -uo pipefail
IFS=$'\n\t'

# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Exclude some files.
if [[ "$f" == "external"* ]]; then
continue
elif [[ "$f" == "src/external"* ]]; then
continue
fi
# Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
# Ensure that files have LF line endings and do not contain a BOM.
dos2unix "$f" 2> /dev/null
# Remove trailing space characters and ensures that files end
# with newline characters. -l option handles newlines conveniently.
perl -i -ple 's/\s*$//g' "$f"
done

# If no patch has been generated all is OK, clean up, and exit.
if git diff --exit-code > patch.patch; then
printf "Files in this commit comply with the formatting rules.\n"
rm -f patch.patch
exit 0
fi

# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1
6 changes: 3 additions & 3 deletions specification/registry/xr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3550,7 +3550,7 @@ maintained in the default branch of the Khronos OpenXR GitHub project.

<type name="XrEventDataDisplayRefreshRateChangedFB"/>
<enum offset="0" extends="XrStructureType" name="XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB"/>

<command name="xrEnumerateDisplayRefreshRatesFB"/>
<command name="xrGetDisplayRefreshRateFB"/>
<command name="xrRequestDisplayRefreshRateFB"/>
Expand Down Expand Up @@ -3592,14 +3592,14 @@ maintained in the default branch of the Khronos OpenXR GitHub project.
<enum value="&quot;XR_HTC_extension_107&quot;" name="XR_HTC_extension_107_EXTENSION_NAME"/>
</require>
</extension>

<extension name="XR_HTC_extension_108" number="108" type="instance" supported="disabled">
<require>
<enum value="1" name="XR_HTC_extension_108_SPEC_VERSION"/>
<enum value="&quot;XR_HTC_extension_108&quot;" name="XR_HTC_extension_108_EXTENSION_NAME"/>
</require>
</extension>

<extension name="XR_FB_color_space" number="109" type="instance" supported="openxr">
<require>
<enum value="1" name="XR_FB_color_space_SPEC_VERSION"/>
Expand Down
2 changes: 1 addition & 1 deletion specification/scripts/docgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def genStructBody(self, typeinfo, typeName):
body += ';\n'
body += '} ' + typeName + ';'
return body

def genStruct(self, typeinfo, typeName, alias):
"""Generate struct."""
OutputGenerator.genStruct(self, typeinfo, typeName, alias)
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/validation_layer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def outputValidationSourceNextChainFunc(self):
continue
if struct_tuple.protect_value:
next_chain_info += '#if %s\n' % struct_tuple.protect_string

next_chain_info += self.writeIndent(2)
next_chain_info += 'case %s:\n' % cur_value.name
next_chain_info += self.writeIndent(3)
Expand Down

0 comments on commit f667247

Please sign in to comment.