Skip to content

Commit 2966b83

Browse files
committed
many: add meson project files
1 parent 7f54f8b commit 2966b83

55 files changed

Lines changed: 1533 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.clang-format-include‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmd/libsnap-confine-private/*
2+
cmd/snap-confine/*
3+
cmd/snap-device-helper/*
4+
cmd/snap-discard-ns/*
5+
cmd/snap-gdb-shim/*
6+
cmd/snap-update-ns/*
7+
cmd/snapd-env-generator/*
8+
cmd/snapd-generator/*
9+
cmd/system-shutdown/*
10+
cmd/snap-cli-wrap/*
11+
cmd/snapd-tool-wrap/*

‎checks/bad_match.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
badMATCH=$(find tests -name 'task.yaml' -print0 -o -name 'spread.yaml' -print0 |
6+
xargs -0 grep -R -n -E 'MATCH +-v' || true)
7+
if [ -n "$badMATCH" ]; then
8+
echo "Potentially incorrect use of MATCH -v at the following locations:" >&2
9+
echo "$badMATCH" >&2
10+
exit 1
11+
fi

‎checks/bad_multiline.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
badmultiline=$(find tests -name 'task.yaml' -print0 -o -name 'spread.yaml' -print0 |
6+
xargs -0 grep -R -n -E '(restore*|prepare*|execute|debug):\s*$' || true)
7+
if [ -n "$badmultiline" ]; then
8+
echo "Incorrect multiline strings at the following locations:" >&2
9+
echo "$badmultiline" >&2
10+
exit 1
11+
fi

‎checks/check_mountinfo_override.sh‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# This check verifies that interfaces that grant access to /proc/self/mountinfo
6+
# (directly or not) also have a prioritized override (see basePrioritizedSnippets
7+
# in interfaces/apparmor/template.go for why this is necessary). We do this
8+
# by looking for a "AddPrioritizedSnippet(*, apparmor.MountInfoKey, ...)" call
9+
# for any such interfaces.
10+
11+
missing_override=""
12+
13+
for f in interfaces/builtin/*.go; do
14+
if [[ "$f" == *"_test.go" ]]; then
15+
continue
16+
fi
17+
18+
out=$(awk '
19+
# if a prioritized override is present, we can stop early
20+
/AddPrioritizedSnippet\(.* apparmor\.MountInfoKey/ { m=""; exit }
21+
22+
# We look for the following types of rules:
23+
# * Explicit mountinfo rules. For example, any combination of:
24+
# owner /proc/self/mountinfo r,
25+
# @{PROC}/@{pid} rw,
26+
# /proc/1234/mountinfo
27+
# * References to the "mountInfoSnippet" variable which contains
28+
# the same rules as the previous item
29+
# * Broad /proc grants:
30+
# owner @{PROC}/** r,
31+
# /proc/** rw,
32+
# * Relevant "allow" rules:
33+
# allow file
34+
# allow all
35+
36+
/^[[:space:]]*(owner[[:space:]]+)?(\/proc|@\{PROC\})\/(self|@\{pid\}|[0-9]+)\/mountinfo[[:space:]][a-z]*r[a-z]*,/ ||
37+
/^[[:space:]]*(owner[[:space:]]+)?(\/proc|@\{PROC\})\/\*\*[[:space:]][a-z]*r[a-z]*,/ ||
38+
/^[[:space:]]*allow[[:space:]]+(file|all),[[:space:]]*$/ ||
39+
/mountInfoSnippet/ { m = m " " NR ":" $0 ORS }
40+
END { if (m != "") printf " - %s:\n%s", FILENAME, m }
41+
' "$f")
42+
[ -n "$out" ] && missing_override+="${out}"$'\n'
43+
done
44+
45+
if [ -n "$missing_override" ]; then
46+
echo "" >&2
47+
echo "These interfaces allow access to /proc/*/mountinfo (specifically or not)" >&2
48+
echo "without adding the allow rule as a prioritized snippet" >&2
49+
echo "(see basePrioritizedSnippets in interfaces/apparmor/template.go):" >&2
50+
printf "%s" "$missing_override" >&2
51+
exit 1
52+
fi

