From 3c41ea1e57eeaab27ee9ceb1e13fc4d36ab2ea69 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Sun, 30 Sep 2018 13:02:09 +0100 Subject: [PATCH] make run-checks --static pass again w/shellcheck installed --- get-deps.sh | 12 +++--- mkauthors.sh | 14 +++---- packaging/arch/PKGBUILD | 41 +++++++++---------- run-checks | 7 ++-- tests/lib/files.sh | 4 +- tests/lib/nested.sh | 2 +- tests/lib/pkgdb.sh | 2 +- tests/lib/prepare-restore.sh | 8 ++-- tests/lib/reset.sh | 2 +- .../meta/hooks/unprepare-plug-consumer | 2 +- tests/lib/snaps/snap-hooks/meta/hooks/remove | 2 +- tests/main/lxd/task.yaml | 2 +- 12 files changed, 47 insertions(+), 51 deletions(-) diff --git a/get-deps.sh b/get-deps.sh index 1019a32daa5..d9f1ad58081 100755 --- a/get-deps.sh +++ b/get-deps.sh @@ -3,14 +3,14 @@ set -e if [ "$GOPATH" = "" ]; then - GOPATH=$(mktemp -d) - export GOPATH + tmpdir=$(mktemp -d) + export GOPATH=$tmpdir # shellcheck disable=SC2064 - trap "rm -rf $GOPATH" EXIT + trap "rm -rf $tmpdir" EXIT - mkdir -p "$GOPATH/src/github.com/snapcore/" - ln -s "$(pwd)" "$GOPATH/src/github.com/snapcore/snapd" - cd "$GOPATH/src/github.com/snapcore/snapd" + mkdir -p "$tmpdir/src/github.com/snapcore/" + ln -s "$(pwd)" "$tmpdir/src/github.com/snapcore/snapd" + cd "$tmpdir/src/github.com/snapcore/snapd" fi if ! command -v govendor >/dev/null;then diff --git a/mkauthors.sh b/mkauthors.sh index 0e6ab79770b..8089a63be5a 100755 --- a/mkauthors.sh +++ b/mkauthors.sh @@ -11,14 +11,10 @@ set -e #echo "mkauthors.sh run from: $0" #echo "pwd: $(pwd)" -# we have two directories we need to care about: -# - our toplevel pkg builddir which is where "mkauthors.sh" is located -# and where "snap-confine" expects its cmd/VERSION file -# - the GO_GENERATE_BUILDDIR which may be the toplevel pkg dir. but -# during "dpkg-buildpackage" it will become a different _build/ dir -# that dh-golang creates and that only contains a subset of the -# files of the toplevel buildir. -PKG_BUILDDIR=$(dirname "$0") +# GO_GENERATE_BUILDDIR may be the toplevel pkg dir, but during +# "dpkg-buildpackage" it will become a different _build/ dir that +# dh-golang creates and that only contains a subset of the files of +# the toplevel buildir. GO_GENERATE_BUILDDIR="$(pwd)" # run from "go generate" adjust path @@ -53,4 +49,4 @@ func init() { } EOF -go fmt $GO_GENERATE_BUILDDIR/cmd/snap/cmd_blame_generated.go >/dev/null +go fmt "$GO_GENERATE_BUILDDIR/cmd/snap/cmd_blame_generated.go" >/dev/null diff --git a/packaging/arch/PKGBUILD b/packaging/arch/PKGBUILD index 064ae74c97d..3f4b9d68f42 100644 --- a/packaging/arch/PKGBUILD +++ b/packaging/arch/PKGBUILD @@ -36,13 +36,12 @@ prepare() { cd "$pkgname" export GOPATH="$srcdir/go" - mkdir -p "$GOPATH" # Have snapd checkout appear in a place suitable for subsequent GOPATH. This # way we don't have to go get it again and it is exactly what the tag/hash # above describes. - mkdir -p "$(dirname "$GOPATH/src/${_gourl}")" - ln --no-target-directory -fs "$srcdir/$pkgname" "$GOPATH/src/${_gourl}" + mkdir -p "$(dirname "$srcdir/go/src/${_gourl}")" + ln --no-target-directory -fs "$srcdir/$pkgname" "$srcdir/go/src/${_gourl}" } build() { @@ -65,20 +64,20 @@ build() { # Use get-deps.sh provided by upstream to fetch go dependencies using the # godeps tool and dependencies.tsv (maintained upstream). - cd "$GOPATH/src/${_gourl}" + cd "$srcdir/go/src/${_gourl}" XDG_CONFIG_HOME="$srcdir" ./get-deps.sh gobuild="go build -x -v -buildmode=pie" gobuild_static="go build -x -v -buildmode=pie -ldflags=-extldflags=-static" # Build/install snap and snapd - $gobuild -o $GOPATH/bin/snap $GOFLAGS "${_gourl}/cmd/snap" - $gobuild -o $GOPATH/bin/snapctl $GOFLAGS "${_gourl}/cmd/snapctl" - $gobuild -o $GOPATH/bin/snapd $GOFLAGS "${_gourl}/cmd/snapd" - $gobuild -o $GOPATH/bin/snap-seccomp $GOFLAGS "${_gourl}/cmd/snap-seccomp" - $gobuild -o $GOPATH/bin/snap-failure $GOFLAGS "${_gourl}/cmd/snap-failure" + $gobuild -o $srcdir/go/bin/snap $GOFLAGS "${_gourl}/cmd/snap" + $gobuild -o $srcdir/go/bin/snapctl $GOFLAGS "${_gourl}/cmd/snapctl" + $gobuild -o $srcdir/go/bin/snapd $GOFLAGS "${_gourl}/cmd/snapd" + $gobuild -o $srcdir/go/bin/snap-seccomp $GOFLAGS "${_gourl}/cmd/snap-seccomp" + $gobuild -o $srcdir/go/bin/snap-failure $GOFLAGS "${_gourl}/cmd/snap-failure" # build snap-exec and snap-update-ns completely static for base snaps - $gobuild_static -o $GOPATH/bin/snap-update-ns $GOFLAGS "${_gourl}/cmd/snap-update-ns" - $gobuild_static -o $GOPATH/bin/snap-exec $GOFLAGS "${_gourl}/cmd/snap-exec" + $gobuild_static -o $srcdir/go/bin/snap-update-ns $GOFLAGS "${_gourl}/cmd/snap-update-ns" + $gobuild_static -o $srcdir/go/bin/snap-exec $GOFLAGS "${_gourl}/cmd/snap-exec" # Generate data files such as real systemd units, dbus service, environment # setup helpers out of the available templates @@ -103,7 +102,7 @@ build() { check() { export GOPATH="$srcdir/go" - cd "$GOPATH/src/${_gourl}" + cd "$srcdir/go/src/${_gourl}" SKIP_UNCLEAN=1 ./run-checks --unit # XXX: Static checks choke on autotools generated cruft. Let's not run them @@ -140,14 +139,14 @@ package() { "$pkgdir/usr/share/polkit-1/actions/io.snapcraft.snapd.policy" # Install executables - install -Dm755 "$GOPATH/bin/snap" "$pkgdir/usr/bin/snap" - install -Dm755 "$GOPATH/bin/snapd" "$pkgdir/usr/lib/snapd/snapd" - install -Dm755 "$GOPATH/bin/snap-seccomp" "$pkgdir/usr/lib/snapd/snap-seccomp" - install -Dm755 "$GOPATH/bin/snap-failure" "$pkgdir/usr/lib/snapd/snap-failure" - install -Dm755 "$GOPATH/bin/snap-update-ns" "$pkgdir/usr/lib/snapd/snap-update-ns" - install -Dm755 "$GOPATH/bin/snap-exec" "$pkgdir/usr/lib/snapd/snap-exec" + install -Dm755 "$srcdir/go/bin/snap" "$pkgdir/usr/bin/snap" + install -Dm755 "$srcdir/go/bin/snapd" "$pkgdir/usr/lib/snapd/snapd" + install -Dm755 "$srcdir/go/bin/snap-seccomp" "$pkgdir/usr/lib/snapd/snap-seccomp" + install -Dm755 "$srcdir/go/bin/snap-failure" "$pkgdir/usr/lib/snapd/snap-failure" + install -Dm755 "$srcdir/go/bin/snap-update-ns" "$pkgdir/usr/lib/snapd/snap-update-ns" + install -Dm755 "$srcdir/go/bin/snap-exec" "$pkgdir/usr/lib/snapd/snap-exec" # Ensure /usr/bin/snapctl is a symlink to /usr/libexec/snapd/snapctl - install -Dm755 "$GOPATH/bin/snapctl" "$pkgdir/usr/lib/snapd/snapctl" + install -Dm755 "$srcdir/go/bin/snapctl" "$pkgdir/usr/lib/snapd/snapctl" ln -s ../lib/snapd/snapctl "$pkgdir/usr/bin/snapctl" # pre-create directories @@ -174,10 +173,10 @@ package() { # Install man file mkdir -p "$pkgdir/usr/share/man/man1" - "$GOPATH/bin/snap" help --man > "$pkgdir/usr/share/man/man1/snap.1" + "$srcdir/go/bin/snap" help --man > "$pkgdir/usr/share/man/man1/snap.1" # Install the "info" data file with snapd version - install -m 644 -D "$GOPATH/src/${_gourl}/data/info" \ + install -m 644 -D "$srcdir/go/src/${_gourl}/data/info" \ "$pkgdir/usr/lib/snapd/info" # Remove snappy core specific units diff --git a/run-checks b/run-checks index d2c11230600..bcf5238eb3c 100755 --- a/run-checks +++ b/run-checks @@ -133,7 +133,7 @@ if [ "$STATIC" = 1 ]; then echo Checking formatting fmt="" for dir in $(go list -f '{{.Dir}}' ./... | grep -v '/vendor/' ); do - s="$(gofmt -s -l "$dir")" + s="$(gofmt -s -l "$dir" | grep -v /vendor/ || true)" if [ -n "$s" ]; then fmt="$s\\n$fmt" fi @@ -170,11 +170,12 @@ if [ "$STATIC" = 1 ]; then find . \( -name .git -o -name vendor \) -prune -o -print0 ) | xargs -0 file -N | awk -F": " '$2~/shell.script/{print $1}' | - xargs shellcheck + xargs --verbose shellcheck regexp='GOPATH(?!%%:\*)(?!:)[^=]*/' - if grep -qPr --exclude HACKING.md --exclude-dir .git --exclude-dir vendor "$regexp"; then + if grep -qPr --exclude HACKING.md --exclude 'Makefile.*' --exclude-dir .git --exclude-dir vendor "$regexp"; then echo "Using GOPATH as if it were a single entry and not a list:" grep -PHrn -C1 --color=auto --exclude HACKING.md --exclude-dir .git --exclude-dir vendor "$regexp" + echo "Use GOHOME, or {GOPATH%%:*}, instead." exit 1 fi unset regexp diff --git a/tests/lib/files.sh b/tests/lib/files.sh index 5187695f7aa..888df21e077 100644 --- a/tests/lib/files.sh +++ b/tests/lib/files.sh @@ -56,8 +56,8 @@ ensure_file_exists_backup_real() { mv "$file" "$file.back" fi # ensure the parent dir is available - if [ ! -d "$(dirname $file)" ]; then - mkdir -p "$(dirname $file)" + if [ ! -d "$(dirname "$file")" ]; then + mkdir -p "$(dirname "$file")" fi touch "$file" touch "$file.fake" diff --git a/tests/lib/nested.sh b/tests/lib/nested.sh index 36ada69cd24..83616124ade 100644 --- a/tests/lib/nested.sh +++ b/tests/lib/nested.sh @@ -47,7 +47,7 @@ create_nested_core_vm(){ # create ubuntu-core image EXTRA_SNAPS="" - if [ -d "${PWD}/extra-snaps" ] && [ "$(ls -l ${PWD}/extra-snaps/*.snap | wc -l)" -gt 0 ]; then + if [ -d "${PWD}/extra-snaps" ] && [ "$(find "${PWD}/extra-snaps/" -type f -name "*.snap" | wc -l)" -gt 0 ]; then EXTRA_SNAPS="--extra-snaps ${PWD}/extra-snaps/*.snap" fi /snap/bin/ubuntu-image --image-size 3G "$TESTSLIB/assertions/nested-${NESTED_ARCH}.model" --channel "$CORE_CHANNEL" --output ubuntu-core.img "$EXTRA_SNAPS" diff --git a/tests/lib/pkgdb.sh b/tests/lib/pkgdb.sh index ca3605714e1..6042cb1da5e 100755 --- a/tests/lib/pkgdb.sh +++ b/tests/lib/pkgdb.sh @@ -415,7 +415,7 @@ distro_install_build_snapd(){ ;; fedora-*|amazon-*) # shellcheck disable=SC2125 - packages="${GOHOME}"/snap-confine*.rpm\ "${GOPATH}"/snapd*.rpm + packages="${GOHOME}"/snap-confine*.rpm\ "${GOPATH%%:*}"/snapd*.rpm ;; opensuse-*) # shellcheck disable=SC2125 diff --git a/tests/lib/prepare-restore.sh b/tests/lib/prepare-restore.sh index 0c2c9d29a41..b5f8cd0b93f 100755 --- a/tests/lib/prepare-restore.sh +++ b/tests/lib/prepare-restore.sh @@ -152,10 +152,10 @@ build_rpm() { -ba \ "$packaging_path/snapd.spec" - cp "$rpm_dir"/RPMS/$arch/snap*.rpm "$GOPATH" + cp "$rpm_dir"/RPMS/$arch/snap*.rpm "${GOPATH%%:*}" if [[ "$SPREAD_SYSTEM" = fedora-* ]]; then # On Fedora we have an additional package for SELinux - cp "$rpm_dir"/RPMS/noarch/snap*.rpm "$GOPATH" + cp "$rpm_dir"/RPMS/noarch/snap*.rpm "${GOPATH%%:*}" fi } @@ -198,7 +198,7 @@ build_arch_pkg() { chown -R test:test /tmp/pkg su -l -c "cd /tmp/pkg && WITH_TEST_KEYS=1 makepkg -f --nocheck" test - cp /tmp/pkg/snapd*.pkg.tar.xz "$GOPATH" + cp /tmp/pkg/snapd*.pkg.tar.xz "${GOPATH%%:*}" } download_from_published(){ @@ -342,7 +342,7 @@ prepare_project() { # update vendoring if [ -z "$(command -v govendor)" ]; then - rm -rf "$GOPATH/src/github.com/kardianos/govendor" + rm -rf "${GOPATH%%:*}/src/github.com/kardianos/govendor" go get -u github.com/kardianos/govendor fi quiet govendor sync diff --git a/tests/lib/reset.sh b/tests/lib/reset.sh index f43f4febbfd..fead9623f80 100755 --- a/tests/lib/reset.sh +++ b/tests/lib/reset.sh @@ -112,7 +112,7 @@ reset_all_snap() { systemctl start snapd.service snapd.socket fi if ! echo "$SKIP_REMOVE_SNAPS" | grep -w "$snap"; then - if snap info "$snap" | egrep '^type: +(base|core)'; then + if snap info "$snap" | grep -E '^type: +(base|core)'; then remove_bases="$remove_bases $snap" else snap remove "$snap" diff --git a/tests/lib/snaps/basic-iface-hooks-consumer/meta/hooks/unprepare-plug-consumer b/tests/lib/snaps/basic-iface-hooks-consumer/meta/hooks/unprepare-plug-consumer index fea3578ff2a..114d919b4fc 100755 --- a/tests/lib/snaps/basic-iface-hooks-consumer/meta/hooks/unprepare-plug-consumer +++ b/tests/lib/snaps/basic-iface-hooks-consumer/meta/hooks/unprepare-plug-consumer @@ -2,4 +2,4 @@ # Read own 'before-connect' attribute output=$(snapctl get :consumer before-connect) -echo "$output" > $SNAP_COMMON/unprepare-plug-consumer-done +echo "$output" > "$SNAP_COMMON/unprepare-plug-consumer-done" diff --git a/tests/lib/snaps/snap-hooks/meta/hooks/remove b/tests/lib/snaps/snap-hooks/meta/hooks/remove index 2b3af258864..540a0a0a7a5 100755 --- a/tests/lib/snaps/snap-hooks/meta/hooks/remove +++ b/tests/lib/snaps/snap-hooks/meta/hooks/remove @@ -1,5 +1,5 @@ #!/bin/sh RETVAL=$(snapctl get exitcode) -echo "$RETVAL" > $SNAP_USER_COMMON/remove-hook-executed +echo "$RETVAL" > "$SNAP_USER_COMMON/remove-hook-executed" exit "$RETVAL" diff --git a/tests/main/lxd/task.yaml b/tests/main/lxd/task.yaml index 8a0cc9a1149..357aa0aa141 100644 --- a/tests/main/lxd/task.yaml +++ b/tests/main/lxd/task.yaml @@ -72,7 +72,7 @@ execute: | echo "Install snapd" lxd.lxc exec my-ubuntu -- mkdir -p "$GOHOME" - lxd.lxc file push "$GOHOME"/snapd_*.deb "my-ubuntu/$GOPATH/" + lxd.lxc file push "$GOHOME"/snapd_*.deb "my-ubuntu/$GOHOME/" lxd.lxc exec my-ubuntu -- apt install -y "$GOHOME"/snapd_*.deb echo "Setting up proxy *inside* the container"