• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2020 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# Sets up cipd packages for presubmit scripts.
8#
9# Scripts should set the script_dir variable and source this file:
10#
11#   readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
12#   source "${script_dir}/setup_cipd.sh"
13#
14# Upon completion of this script the $PATH has been adjusted and other
15# environment variables, such as $CIPD_ROOT, also exist for finer grained
16# control.
17
18if [[ -z "${script_dir}" ]]; then
19     echo "The script_dir variable must be set when setup_cipd.sh is called."
20     exit 1
21fi
22
23# Check if you're in a git checkout. If you're not, you're very likely in a cog
24# and should place cipd outside the current working dir.
25# TODO(engeg): Clean up the created tmp directory.
26set +e
27
28if ! git status &>/dev/null; then
29     echo "Not within a git repo, setting CIPD_ROOT to a temp dir."
30     CIPD_ROOT=$(mktemp -d)
31     readonly CIPD_ROOT
32else
33     CIPD_ROOT="${script_dir}/.cipd_bin"
34     readonly CIPD_ROOT
35fi
36set -e
37
38# Versions of packages to get from CIPD.
39readonly CIPD_PROTOC_VERSION='3.17.1'
40readonly CIPD_BUF_VERSION='0.46.0'
41
42GOBIN="${script_dir}/.go_bin"
43cipd ensure \
44     -log-level warning \
45     -root "${CIPD_ROOT}" \
46     -ensure-file - \
47     <<ENSURE_FILE
48fuchsia/third_party/jq/\${platform} latest
49infra/3pp/tools/protoc/\${platform} version:2@${CIPD_PROTOC_VERSION}
50infra/3pp/tools/go/\${platform} latest
51infra/3pp/go/github.com/bufbuild/buf/\${platform} version:2@${CIPD_BUF_VERSION}
52infra/3pp/go/github.com/protocolbuffers/protoc-gen-go/\${platform} protoc
53infra/3pp/go/github.com/grpc/protoc-gen-go-grpc/\${platform} protoc
54ENSURE_FILE
55
56PATH="${GOBIN}:${PATH}"
57PATH="${CIPD_ROOT}/bin:${CIPD_ROOT}:${PATH}"
58