Skip to content

Commit

Permalink
Merge pull request heroku#396 from heroku/go-1-14-no-vendor
Browse files Browse the repository at this point in the history
make `go list` use of -mod=vendor more dynamic
  • Loading branch information
schneems committed Apr 16, 2020
2 parents 9e49fbc + fb22bbe commit 289f452
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add go1.12.17, use for go1.12 and as the default
* Add go1.13.9, use for go1.13
* Add go1.14.1, use for go1.14
* Only pass -mod=vendor to `go list` if a vendor directory is present (#394)

## v138 (2020-03-13)
* Add go1.13.8
Expand Down
45 changes: 25 additions & 20 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -385,25 +385,13 @@ loadEnvDir "${env_dir}"
setGitCredHelper "${env_dir}"
trap clearGitCredHelper INT TERM EXIT

FLAGS=(-tags heroku)

determineTool

ver=$(expandVer $ver)

if [ -e "${build}/bin" -a ! -d "${build}/bin" ]; then
err ""
err "File bin exists and is not a directory."
err ""
exit 1
fi

reportVer "${ver}"

ensureGo "${ver}"

mkdir -p "${build}/bin"

# If $GO_LINKER_SYMBOL and GO_LINKER_VALUE are set, tell the linker to DTRT
FLAGS=(-tags heroku)
if [ -n "${GO_LINKER_SYMBOL}" -a -n "${GO_LINKER_VALUE}" ]; then
case "${ver}" in
go1|go1.0.*|go1.1|go1.1.*|go1.2|go1.2.*|go1.3|go1.3.*|go1.4|go1.4.*)
Expand All @@ -416,14 +404,27 @@ if [ -n "${GO_LINKER_SYMBOL}" -a -n "${GO_LINKER_VALUE}" ]; then
FLAGS+=(-ldflags "-X ${xval}")
fi

if [ -e "${build}/bin" -a ! -d "${build}/bin" ]; then
err ""
err "File bin exists and is not a directory."
err ""
exit 1
fi

reportVer "${ver}"

ensureGo "${ver}"

mkdir -p "${build}/bin"

export GOPATH

# GB installation
mcount "pkgmanagement.$TOOL"

mainPackagesInModule() {
# For an explanation of what this is doing, see https://dave.cheney.net/2014/09/14/go-list-your-swiss-army-knife
go list -find -mod=vendor -f '{{ if eq .Name "main" }} {{.ImportPath}} {{ end }}' ./...
go list -find "${FLAGS[@]}" -f '{{ if eq .Name "main" }} {{.ImportPath}} {{ end }}' ./... 2>/dev/null
}

setupProcfile() {
Expand Down Expand Up @@ -463,6 +464,15 @@ setupProcfile() {
case "${TOOL}" in
gomodules)
cd ${build}

# TODO: Check the desired language version (eg `go mod edit -json | jq -r '.Go'`)
# and only do this if it's <1.14. The 1.14 release and beyond handles this automatically
# when the desired language version is 1.14+ and vendoring should be used.
# https://golang.org/doc/go1.14#vendor
if [ -d "${build}/vendor" -a -s "${build}/go.sum" ]; then
FLAGS+=(-mod=vendor)
fi

step "Determining packages to install"
pkgs=${GO_INSTALL_PACKAGE_SPEC:-$(awk '{ if ($1 == "//" && $2 == "+heroku" && $3 == "install" ) { print substr($0, index($0,$4)); exit }}' ${goMOD})}
if [ -z "${pkgs}" ]; then
Expand Down Expand Up @@ -500,10 +510,6 @@ case "${TOOL}" in
handleDefaultPkgSpec
massagePkgSpecForVendor

if [ -d "${build}/vendor" -a -s "${build}/go.sum" ]; then
FLAGS+=(-mod=vendor)
fi

unset GIT_DIR # unset git dir or it will mess with goinstall
export GOBIN="${build}/bin"
if [ "${GO_SETUP_GOPATH_FOR_MODULE_CACHE}" = "true" ]; then
Expand Down Expand Up @@ -707,4 +713,3 @@ echo "TOOL=${TOOL}" > "${t}"
if [ "${TOOL}" != "gb" ]; then
echo "NAME=${name}" >> "${t}"
fi

1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"go1.10.8.linux-amd64.tar.gz",
"go1.11.13.linux-amd64.tar.gz",
"go1.12.17.linux-amd64.tar.gz",
"go1.14.1.linux-amd64.tar.gz",
"go1.4.3.linux-amd64.tar.gz",
"go1.6.4.linux-amd64.tar.gz",
"go1.7.6.linux-amd64.tar.gz",
Expand Down
2 changes: 1 addition & 1 deletion lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,4 @@ determineTool() {
err "https://devcenter.heroku.com/articles/go-support"
exit 1
fi
}
}
1 change: 1 addition & 0 deletions test/fixtures/mod-deps-114/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: fixture
10 changes: 10 additions & 0 deletions test/fixtures/mod-deps-114/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +heroku goVersion 1.14

module github.com/heroku/fixture

go 1.14

require (
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2
)
4 changes: 4 additions & 0 deletions test/fixtures/mod-deps-114/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
11 changes: 11 additions & 0 deletions test/fixtures/mod-deps-114/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"

"github.com/gorilla/mux"
)

func main() {
fmt.Println(mux.ErrNotFound)
}
37 changes: 34 additions & 3 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ testModProcfileCreation() {
fixture "mod-cmd-web"

assertDetected

compile
assertModulesBoilerplateCaptured
assertGoInstallCaptured
Expand Down Expand Up @@ -163,7 +163,7 @@ github.com/heroku/fixture/cmd/other"

assertFile "fixture: bin/fixture
other: bin/other" "Procfile"

assertCapturedSuccess
assertInstalledFixtureBinary
assertCompiledBinaryExists other
Expand Down Expand Up @@ -198,7 +198,7 @@ testModNoVersion() {
assertModulesBoilerplateCaptured
assertGoInstallCaptured
assertGoInstallOnlyFixturePackageCaptured

assertCapturedSuccess
assertInstalledFixtureBinary
}
Expand Down Expand Up @@ -308,6 +308,37 @@ github.com/gorilla/mux
assertInstalledFixtureBinary
}

# Ensure that a project works when:
#
# * no vendor directory is present
# * Go release of 1.14 or greater is used (eg `// +heroku goVersion 1.14` in go.mod)
# * Go language version of 1.14 or greater is used (eg `go 1.14` in go.mod)
#
# The use of language version 1.14 or greater in particular
# activates new consistency checks between go.mod and the vendor
# directory, described at https://golang.org/doc/go1.14#vendor.
testModDeps114() {
fixture "mod-deps-114"

assertDetected

compile
assertModulesBoilerplateCaptured
assertCaptured "Installing go1.14"
assertGoInstallOnlyFixturePackageCaptured

# The other deps are downloaded/installed
assertCaptured "
go: finding github.com/gorilla/mux v1.6.2
go: finding github.com/gorilla/context v1.1.1
go: downloading github.com/gorilla/mux v1.6.2
go: extracting github.com/gorilla/mux v1.6.2
github.com/gorilla/mux
"
assertCapturedSuccess
assertInstalledFixtureBinary
}

testModDepsVendored() {
fixture "mod-deps-vendored"

Expand Down
2 changes: 1 addition & 1 deletion test/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,4 @@ assertGoInstallCaptured() {
local go_ver=${1:-${DEFAULT_GO_VERSION}}
assertCaptured "Installing ${go_ver}
Fetching ${go_ver}.linux-amd64.tar.gz... done"
}
}

0 comments on commit 289f452

Please sign in to comment.