moby/hack/with-go-mod.sh
Bjorn Neergaard a449f77774 hack: replace go-mod-prepare.sh with wrapper script
To make the local build environment more correct and consistent, we
should never leave an uncommitted go.mod in the tree; however, we need a
go.mod for certain commands to work properly. Use a wrapper script to
create and destroy the go.mod as needed instead of potentially changing
tooling behavior by leaving it.

If a go.mod already exists, this script will warn and call the wrapped
command with GO111MODULE=on.

Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
2022-12-12 18:39:06 -07:00

31 lines
924 B
Bash
Executable file

#!/usr/bin/env bash
#
# This script is used to coerce certain commands which rely on the presence of
# a go.mod into working with our repository. It works by creating a fake
# go.mod, running a specified command (passed via arguments), and removing it
# when the command is finished. This script should be dropped when this
# repository is a proper Go module with a permanent go.mod.
set -e
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)"
if test -e "${ROOTDIR}/go.mod"; then
{
scriptname=$(basename "$0")
echo "${scriptname}: WARN: go.mod exists in the repository root!"
echo "${scriptname}: WARN: Using your go.mod instead of our generated version -- this may misbehave!"
} >&2
else
set -x
tee "${ROOTDIR}/go.mod" >&2 <<- EOF
module github.com/docker/docker
go 1.18
EOF
trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
fi
GO111MODULE=on "$@"