From e92d31edf940618fc58e0f0d8d7b90c1a0693f85 Mon Sep 17 00:00:00 2001 From: Katie Dektar Date: Fri, 25 Sep 2020 11:47:24 -0700 Subject: [PATCH 1/2] Use clang-format version 6 to ensure no diffs between newer and older ubuntu --- Makefile | 18 ++++++++++++------ diff_format.sh | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 67c9d5f..ab2b6f3 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,14 @@ REL_ROOT_PATH := $(shell realpath --relative-to=$(CPP_AUDIT_PATH) $(ROOT_PATH)) OUTPUT_FROM_ROOT := $(shell realpath --relative-to=$(ROOT_PATH) $(OUTPUT_PATH)) FILES := $(DRIVER) $(IMPLEMS) $(HEADERS) HAS_CLANGTDY := $(shell command -v clang-tidy 2> /dev/null) -HAS_CLANGFMT := $(shell command -v clang-format 2> /dev/null) +HAS_CLANGFMT := $(shell command -v clang-format-6.0 2> /dev/null) HAS_GTEST := $(shell echo -e "int main() { }" >> test.cc ; clang++ test.cc -o test -lgtest 2> /dev/null; echo $$?; rm -f test.cc test;) ifeq ($(OS_NAME), darwin) COMPILE_FLAGS := $(MAC_COMPILE_FLAGS) UT_COMPILE_FLAGS := $(MAC_UT_COMPILE_FLAGS) + # Mac doesn't have clang-format 6.0, must use default version. + HAS_CLANGFMT := $(shell command -v clang-format 2> /dev/null) HAS_BREW := $(shell command -v brew 2> /dev/null) endif @@ -96,20 +98,24 @@ endif formatcheck: ifndef HAS_CLANGFMT ifeq ($(OS_NAME),darwin) - @echo -e "clang-format not installed.\n" + @echo -e "clang-format not installed.\nNOTE: Mac doesn't support clang-format 6 which is used for grading.\n" @echo -e "Installing clang-format. Please provide the password when asked\n" @brew install clang-format @echo -e "Finished installing clang-format\n" else - @echo -e "clang-format not installed.\n" - @echo -e "Installing clang-format. Please provide the password when asked\n" - @sudo apt-get -y install clang-format - @echo -e "Finished installing clang-format\n" + @echo -e "clang-format-6.0 not installed.\n" + @echo -e "Installing clang-format-6.0. Please provide the password when asked\n" + @sudo apt-get -y install clang-format-6.0 + @echo -e "Finished installing clang-format-6.0\n" endif endif @echo -e "========================\nRunning format checker\n========================" @cd $(REL_ROOT_PATH)/ && bash $(CPPAUDIT_FROM_ROOT)/diff_format.sh $(CLANG_FORMAT_FLAGS) $(FILES) +ifeq ($(OS_NAME),darwin) @cd $(REL_ROOT_PATH)/ && clang-format $(FILES) -output-replacements-xml > $(OUTPUT_FROM_ROOT)/format.xml +else + @cd $(REL_ROOT_PATH)/ && clang-format-6.0 $(FILES) -output-replacements-xml > $(OUTPUT_FROM_ROOT)/format.xml +endif @echo -e "========================\nFormat checking complete\n========================\n" all: test stylecheck formatcheck diff --git a/diff_format.sh b/diff_format.sh index 4239dbe..6d1e3eb 100644 --- a/diff_format.sh +++ b/diff_format.sh @@ -2,7 +2,7 @@ OS_NAME=`uname -s | tr A-Z a-z` # Check if the first parameter is a flag starting with --. If so, that's -# a flag we want to pass to clang-format. Shift the other parameters +# a flag we want to pass to clang-format-6.0. Shift the other parameters # and continue. if [[ $1 =~ --.* ]]; then flag="$1" @@ -14,7 +14,7 @@ for file in "$@" do echo -e "\n[Checking $file]" if [[ "$OS_NAME" != "darwin" ]]; then - diff --suppress-common-lines --color=always -u1 <(cat $file) <(clang-format $flag $file) + diff --suppress-common-lines --color=always -u1 <(cat $file) <(clang-format-6.0 $flag $file) else diff --suppress-common-lines -U1 <(cat $file) <(clang-format $flag $file) fi From 6d3b532ffde85c2134b24cfb6a907c00d99fd976 Mon Sep 17 00:00:00 2001 From: Katie Dektar Date: Fri, 25 Sep 2020 11:47:24 -0700 Subject: [PATCH 2/2] Use clang-format version 6 to ensure no diffs between newer and older ubuntu --- Makefile | 18 ++++++++++++------ diff_format.sh | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 67c9d5f..ab2b6f3 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,14 @@ REL_ROOT_PATH := $(shell realpath --relative-to=$(CPP_AUDIT_PATH) $(ROOT_PATH)) OUTPUT_FROM_ROOT := $(shell realpath --relative-to=$(ROOT_PATH) $(OUTPUT_PATH)) FILES := $(DRIVER) $(IMPLEMS) $(HEADERS) HAS_CLANGTDY := $(shell command -v clang-tidy 2> /dev/null) -HAS_CLANGFMT := $(shell command -v clang-format 2> /dev/null) +HAS_CLANGFMT := $(shell command -v clang-format-6.0 2> /dev/null) HAS_GTEST := $(shell echo -e "int main() { }" >> test.cc ; clang++ test.cc -o test -lgtest 2> /dev/null; echo $$?; rm -f test.cc test;) ifeq ($(OS_NAME), darwin) COMPILE_FLAGS := $(MAC_COMPILE_FLAGS) UT_COMPILE_FLAGS := $(MAC_UT_COMPILE_FLAGS) + # Mac doesn't have clang-format 6.0, must use default version. + HAS_CLANGFMT := $(shell command -v clang-format 2> /dev/null) HAS_BREW := $(shell command -v brew 2> /dev/null) endif @@ -96,20 +98,24 @@ endif formatcheck: ifndef HAS_CLANGFMT ifeq ($(OS_NAME),darwin) - @echo -e "clang-format not installed.\n" + @echo -e "clang-format not installed.\nNOTE: Mac doesn't support clang-format 6 which is used for grading.\n" @echo -e "Installing clang-format. Please provide the password when asked\n" @brew install clang-format @echo -e "Finished installing clang-format\n" else - @echo -e "clang-format not installed.\n" - @echo -e "Installing clang-format. Please provide the password when asked\n" - @sudo apt-get -y install clang-format - @echo -e "Finished installing clang-format\n" + @echo -e "clang-format-6.0 not installed.\n" + @echo -e "Installing clang-format-6.0. Please provide the password when asked\n" + @sudo apt-get -y install clang-format-6.0 + @echo -e "Finished installing clang-format-6.0\n" endif endif @echo -e "========================\nRunning format checker\n========================" @cd $(REL_ROOT_PATH)/ && bash $(CPPAUDIT_FROM_ROOT)/diff_format.sh $(CLANG_FORMAT_FLAGS) $(FILES) +ifeq ($(OS_NAME),darwin) @cd $(REL_ROOT_PATH)/ && clang-format $(FILES) -output-replacements-xml > $(OUTPUT_FROM_ROOT)/format.xml +else + @cd $(REL_ROOT_PATH)/ && clang-format-6.0 $(FILES) -output-replacements-xml > $(OUTPUT_FROM_ROOT)/format.xml +endif @echo -e "========================\nFormat checking complete\n========================\n" all: test stylecheck formatcheck diff --git a/diff_format.sh b/diff_format.sh index 4239dbe..6d1e3eb 100644 --- a/diff_format.sh +++ b/diff_format.sh @@ -2,7 +2,7 @@ OS_NAME=`uname -s | tr A-Z a-z` # Check if the first parameter is a flag starting with --. If so, that's -# a flag we want to pass to clang-format. Shift the other parameters +# a flag we want to pass to clang-format-6.0. Shift the other parameters # and continue. if [[ $1 =~ --.* ]]; then flag="$1" @@ -14,7 +14,7 @@ for file in "$@" do echo -e "\n[Checking $file]" if [[ "$OS_NAME" != "darwin" ]]; then - diff --suppress-common-lines --color=always -u1 <(cat $file) <(clang-format $flag $file) + diff --suppress-common-lines --color=always -u1 <(cat $file) <(clang-format-6.0 $flag $file) else diff --suppress-common-lines -U1 <(cat $file) <(clang-format $flag $file) fi