From 1c453a372efeba834d2ebc3a37147948b2ed573d Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 10 Jul 2018 14:57:32 +0100 Subject: [PATCH 1/4] ci: no-exit: Document and echo what the check is Make it clearer why we run the check. Make it announce itself. Signed-off-by: Graham Whaley --- .ci/go-no-os-exit.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.ci/go-no-os-exit.sh b/.ci/go-no-os-exit.sh index 51eac257ab..fe3bbf64ab 100755 --- a/.ci/go-no-os-exit.sh +++ b/.ci/go-no-os-exit.sh @@ -2,9 +2,14 @@ # Copyright (c) 2018 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 +# +# Check there are no os.Exit() calls creeping into the code +# We don't use that exit path in the Kata codebase. go_packages=. +echo "Checking for no os.Exit() calls for package [${go_packages}]" + candidates=`go list -f '{{.Dir}}/*.go' $go_packages` for f in $candidates; do filename=`basename $f` From 6268ba4aa3ade9e195accdaf23e9ec84d493b8ff Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 10 Jul 2018 15:02:06 +0100 Subject: [PATCH 2/4] ci: no-exit: Skip check if no files to check If we find no files to check, gracefully quit the test. Formerly, if the list was empty we ended up trying to read from stdin, and thus hung. Signed-off-by: Graham Whaley --- .ci/go-no-os-exit.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.ci/go-no-os-exit.sh b/.ci/go-no-os-exit.sh index fe3bbf64ab..efac2835ad 100755 --- a/.ci/go-no-os-exit.sh +++ b/.ci/go-no-os-exit.sh @@ -22,6 +22,8 @@ for f in $candidates; do files="$f $files" done +[ -z "$files" ] && echo "No files to check, skipping" && exit 0 + if egrep -n '\' $files; then echo "Direct calls to os.Exit() are forbidden, please use exit() so atexit() works" exit 1 From 62495d45bedf23a552c5440f7359b9e3ba7da706 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 10 Jul 2018 15:14:24 +0100 Subject: [PATCH 3/4] ci: no-exit: Allow path override for os.Exit check Allow the path being checked by the os-no-exit script to be passed in, and update the Makefile to use that to check the current code paths of the cli and virtcontainers. Fixes: #477 Signed-off-by: Graham Whaley --- .ci/go-no-os-exit.sh | 4 +++- Makefile | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.ci/go-no-os-exit.sh b/.ci/go-no-os-exit.sh index efac2835ad..b429ed5a46 100755 --- a/.ci/go-no-os-exit.sh +++ b/.ci/go-no-os-exit.sh @@ -6,7 +6,9 @@ # Check there are no os.Exit() calls creeping into the code # We don't use that exit path in the Kata codebase. -go_packages=. +# Allow the path to check to be over-ridden. +# Default to the current directory. +go_packages=${1:-.} echo "Checking for no os.Exit() calls for package [${go_packages}]" diff --git a/Makefile b/Makefile index 10a7f851d2..cf68c09bc1 100644 --- a/Makefile +++ b/Makefile @@ -395,7 +395,8 @@ go-test: $(GENERATED_FILES) check-go-static: $(QUIET_CHECK).ci/static-checks.sh - $(QUIET_CHECK).ci/go-no-os-exit.sh + $(QUIET_CHECK).ci/go-no-os-exit.sh ./cli + $(QUIET_CHECK).ci/go-no-os-exit.sh ./virtcontainers coverage: $(QUIET_TEST).ci/go-test.sh html-coverage From 031632d5b00ffc3cff3314037741121f6cdff863 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 10 Jul 2018 17:04:27 +0100 Subject: [PATCH 4/4] ci: no-exit: Do not run no-exit check on test files The test files do not have access to our app level exit() function, and are thus OK to call os.Exit() if they need. Skip them from the check. Signed-off-by: Graham Whaley --- .ci/go-no-os-exit.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.ci/go-no-os-exit.sh b/.ci/go-no-os-exit.sh index b429ed5a46..5f0f98436a 100755 --- a/.ci/go-no-os-exit.sh +++ b/.ci/go-no-os-exit.sh @@ -15,12 +15,10 @@ echo "Checking for no os.Exit() calls for package [${go_packages}]" candidates=`go list -f '{{.Dir}}/*.go' $go_packages` for f in $candidates; do filename=`basename $f` + # skip all go test files + [[ $filename == *_test.go ]] && continue # skip exit.go where, the only file we should call os.Exit() from. [[ $filename == "exit.go" ]] && continue - # skip exit_test.go - [[ $filename == "exit_test.go" ]] && continue - # skip main_test.go - [[ $filename == "main_test.go" ]] && continue files="$f $files" done