|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Need to run linter twice to cover all the build tags code paths |
| 3 | +# Run golangci-lint with different sets of build tags. |
4 | 4 | set -e
|
5 | 5 |
|
6 | 6 | # WARNING: This script executes on multiple operating systems that
|
7 | 7 | # do not have the same version of Bash. Specifically, Darwin uses
|
8 | 8 | # a very old version, where modern features (like `declare -A`) are
|
9 | 9 | # absent.
|
10 | 10 |
|
11 |
| -# Makefile calls script with the 'run' argument, but developers may not. |
12 |
| -# Handle both cases transparently. |
13 |
| -[[ $1 == run ]] && shift |
14 |
| - |
15 |
| -BUILD_TAGS_DEFAULT="apparmor,seccomp,selinux" |
16 |
| -BUILD_TAGS_ABI="$BUILD_TAGS_DEFAULT,systemd" |
17 |
| -BUILD_TAGS_TUNNEL="$BUILD_TAGS_DEFAULT,remote" |
18 |
| -BUILD_TAGS_REMOTE="remote,containers_image_openpgp" |
19 |
| - |
20 |
| -SKIP_DIRS_ABI="" |
21 |
| -SKIP_DIRS_TUNNEL="" |
22 |
| -SKIP_DIRS_REMOTE="libpod/events,pkg/machine/qemu,pkg/machine/wsl,test" |
23 |
| - |
24 |
| -declare -a to_lint |
25 |
| -to_lint=(ABI TUNNEL) |
26 |
| - |
27 |
| -# Special-case, for Darwin and Windows only "remote" linting is possible and required. |
28 |
| -if [[ "$GOOS" == "windows" ]] || [[ "$GOOS" == "darwin" ]]; then |
29 |
| - to_lint=(REMOTE) |
| 11 | +echo "Linting for GOOS=$GOOS" |
| 12 | +# Special case: for Darwin and Windows only "remote" linting is possible and required. |
| 13 | +if [[ "$GOOS" == "windows" || "$GOOS" == "darwin" ]]; then |
| 14 | + ( |
| 15 | + set -x |
| 16 | + ./bin/golangci-lint run --build-tags="remote,containers_image_openpgp" "$@" |
| 17 | + ) |
| 18 | + exit 0 |
30 | 19 | fi
|
31 | 20 |
|
32 |
| -for to_lint in "${to_lint[@]}"; do |
33 |
| - tags_var="BUILD_TAGS_${to_lint}" |
34 |
| - skip_var="SKIP_DIRS_${to_lint}" |
35 |
| - echo "" |
36 |
| - echo Running golangci-lint for "$to_lint" |
37 |
| - echo Build Tags "$to_lint": ${!tags_var} |
38 |
| - echo Skipped directories "$to_lint": ${!skip_var} |
| 21 | +# Normal case (Linux): run linter for various sets of build tags. |
| 22 | +TAGS="apparmor,seccomp,selinux" |
| 23 | +for EXTRA_TAGS in "" ",systemd" ",remote"; do |
39 | 24 | (
|
40 | 25 | # Make it really easy for a developer to copy-paste the command-line
|
41 | 26 | # to focus or debug a single, specific linting category.
|
42 | 27 | set -x
|
43 |
| - ./bin/golangci-lint run --timeout=10m --build-tags="${!tags_var}" --exclude-dirs="${!skip_var}" "$@" |
| 28 | + ./bin/golangci-lint run --build-tags="${TAGS}${EXTRA_TAGS}" "$@" |
44 | 29 | )
|
45 | 30 | done
|
0 commit comments