summaryrefslogtreecommitdiff
path: root/hack/update-vendor.sh
blob: 97284c8ad340b7a56a904b36ca8636328651b4bf (about) (plain)
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
#!/usr/bin/env bash

###
#Copyright 2019 The KubeEdge Authors.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
###

set -o errexit
set -o nounset
set -o pipefail

# The root of the build/dist directory
KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

# list_staging_repos outputs a sorted list of repos in staging/src/kubeedge
# each entry will just be the $repo portion of staging/src/kubeedge/$repo/...
# $KUBEEDGE_ROOT must be set.
function kubeedge::util::list_staging_repos() {
  (
    cd "${KUBEEDGE_ROOT}/staging/src/github.com/kubeedge/" && \
    find . -mindepth 1 -maxdepth 1 -type d | cut -c 3- | sort
  )
}

# update go.mod and go.sum for staging repos
for repo in $(kubeedge::util::list_staging_repos); do
  pushd "${KUBEEDGE_ROOT}/staging/src/github.com/kubeedge/${repo}"
  echo "running 'go mod tidy' for ${repo}"
  go mod tidy

  # go mod tidy sometimes removes lines that build seems to need. See also https://github.com/golang/go/issues/31248.
  # We would have to always execute go mod vendor after go mod tidy to ensure correctness.
  echo "running 'go mod vendor' for ${repo}"
  go mod vendor

  # vendor/ is not supposed to exist in staging repos, remove it.
  rm -rf vendor/

  popd
done


echo "running 'go mod tidy' for repo root"
go mod tidy

echo "running 'go mod vendor' for repo root"
go mod vendor

# create a symlink in vendor directory pointing to the staging components.
# This lets other packages and tools use the local staging components as if they were vendored.
for repo in $(kubeedge::util::list_staging_repos); do
  rm -fr "${KUBEEDGE_ROOT}/vendor/github.com/kubeedge/${repo}"
  ln -s "../../../staging/src/github.com/kubeedge/${repo}/" "${KUBEEDGE_ROOT}/vendor/github.com/kubeedge/${repo}"
done