Skip to content

Commit 278ac25

Browse files
authored
Merge pull request #6039 from thaJeztah/gomod_symlink
scripts/with-go-mod.sh: use symlink instead of -modfile
2 parents 54f3309 + deacdc6 commit 278ac25

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

scripts/docs/generate-man.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if ! command -v "$GO_MD2MAN" > /dev/null; then
88
(
99
set -x
1010
# note: this installs all tools defined in go.mod/vendor.mod
11-
GOBIN="$(pwd)/build/tools" go install -mod=vendor -modfile=vendor.mod tool
11+
GOBIN="$(pwd)/build/tools" go install -mod=vendor tool
1212
)
1313
GO_MD2MAN="$(pwd)/build/tools/go-md2man"
1414
fi
1515

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

2222
(

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/go-mod-outdated@v0.8.0'"
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=readonly -u -m -json all | go-mod-outdated -update -direct)
3535
}
3636

3737
case $TYP in

scripts/with-go-mod.sh

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,36 @@
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+
16+
create_symlink() {
17+
local target="$1"
18+
local link="$2"
19+
20+
if [ -e "$link" ]; then
21+
# see https://superuser.com/a/196698
22+
if ! [ "$link" -ef "${ROOTDIR}/${target}" ]; then
23+
echo "$(basename "$0"): WARN: $link exists but is not the expected symlink!" >&2
24+
echo "$(basename "$0"): WARN: Using your version instead of our generated version -- this may misbehave!" >&2
25+
fi
26+
return
27+
fi
28+
2329
set -x
30+
ln -s "$target" "$link"
31+
cleanup_paths+=( "$link" )
32+
}
2433

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

28-
go 1.25.0
29-
EOF
30-
trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
37+
if [ "${#cleanup_paths[@]}" -gt 0 ]; then
38+
trap 'rm -f "${cleanup_paths[@]}"' EXIT
3139
fi
3240

3341
GO111MODULE=on GOTOOLCHAIN=local "$@"

0 commit comments

Comments
 (0)