Skip to content

Commit 634f9d8

Browse files
committed
scripts/with-go-mod.sh: use symlink instead of -modfile
While the "-modfile=vendor.mod" is slightly more correct, using a symlink allows for most of the go tools to work "as usual", just without an acual `go.mod` being committed in the repository. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c80675b commit 634f9d8

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

scripts/docs/generate-man.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ set -eu
77
if ! command -v "$GO_MD2MAN" > /dev/null; then
88
(
99
set -x
10-
go build -mod=vendor -modfile=vendor.mod -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
10+
go build -mod=vendor -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
1111
)
1212
GO_MD2MAN=$(realpath ./build/tools/go-md2man)
1313
fi
1414

1515
mkdir -p man/man1
1616
(
1717
set -x
18-
go run -mod=vendor -modfile=vendor.mod -tags manpages ./man/generate.go --source "./man/src" --target "./man/man1"
18+
go run -mod=vendor -tags manpages ./man/generate.go --source "./man/src" --target "./man/man1"
1919
)
2020

2121
(

scripts/docs/generate-md.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44

55
(
66
set -x
7-
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats md --source "./docs/reference/commandline" --target "./docs/reference/commandline"
7+
go run -mod=vendor -tags docsgen ./docs/generate/generate.go --formats md --source "./docs/reference/commandline" --target "./docs/reference/commandline"
88
)
99

1010
# remove generated help.md file

scripts/docs/generate-yaml.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -eu
44

55
mkdir -p docs/yaml
66
set -x
7-
go run -mod=vendor -modfile=vendor.mod -tags docsgen ./docs/generate/generate.go --formats yaml --source "./docs/reference/commandline" --target "./docs/yaml"
7+
go run -mod=vendor -tags docsgen ./docs/generate/generate.go --formats yaml --source "./docs/reference/commandline" --target "./docs/yaml"

scripts/vendor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ -z "$TYP" ]; then
1414
fi
1515

1616
update() {
17-
(set -x ; go mod tidy -modfile=vendor.mod; go mod vendor -modfile=vendor.mod)
17+
(set -x ; go mod tidy; go mod vendor)
1818
}
1919

2020
validate() {
@@ -31,7 +31,7 @@ outdated() {
3131
echo "go-mod-outdated not found. Install with 'go install github.com/psampaz/[email protected]'"
3232
exit 1
3333
fi
34-
(set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct)
34+
(set -x ; go list -mod=vendor -mod=readonly -u -m -json all | go-mod-outdated -update -direct)
3535
}
3636

3737
case $TYP in

scripts/with-go-mod.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,40 @@
66
# when the command is finished. This script should be dropped when this
77
# repository is a proper Go module with a permanent go.mod.
88

9-
set -e
9+
set -euo pipefail
1010

1111
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1212
ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)"
1313

14-
if test -e "${ROOTDIR}/go.mod"; then
15-
{
16-
scriptname=$(basename "$0")
17-
cat >&2 <<- EOF
18-
$scriptname: WARN: go.mod exists in the repository root!
19-
$scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave!
20-
EOF
21-
} >&2
22-
else
14+
cleanup_paths=""
15+
create_symlink() {
16+
local target="$1"
17+
local link="$2"
18+
19+
pushd "${ROOTDIR}" > /dev/null
20+
trap 'popd > /dev/null' RETURN
21+
22+
if [ -L "$link" ] && [ "$(readlink "$link")" = "$target" ]; then
23+
# symlink already present; we're done
24+
return
25+
fi
26+
27+
if [ -e "$link" ]; then
28+
echo "$(basename "$0"): WARN: $link exists but is not the expected symlink!" >&2
29+
echo "$(basename "$0"): WARN: Using your version instead of our generated version -- this may misbehave!" >&2
30+
return
31+
fi
32+
2333
set -x
34+
ln -s "$target" "$link"
35+
cleanup_paths="$cleanup_paths ${ROOTDIR}/$link"
36+
}
2437

25-
tee "${ROOTDIR}/go.mod" >&2 <<- EOF
26-
module github.com/docker/cli
38+
create_symlink "vendor.mod" "go.mod"
39+
create_symlink "vendor.sum" "go.sum"
2740

28-
go 1.23.0
29-
EOF
30-
trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
41+
if [ -n "$cleanup_paths" ]; then
42+
trap 'rm -f'"$cleanup_paths" EXIT
3143
fi
3244

3345
GO111MODULE=on GOTOOLCHAIN=local "$@"

0 commit comments

Comments
 (0)