aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/work/build.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-10-22 11:30:20 -0400
committerJay Conrod <jayconrod@google.com>2019-10-24 20:15:50 +0000
commitc357b363cf1027afe3296e973ea6f6613cc757ad (patch)
tree089677a31fcbabaccf4e5c6172c103529a0b0975 /src/cmd/go/internal/work/build.go
parentc4c37547b12f113d07b987881a81c1dbc754cd66 (diff)
downloadgo-c357b363cf1027afe3296e973ea6f6613cc757ad.tar.gz
go-c357b363cf1027afe3296e973ea6f6613cc757ad.zip
cmd/go: add -modfile flag that sets go.mod file to read/write
This change adds the -modfile flag to module aware build commands and to 'go mod' subcommands. -modfile may be set to a path to an alternate go.mod file to be read and written. A real go.mod file must still exist and is used to set the module root directory. However, it is not opened. When -modfile is set, the effective location of the go.sum file is also changed to the -modfile with the ".mod" suffix trimmed (if present) and ".sum" added. Updates #34506 Change-Id: I2d1e044e18af55505a4f24bbff09b73bb9c908b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/202564 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/work/build.go')
-rw-r--r--src/cmd/go/internal/work/build.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index d2b4bd3c65..7dd8104683 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -105,6 +105,13 @@ and test commands:
-modcacherw
leave newly-created directories in the module cache read-write
instead of making them read-only.
+ -modfile file
+ in module aware mode, read (and possibly write) an alternate go.mod
+ file instead of the one in the module root directory. A file named
+ "go.mod" must still be present in order to determine the module root
+ directory, but it is not accessed. When -modfile is specified, an
+ alternate go.sum file is also used: its path is derived from the
+ -modfile flag by trimming the ".mod" extension and appending ".sum".
-pkgdir dir
install and load all packages from dir instead of the usual locations.
For example, when building with a non-standard configuration,
@@ -266,6 +273,7 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
// and 'go mod' subcommands.
func AddModCommonFlags(cmd *base.Command) {
cmd.Flag.BoolVar(&cfg.ModCacheRW, "modcacherw", false, "")
+ cmd.Flag.StringVar(&cfg.ModFile, "modfile", "", "")
}
// tagsFlag is the implementation of the -tags flag.