]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: support the -overlay flag for go mod commands
authorMichael Matloob <matloob@golang.org>
Fri, 20 Nov 2020 19:09:03 +0000 (14:09 -0500)
committerMichael Matloob <matloob@golang.org>
Fri, 20 Nov 2020 23:58:48 +0000 (23:58 +0000)
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>
src/cmd/go/internal/base/flag.go
src/cmd/go/internal/work/build.go
src/cmd/go/testdata/script/mod_overlay.txt

index c97c7445200e55620c813aef710cf5ce978d6772..677f8196827f4c8fa18e49964ba2abc75a5861fa 100644 (file)
@@ -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", "", "")
 }
index ca88f0efa1cf6b90c21593c57448159c507487ba..21b2289dff2be567c1cad92ac32e9303d5b9a290 100644 (file)
@@ -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", "", "")
index 35bb30248b09ee5ad83a097665cb6c0d6103fe2c..92e79c725a3faf0d426a4e6773d4564536e8c9c3 100644 (file)
@@ -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