mirror of
https://github.com/golang/go
synced 2024-11-26 08:58:09 -07:00
cmd/go: support the -overlay flag for go mod commands
Move the declaration of the -overlay flag to base.AddModCommonFlags, where other flags that are needed for go mod commands and for builds are declared. The flag's already initialized in modload.Init so there's no additional work needed to be done to support it in the go mod commands. For #39958 Change-Id: I70725d620cc69cb820f6ed923d626f4fe041b1c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/272126 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
c47eac7db0
commit
78e59bb1f7
@ -8,6 +8,7 @@ import (
|
||||
"flag"
|
||||
|
||||
"cmd/go/internal/cfg"
|
||||
"cmd/go/internal/fsys"
|
||||
"cmd/go/internal/str"
|
||||
)
|
||||
|
||||
@ -66,4 +67,5 @@ func AddModFlag(flags *flag.FlagSet) {
|
||||
func AddModCommonFlags(flags *flag.FlagSet) {
|
||||
flags.BoolVar(&cfg.ModCacheRW, "modcacherw", false, "")
|
||||
flags.StringVar(&cfg.ModFile, "modfile", "", "")
|
||||
flags.StringVar(&fsys.OverlayFile, "overlay", "", "")
|
||||
}
|
||||
|
@ -267,6 +267,11 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
|
||||
}
|
||||
if mask&OmitModCommonFlags == 0 {
|
||||
base.AddModCommonFlags(&cmd.Flag)
|
||||
} else {
|
||||
// Add the overlay flag even when we don't add the rest of the mod common flags.
|
||||
// This only affects 'go get' in GOPATH mode, but add the flag anyway for
|
||||
// consistency.
|
||||
cmd.Flag.StringVar(&fsys.OverlayFile, "overlay", "", "")
|
||||
}
|
||||
cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
|
||||
cmd.Flag.Var(&load.BuildLdflags, "ldflags", "")
|
||||
@ -279,8 +284,6 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
|
||||
cmd.Flag.BoolVar(&cfg.BuildTrimpath, "trimpath", false, "")
|
||||
cmd.Flag.BoolVar(&cfg.BuildWork, "work", false, "")
|
||||
|
||||
cmd.Flag.StringVar(&fsys.OverlayFile, "overlay", "", "")
|
||||
|
||||
// Undocumented, unstable debugging flags.
|
||||
cmd.Flag.StringVar(&cfg.DebugActiongraph, "debug-actiongraph", "", "")
|
||||
cmd.Flag.StringVar(&cfg.DebugTrace, "debug-trace", "", "")
|
||||
|
6
src/cmd/go/testdata/script/mod_overlay.txt
vendored
6
src/cmd/go/testdata/script/mod_overlay.txt
vendored
@ -32,7 +32,10 @@ cmp $WORK/overlay/get_doesnt_add_dep_go_mod $WORK/want_go_mod
|
||||
cd $WORK/gopath/src/overlay-sum-used
|
||||
! go get -d .
|
||||
stderr 'SECURITY ERROR'
|
||||
! go mod verify
|
||||
stderr 'SECURITY ERROR'
|
||||
go get -d -overlay overlay.json .
|
||||
go mod verify -overlay overlay.json
|
||||
# Overlaid go.sum is not rewritten.
|
||||
# Copy an incomplete file to the overlay file, and expect an error
|
||||
# attempting to update the file
|
||||
@ -40,6 +43,9 @@ cp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
|
||||
! go get -d -overlay overlay.json .
|
||||
stderr 'overlaid files can''t be opened for write'
|
||||
cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
|
||||
! go mod tidy -overlay overlay.json
|
||||
stderr 'overlaid files can''t be opened for write'
|
||||
cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums
|
||||
|
||||
# -overlay works with -modfile.
|
||||
# There's an empty go.mod file in the directory, and the file alternate.mod is
|
||||
|
Loading…
Reference in New Issue
Block a user