File: run_local.sh

package info (click to toggle)
golang-golang-x-tools 1%3A0.1.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,588 kB
  • sloc: javascript: 2,011; asm: 1,458; sh: 174; yacc: 155; makefile: 21; ansic: 17
file content (96 lines) | stat: -rwxr-xr-x 2,604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash -e

# Copyright 2019 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# Run govim integration tests against a local gopls.

usage() {
  cat <<EOUSAGE
Usage: $0 [--sudo] [--short] [--version (semver|latest)]

Args:
  --sudo     run docker with sudo
  --short    run `go test` with `-short`
  --version  run on the specific tagged Go version (or latest) rather
             than the default branch

Run govim tests against HEAD using local docker.
EOUSAGE
}

SUDO_IF_NEEDED=
TEST_SHORT=
DOCKERFILE=gopls/integration/govim/Dockerfile
GOVIM_REF=main
while [[ $# -gt 0 ]]; do
  case "$1" in
    "-h" | "--help" | "help")
      usage
      exit 0
      ;;
    "--sudo")
      SUDO_IF_NEEDED="sudo "
      shift
      ;;
    "--short")
      TEST_SHORT="-short"
      shift
      ;;
    "--version")
      if [[ -z "$2" ]]; then
        usage
        exit 1
      fi
      GOVIM_REF=$2
      if [[ "${GOVIM_REF}" == "latest" ]]; then
        TMPGOPATH=$(mktemp -d)
        trap "GOPATH=${TMPGOPATH} go clean -modcache && rm -r ${TMPGOPATH}" EXIT
        GOVIM_REF=$(GOPATH=${TMPGOPATH} go mod download -json \
          github.com/govim/govim@latest | jq -r .Version)
      fi
      shift 2
      ;;
    *)
      usage
      exit 1
  esac
done

# Find the tools root, so that this script can be run from any directory.
script_dir=$(dirname "$(readlink -f "$0")")
tools_dir=$(readlink -f "${script_dir}/../../..")

# Build gopls.
cd "${tools_dir}/gopls"
temp_gopls=$(mktemp -p "$PWD")
trap "rm -f \"${temp_gopls}\"" EXIT
# For consistency across environments, use golang docker to build rather than
# the local go command.
${SUDO_IF_NEEDED}docker run --rm -t \
  -v "${tools_dir}:/src/tools" \
  -w "/src/tools/gopls" \
  golang:latest \
  go build -o $(basename ${temp_gopls})

# Build the test harness. Here we are careful to pass in a very limited build
# context so as to optimize caching.
echo "Checking out govim@${GOVIM_REF}"
cd "${tools_dir}"
${SUDO_IF_NEEDED}docker build \
  --build-arg GOVIM_REF="${GOVIM_REF}" \
  -t gopls-govim-harness:${GOVIM_REF} \
  -f gopls/integration/govim/Dockerfile \
  gopls/integration/govim

# Run govim integration tests.
echo "running govim integration tests using ${temp_gopls}"
temp_gopls_name=$(basename "${temp_gopls}")
${SUDO_IF_NEEDED}docker run --rm -t \
  -v "${tools_dir}:/src/tools" \
  -w "/src/govim" \
  --ulimit memlock=-1:-1 \
  gopls-govim-harness:${GOVIM_REF} \
  go test ${TEST_SHORT} ./cmd/govim \
    -gopls "/src/tools/gopls/${temp_gopls_name}"