‎checks/equals.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
if got=$(grep -n -R -E "(\!=|==|Equals,) (state\.)?ErrNoState" --include=*.go); then
6+
echo "Don't use equality checks with ErrNoState, use errors.Is() instead" >&2
7+
echo "$got" >&2
8+
exit 1
9+
fi

‎checks/forbidden_cmd_go_deps.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
forbidden_deps=(
6+
"github.com/snapcore/snapd/testutil"
7+
"gopkg.in/check.v1"
8+
)
9+
go_list_cmd=(go list)
10+
11+
if [ -n "${GO_BUILD_TAGS:-}" ]; then
12+
go_list_cmd+=(-tags "$GO_BUILD_TAGS")
13+
fi
14+
15+
cmd_mains=$("${go_list_cmd[@]}" -f '{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./cmd/...)
16+
17+
violations=()
18+
19+
for cmd_main in $cmd_mains; do
20+
deps=$("${go_list_cmd[@]}" -deps "$cmd_main")
21+
22+
for dep in "${forbidden_deps[@]}"; do
23+
if grep -qx "$dep" <<<"$deps"; then
24+
violations+=("$cmd_main -> $dep")
25+
fi
26+
done
27+
done
28+
29+
if [ ${#violations[@]} -gt 0 ]; then
30+
echo "Go binaries must not depend on forbidden packages:" >&2
31+
for dep in "${forbidden_deps[@]}"; do
32+
echo " - $dep" >&2
33+
done
34+
echo "Violations:" >&2
35+
for violation in "${violations[@]}"; do
36+
echo " - $violation" >&2
37+
done
38+
exit 1
39+
fi

‎checks/gofmt.sh‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
fmt=""
6+
7+
for dir in $(go list -f '{{.Dir}}' ./...); do
8+
s="$(gofmt -s -d "$dir" || true)"
9+
if [ -n "$s" ]; then
10+
fmt="$s\\n$fmt"
11+
fi
12+
done
13+
14+
if [ -n "$fmt" ]; then
15+
echo "Formatting wrong in following files:"
16+
# shellcheck disable=SC2001
17+
echo "$fmt" | sed -e 's/\\n/\n/g'
18+
exit 1
19+
fi

‎checks/gopath.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
regexp='GOPATH(?!%%:\*)(?!:)[^= ]*/'
6+
if grep -qPr --exclude HACKING.md --exclude 'Makefile.*' --exclude '*.qcow2' --exclude-dir .git --exclude-dir vendor "$regexp"; then
7+
echo "Using GOPATH as if it were a single entry and not a list:" >&2
8+
grep -PHrn -C1 --color=auto --exclude HACKING.md --exclude 'Makefile.*' --exclude '*.qcow2' --exclude-dir .git --exclude-dir vendor "$regexp"
9+
echo "Use GOHOME, or {GOPATH%%:*}, instead." >&2
10+
exit 1
11+
fi

‎checks/http_status.sh‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
got=""
6+
for dir in $(go list -f '{{.Dir}}' ./...); do
7+
s="$(grep -nP 'http\.Status(?!Text)' "$dir"/*.go || true)"
8+
if [ -n "$s" ]; then
9+
got="$s\\n$got"
10+
fi
11+
done
12+
13+
if [ -n "$got" ]; then
14+
echo 'Usages of http.Status*, we prefer the numeric values directly:' >&2
15+
echo "$got" >&2
16+
exit 1
17+
fi

‎checks/ioutil.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
got=""
6+
for dir in $(go list -f '{{.Dir}}' ./...); do
7+
# shellcheck disable=SC2063
8+
s="$(grep -nP io/ioutil "$dir"/*.go || true)"
9+
if [ -n "$s" ]; then
10+
got="$s\\n$got"
11+
fi
12+
done
13+
14+
if [ -n "$got" ]; then
15+
echo 'Found usages of deprecated io/ioutil, please use "io" or "os" equivalents' >&2
16+
echo "$got" >&2
17+
exit 1
18+
fi

0 commit comments

Comments
 (0)