Skip to content

Commit

Permalink
Add support for formatting .cu CUDA source files (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaddy authored Dec 6, 2022
1 parent 7a90ba8 commit d687534
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The following file extensions are checked:
* `.cxx`
* `.ino`
* `.pde`
* `.cu`
* Protobuf files:
* `.proto`

Expand Down
13 changes: 7 additions & 6 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
###############################################################################
# USAGE: ./entrypoint.sh [<path>] [<fallback style>]
#
# Checks all C/C++/Protobuf files (.h, .H, .hpp, .hh, .h++, .hxx and .c, .C,
# .cpp, .cc, .c++, .cxx, .proto) in the provided GitHub repository path
# Checks all C/C++/Protobuf/CUDA files (.h, .H, .hpp, .hh, .h++, .hxx and .c, .C,
# .cpp, .cc, .c++, .cxx, .proto, .cu) in the provided GitHub repository path
# (arg1) for conforming to clang-format. If no path is provided or provided path
# is not a directory, all C/C++/Protobuf files are checked. If any files are
# is not a directory, all C/C++/Protobuf/CUDA files are checked. If any files are
# incorrectly formatted, the script lists them and exits with 1.
#
# Define your own formatting rules in a .clang-format file at your repository
# root. Otherwise, the provided style guide (arg2) is used as a fallback.

# format_diff function
# Accepts a filepath argument. The filepath passed to this function must point
# to a C/C++/Protobuf file.
# to a C/C++/Protobuf/CUDA file.
format_diff() {
local filepath="$1"
# Invoke clang-format with dry run and formatting error output
Expand Down Expand Up @@ -62,12 +62,13 @@ fi
exit_code=0

# All files improperly formatted will be printed to the output.
# find all C/C++/Protobuf files:
# find all C/C++/Protobuf/CUDA files:
# h, H, hpp, hh, h++, hxx
# c, C, cpp, cc, c++, cxx
# ino, pde
# proto
src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex '^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde)|(proto))$' -print)
# cu
src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex '^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde|proto|cu))$' -print)

# check formatting in each source file
for file in $src_files; do
Expand Down
16 changes: 16 additions & 0 deletions test/known_fail/addition.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Addition program */
#include <stdio.h>

main()
{
int integer1, integer2,sum; /* declaration before any executable statements*/

printf("Enter first integer\n"); /* prompt */
scanf("%d", &integer1); /* read an integer */
printf("Enter second integer\n"); /* prompt */
scanf("%d", &integer2); /* read an integer */
sum = integer1 + integer2; /* assignment of sum */
printf("Sum is %d\n", sum); /* print sum */

return 0; /* Indicate program ended successfully */
}
17 changes: 17 additions & 0 deletions test/known_pass/addition.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Addition program */
#include <stdio.h>

main()
{
int integer1, integer2,
sum; /* declaration before any executable statements*/

printf("Enter first integer\n"); /* prompt */
scanf("%d", &integer1); /* read an integer */
printf("Enter second integer\n"); /* prompt */
scanf("%d", &integer2); /* read an integer */
sum = integer1 + integer2; /* assignment of sum */
printf("Sum is %d\n", sum); /* print sum */

return 0; /* Indicate program ended successfully */
}

0 comments on commit d687534

Please sign in to comment.