From 583ee4c2bf6260225612363d9bb278eb963685bf Mon Sep 17 00:00:00 2001 From: Bob Caddy Date: Fri, 11 Nov 2022 17:10:41 -0500 Subject: [PATCH 1/3] Add support for formatting `.cu` CUDA source files --- README.md | 1 + check.sh | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cb31bd9..69afaf4 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ The following file extensions are checked: * `.cxx` * `.ino` * `.pde` + * `.cu` * Protobuf files: * `.proto` diff --git a/check.sh b/check.sh index 41cc77a..a369ce1 100755 --- a/check.sh +++ b/check.sh @@ -5,10 +5,10 @@ ############################################################################### # USAGE: ./entrypoint.sh [] [] # -# 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 @@ -16,7 +16,7 @@ # 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 @@ -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|\+\+)(cu)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde)|(proto))$' -print) # check formatting in each source file for file in $src_files; do From e8ef01aa4f4e9aca5f1f8e5c6ad8595fa8b85f4a Mon Sep 17 00:00:00 2001 From: bcaddy <41171425+bcaddy@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:55:40 -0500 Subject: [PATCH 2/3] keep the non-C(++) regex tokens at the end with the others Co-authored-by: Johanan Idicula --- check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check.sh b/check.sh index a369ce1..2bf4cdb 100755 --- a/check.sh +++ b/check.sh @@ -68,7 +68,7 @@ exit_code=0 # ino, pde # proto # cu -src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex '^.*\.((((c|C)(c|pp|xx|\+\+)(cu)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde)|(proto))$' -print) +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 From 311cc0a7782144f2828d08f7533c902367a880f5 Mon Sep 17 00:00:00 2001 From: Bob Caddy Date: Tue, 6 Dec 2022 13:32:24 -0500 Subject: [PATCH 3/3] Add tests --- test/known_fail/addition.cu | 16 ++++++++++++++++ test/known_pass/addition.cu | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 test/known_fail/addition.cu create mode 100755 test/known_pass/addition.cu diff --git a/test/known_fail/addition.cu b/test/known_fail/addition.cu new file mode 100755 index 0000000..84dd741 --- /dev/null +++ b/test/known_fail/addition.cu @@ -0,0 +1,16 @@ +/* Addition program */ +#include + +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 */ +} diff --git a/test/known_pass/addition.cu b/test/known_pass/addition.cu new file mode 100755 index 0000000..ea6fe7c --- /dev/null +++ b/test/known_pass/addition.cu @@ -0,0 +1,17 @@ +/* Addition program */ +#include + +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 */ +}