Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file formatting checks to CI #209

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-pipelines/build_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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
aaronfranke marked this conversation as resolved.
Show resolved Hide resolved
# 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"
rpavlik marked this conversation as resolved.
Show resolved Hide resolved
fi

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

# Loops through all text files tracked by Git.
git grep -zIl '' |
rpavlik marked this conversation as resolved.
Show resolved Hide resolved
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
rpavlik marked this conversation as resolved.
Show resolved Hide resolved
exit 1
6 changes: 3 additions & 3 deletions specification/registry/xr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,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 @@ -3570,14 +3570,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