mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
fb629db693
... and add the file to be checked by shellcheck.
The warnings fixed are:
In tests/integration/helpers.bash line 10:
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
^----------^ SC2128: Expanding an array without an index only gives the first element.
In tests/integration/helpers.bash line 22:
TESTDATA="${INTEGRATION_ROOT}/testdata"
^------^ SC2034: TESTDATA appears unused. Verify use (or export if used externally).
In tests/integration/helpers.bash line 42:
echo "runc $@ (status=$status):" >&2
^-- SC2145: Argument mixes string and array. Use * or separate argument.
^-----^ SC2154: status is referenced but not assigned.
In tests/integration/helpers.bash line 43:
echo "$output" >&2
^-----^ SC2154: output is referenced but not assigned.
In tests/integration/helpers.bash line 77:
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 10))"', "containerID": 1, "size": 20}]
^--------------------^ SC2004: $/${} is unnecessary on arithmetic variables.
In tests/integration/helpers.bash line 78:
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 100))"', "containerID": 1000, "size": '"$(($ROOTLESS_GIDMAP_LENGTH - 1000))"'}]'
^--------------------^ SC2004: $/${} is unnecessary on arithmetic variables.
^---------------------^ SC2004: $/${} is unnecessary on arithmetic variables.
In tests/integration/helpers.bash line 125:
base_path=$(gawk '$(NF-2) == "cgroup" && $NF ~ /\<'${g}'\>/ { print $5; exit }' /proc/self/mountinfo)
^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
base_path=$(gawk '$(NF-2) == "cgroup" && $NF ~ /\<'"${g}"'\>/ { print $5; exit }' /proc/self/mountinfo)
In tests/integration/helpers.bash line 127:
eval CGROUP_${g^^}_BASE_PATH="${base_path}"
^----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
eval CGROUP_"${g^^}"_BASE_PATH="${base_path}"
In tests/integration/helpers.bash line 229:
if [ "x$CGROUP_UNIFIED" = "xyes" ]; then
^----------------^ SC2268: Avoid x-prefix in comparisons as it no longer serves a purpose.
Did you mean:
if [ "$CGROUP_UNIFIED" = "yes" ]; then
In tests/integration/helpers.bash line 234:
eval cgroup=\$${var}${REL_CGROUPS_PATH}
^----^ SC2086: Double quote to prevent globbing and word splitting.
^-----------------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
eval cgroup=\$"${var}""${REL_CGROUPS_PATH}"
In tests/integration/helpers.bash line 236:
cat $cgroup/$source
^-----^ SC2086: Double quote to prevent globbing and word splitting.
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
cat "$cgroup"/"$source"
In tests/integration/helpers.bash line 242:
current="$(get_cgroup_value $1)"
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
current="$(get_cgroup_value "$1")"
In tests/integration/helpers.bash line 245:
echo "current" $current "!?" "$expected"
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "current" "$current" "!?" "$expected"
In tests/integration/helpers.bash line 257:
[ $(id -u) != "0" ] && user="--user"
^------^ SC2046: Quote this to prevent word splitting.
In tests/integration/helpers.bash line 259:
current=$(systemctl show $user --property $source $SD_UNIT_NAME | awk -F= '{print $2}')
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
current=$(systemctl show $user --property "$source" $SD_UNIT_NAME | awk -F= '{print $2}')
In tests/integration/helpers.bash line 261:
[ "$current" = "$expected" ] || [ -n "$expected2" -a "$current" = "$expected2" ]
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
In tests/integration/helpers.bash line 309:
check_cgroup_value "cpu.weight" $weight
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
check_cgroup_value "cpu.weight" "$weight"
In tests/integration/helpers.bash line 310:
check_systemd_value "CPUWeight" $weight
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
check_systemd_value "CPUWeight" "$weight"
In tests/integration/helpers.bash line 383:
if [ $CGROUP_UNIFIED = "no" -a ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
In tests/integration/helpers.bash line 412:
local cpu_count=$(grep -c '^processor' /proc/cpuinfo)
^-------^ SC2155: Declare and assign separately to avoid masking return values.
In tests/integration/helpers.bash line 450:
sleep $delay
^----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
sleep "$delay"
In tests/integration/helpers.bash line 453:
echo "Command \"$@\" failed $attempts times. Output: $output"
^-- SC2145: Argument mixes string and array. Use * or separate argument.
In tests/integration/helpers.bash line 471:
runc state $1
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
runc state "$1"
In tests/integration/helpers.bash line 472:
if [ $2 == "checkpointed" ]; then
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$2" == "checkpointed" ]; then
In tests/integration/helpers.bash line 484:
mkdir $dir
^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
mkdir "$dir"
In tests/integration/helpers.bash line 497:
kill -9 $(cat "$dir/pid")
^---------------^ SC2046: Quote this to prevent word splitting.
In tests/integration/helpers.bash line 508:
export ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc.XXXXXX")
^--^ SC2155: Declare and assign separately to avoid masking return values.
In tests/integration/helpers.bash line 512:
cd "$ROOT/bundle"
^---------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Did you mean:
cd "$ROOT/bundle" || exit
In tests/integration/helpers.bash line 535:
cd "$INTEGRATION_ROOT"
^--------------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Did you mean:
cd "$INTEGRATION_ROOT" || exit
For more information:
https://www.shellcheck.net/wiki/SC2145 -- Argument mixes string and array. ...
https://www.shellcheck.net/wiki/SC2034 -- TESTDATA appears unused. Verify u...
https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
155 lines
4.8 KiB
Makefile
155 lines
4.8 KiB
Makefile
CONTAINER_ENGINE := docker
|
|
GO ?= go
|
|
|
|
PREFIX ?= /usr/local
|
|
BINDIR := $(PREFIX)/sbin
|
|
MANDIR := $(PREFIX)/share/man
|
|
|
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
|
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
|
|
RUNC_IMAGE := runc_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
|
|
PROJECT := github.com/opencontainers/runc
|
|
BUILDTAGS ?= seccomp
|
|
COMMIT ?= $(shell git describe --dirty --long --always)
|
|
VERSION := $(shell cat ./VERSION)
|
|
|
|
ifeq ($(shell $(GO) env GOOS),linux)
|
|
ifeq (,$(filter $(shell $(GO) env GOARCH),mips mipsle mips64 mips64le ppc64))
|
|
ifeq (,$(findstring -race,$(EXTRA_FLAGS)))
|
|
GO_BUILDMODE := "-buildmode=pie"
|
|
endif
|
|
endif
|
|
endif
|
|
GO_BUILD := $(GO) build -trimpath $(GO_BUILDMODE) $(EXTRA_FLAGS) -tags "$(BUILDTAGS)" \
|
|
-ldflags "-X main.gitCommit=$(COMMIT) -X main.version=$(VERSION) $(EXTRA_LDFLAGS)"
|
|
GO_BUILD_STATIC := CGO_ENABLED=1 $(GO) build -trimpath $(EXTRA_FLAGS) -tags "$(BUILDTAGS) netgo osusergo" \
|
|
-ldflags "-extldflags -static -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION) $(EXTRA_LDFLAGS)"
|
|
|
|
.DEFAULT: runc
|
|
|
|
runc:
|
|
$(GO_BUILD) -o runc .
|
|
|
|
all: runc recvtty
|
|
|
|
recvtty:
|
|
$(GO_BUILD) -o contrib/cmd/recvtty/recvtty ./contrib/cmd/recvtty
|
|
|
|
static:
|
|
$(GO_BUILD_STATIC) -o runc .
|
|
$(GO_BUILD_STATIC) -o contrib/cmd/recvtty/recvtty ./contrib/cmd/recvtty
|
|
|
|
release:
|
|
script/release.sh -r release/$(VERSION) -v $(VERSION)
|
|
|
|
dbuild: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
--privileged --rm \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
$(RUNC_IMAGE) make clean all
|
|
|
|
lint:
|
|
golangci-lint run ./...
|
|
|
|
man:
|
|
man/md2man-all.sh
|
|
|
|
runcimage:
|
|
$(CONTAINER_ENGINE) build $(CONTAINER_ENGINE_BUILD_FLAGS) -t $(RUNC_IMAGE) .
|
|
|
|
test: unittest integration rootlessintegration
|
|
|
|
localtest: localunittest localintegration localrootlessintegration
|
|
|
|
unittest: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
-t --privileged --rm \
|
|
-v /lib/modules:/lib/modules:ro \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
$(RUNC_IMAGE) make localunittest TESTFLAGS=$(TESTFLAGS)
|
|
|
|
localunittest: all
|
|
$(GO) test -timeout 3m -tags "$(BUILDTAGS)" $(TESTFLAGS) -v ./...
|
|
|
|
integration: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
-t --privileged --rm \
|
|
-v /lib/modules:/lib/modules:ro \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
$(RUNC_IMAGE) make localintegration TESTPATH=$(TESTPATH)
|
|
|
|
localintegration: all
|
|
bats -t tests/integration$(TESTPATH)
|
|
|
|
rootlessintegration: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
-t --privileged --rm \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
-e ROOTLESS_TESTPATH \
|
|
$(RUNC_IMAGE) make localrootlessintegration
|
|
|
|
localrootlessintegration: all
|
|
tests/rootless.sh
|
|
|
|
shell: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
-ti --privileged --rm \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
$(RUNC_IMAGE) bash
|
|
|
|
install:
|
|
install -D -m0755 runc $(DESTDIR)$(BINDIR)/runc
|
|
|
|
install-bash:
|
|
install -D -m0644 contrib/completions/bash/runc $(DESTDIR)$(PREFIX)/share/bash-completion/completions/runc
|
|
|
|
install-man: man
|
|
install -d -m 755 $(DESTDIR)$(MANDIR)/man8
|
|
install -D -m 644 man/man8/*.8 $(DESTDIR)$(MANDIR)/man8
|
|
|
|
clean:
|
|
rm -f runc runc-*
|
|
rm -f contrib/cmd/recvtty/recvtty
|
|
rm -rf release
|
|
rm -rf man/man8
|
|
|
|
cfmt: C_SRC=$(shell git ls-files '*.c' | grep -v '^vendor/')
|
|
cfmt:
|
|
indent -linux -l120 -il0 -ppi2 -cp1 -T size_t -T jmp_buf $(C_SRC)
|
|
|
|
shellcheck:
|
|
shellcheck tests/integration/*.bats tests/integration/*.sh tests/integration/*.bash tests/*.sh script/release.sh
|
|
# TODO: add shellcheck for more sh files
|
|
|
|
shfmt:
|
|
shfmt -ln bats -d -w tests/integration/*.bats
|
|
shfmt -ln bash -d -w man/*.sh script/* tests/*.sh tests/integration/*.bash
|
|
|
|
vendor:
|
|
$(GO) mod tidy
|
|
$(GO) mod vendor
|
|
$(GO) mod verify
|
|
|
|
verify-dependencies: vendor
|
|
@test -z "$$(git status --porcelain -- go.mod go.sum vendor/)" \
|
|
|| (echo -e "git status:\n $$(git status -- go.mod go.sum vendor/)\nerror: vendor/, go.mod and/or go.sum not up to date. Run \"make vendor\" to update"; exit 1) \
|
|
&& echo "all vendor files are up to date."
|
|
|
|
cross: runcimage
|
|
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \
|
|
-e BUILDTAGS="$(BUILDTAGS)" --rm \
|
|
-v $(CURDIR):/go/src/$(PROJECT) \
|
|
$(RUNC_IMAGE) make localcross
|
|
|
|
localcross:
|
|
CGO_ENABLED=1 GOARCH=arm GOARM=6 CC=arm-linux-gnueabi-gcc $(GO_BUILD) -o runc-armel .
|
|
CGO_ENABLED=1 GOARCH=arm GOARM=7 CC=arm-linux-gnueabihf-gcc $(GO_BUILD) -o runc-armhf .
|
|
CGO_ENABLED=1 GOARCH=arm64 CC=aarch64-linux-gnu-gcc $(GO_BUILD) -o runc-arm64 .
|
|
CGO_ENABLED=1 GOARCH=ppc64le CC=powerpc64le-linux-gnu-gcc $(GO_BUILD) -o runc-ppc64le .
|
|
|
|
.PHONY: runc all recvtty static release dbuild lint man runcimage \
|
|
test localtest unittest localunittest integration localintegration \
|
|
rootlessintegration localrootlessintegration shell install install-bash \
|
|
install-man clean cfmt shfmt shellcheck \
|
|
vendor verify-dependencies cross localcross
|