Skip to content

Commit

Permalink
make run-checks --static pass again w/shellcheck installed
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaca committed Sep 30, 2018
1 parent e655fbb commit 3c41ea1
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 51 deletions.
12 changes: 6 additions & 6 deletions get-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions mkauthors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
41 changes: 20 additions & 21 deletions packaging/arch/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions run-checks
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/nested.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/pkgdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/prepare-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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(){
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/lib/snaps/snap-hooks/meta/hooks/remove
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion tests/main/lxd/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3c41ea1

Please sign in to comment.