From 660c290bbfb84992e0a7a260caf49780010879a4 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Tue, 23 Jun 2020 16:10:26 -0400 Subject: [PATCH] go1.14: set -mod=mod while rebuilding/linting vendor and building licenses, preserve explicit imports in modules.txt --- hack/lint-dependencies.sh | 4 ++-- hack/update-vendor-licenses.sh | 2 ++ hack/update-vendor.sh | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hack/lint-dependencies.sh b/hack/lint-dependencies.sh index ca8047ebd08..f607f904b60 100755 --- a/hack/lint-dependencies.sh +++ b/hack/lint-dependencies.sh @@ -27,8 +27,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh" # Explicitly opt into go modules, even though we're inside a GOPATH directory export GO111MODULE=on -# Explicitly clear GOFLAGS, since GOFLAGS=-mod=vendor breaks dependency resolution while rebuilding vendor -export GOFLAGS= +# Explicitly set GOFLAGS to ignore vendor, since GOFLAGS=-mod=vendor breaks dependency resolution while rebuilding vendor +export GOFLAGS=-mod=mod # Detect problematic GOPROXY settings that prevent lookup of dependencies if [[ "${GOPROXY:-}" == "off" ]]; then kube::log::error "Cannot run with \$GOPROXY=off" diff --git a/hack/update-vendor-licenses.sh b/hack/update-vendor-licenses.sh index 45567512380..50f40ae6878 100755 --- a/hack/update-vendor-licenses.sh +++ b/hack/update-vendor-licenses.sh @@ -134,7 +134,9 @@ process_content () { # MAIN ############################################################################# +# use modules, and use module info rather than the vendor dir for computing dependencies export GO111MODULE=on +export GOFLAGS=-mod=mod # Check bash version if (( BASH_VERSINFO[0] < 4 )); then diff --git a/hack/update-vendor.sh b/hack/update-vendor.sh index ae04558109c..ef2c0c47de3 100755 --- a/hack/update-vendor.sh +++ b/hack/update-vendor.sh @@ -23,8 +23,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh" # Explicitly opt into go modules, even though we're inside a GOPATH directory export GO111MODULE=on -# Explicitly clear GOFLAGS, since GOFLAGS=-mod=vendor breaks dependency resolution while rebuilding vendor -export GOFLAGS= +# Explicitly set GOFLAGS to ignore vendor, since GOFLAGS=-mod=vendor breaks dependency resolution while rebuilding vendor +export GOFLAGS=-mod=mod # Ensure sort order doesn't depend on locale export LANG=C export LC_ALL=C @@ -327,8 +327,16 @@ go mod vendor >>"${LOG_FILE}" 2>&1 # sort recorded packages for a given vendored dependency in modules.txt. # `go mod vendor` outputs in imported order, which means slight go changes (or different platforms) can result in a differently ordered modules.txt. -# scan | prefix comment lines with the module name | sort field 1 | strip leading text on comment lines -awk '{if($1=="#") print $2 " " $0; else print}' < vendor/modules.txt | sort -k1,1 -s | sed 's/.*#/#/' > "${TMP_DIR}/modules.txt.tmp" +# 1. prefix '#' lines with the module name and capture the module name +# 2. prefix '##' with the most recently captured module name +# 3. output other lines as-is +# sort lines +# strip anything before '#' +awk '{ + if($1=="#") { current_module=$2; print $2 " " $0; } + else if($1=="##") { print current_module " " $0; } + else { print } +}' < vendor/modules.txt | sort -k1,1 -s | sed 's/[^#]*#/#/' > "${TMP_DIR}/modules.txt.tmp" mv "${TMP_DIR}/modules.txt.tmp" vendor/modules.txt # create a symlink in vendor directory pointing to the staging components.