mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-02 00:02:01 +00:00
Merge pull request #479 from grahamwhaley/20180710_no_exit_check
Fix no exit static check
This commit is contained in:
commit
8af3dd4511
@ -2,21 +2,28 @@
|
|||||||
# Copyright (c) 2018 Intel Corporation
|
# Copyright (c) 2018 Intel Corporation
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# 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=.
|
# 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}]"
|
||||||
|
|
||||||
candidates=`go list -f '{{.Dir}}/*.go' $go_packages`
|
candidates=`go list -f '{{.Dir}}/*.go' $go_packages`
|
||||||
for f in $candidates; do
|
for f in $candidates; do
|
||||||
filename=`basename $f`
|
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.
|
# skip exit.go where, the only file we should call os.Exit() from.
|
||||||
[[ $filename == "exit.go" ]] && continue
|
[[ $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"
|
files="$f $files"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -z "$files" ] && echo "No files to check, skipping" && exit 0
|
||||||
|
|
||||||
if egrep -n '\<os\.Exit\>' $files; then
|
if egrep -n '\<os\.Exit\>' $files; then
|
||||||
echo "Direct calls to os.Exit() are forbidden, please use exit() so atexit() works"
|
echo "Direct calls to os.Exit() are forbidden, please use exit() so atexit() works"
|
||||||
exit 1
|
exit 1
|
||||||
|
3
Makefile
3
Makefile
@ -395,7 +395,8 @@ go-test: $(GENERATED_FILES)
|
|||||||
|
|
||||||
check-go-static:
|
check-go-static:
|
||||||
$(QUIET_CHECK).ci/static-checks.sh
|
$(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:
|
coverage:
|
||||||
$(QUIET_TEST).ci/go-test.sh html-coverage
|
$(QUIET_TEST).ci/go-test.sh html-coverage
|
||||||
|
Loading…
Reference in New Issue
Block a user