]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: run go install in workspace mode
authorMichael Matloob <matloob@golang.org>
Mon, 10 Jan 2022 17:58:20 +0000 (12:58 -0500)
committerMichael Matloob <matloob@golang.org>
Thu, 13 Jan 2022 19:35:14 +0000 (19:35 +0000)
It's too confusing to users to run go install in module mode, so run
it in workspace mode instead.

Fixes #50036

Change-Id: Ia99927bd98f54be4c42224a247543892045e3464
Reviewed-on: https://go-review.googlesource.com/c/go/+/377334
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/work/build.go
src/cmd/go/testdata/script/work_install_submodule.txt [new file with mode: 0644]

index 9d0ad27f0dc7b7d284d582ca5450fc44048b780b..9b1acf987d0569eb7ea3a2b9946e3aa27f182b85 100644 (file)
@@ -617,6 +617,7 @@ func runInstall(ctx context.Context, cmd *base.Command, args []string) {
                }
        }
 
+       modload.InitWorkfile()
        BuildInit()
        pkgs := load.PackagesAndErrors(ctx, load.PackageOpts{}, args)
        if cfg.ModulesEnabled && !modload.HasModRoot() {
diff --git a/src/cmd/go/testdata/script/work_install_submodule.txt b/src/cmd/go/testdata/script/work_install_submodule.txt
new file mode 100644 (file)
index 0000000..3d11717
--- /dev/null
@@ -0,0 +1,36 @@
+# This is a regression test for golang.org/issue/50036
+# Don't check sums for other modules in the workspace.
+
+cd m/sub
+go install -n
+
+-- go.work --
+go 1.18
+
+use (
+    ./m
+    ./m/sub
+)
+-- m/go.mod --
+module example.com/m
+
+go 1.18
+
+-- m/m.go --
+package m
+
+func M() {}
+-- m/sub/go.mod --
+module example.com/m/sub
+
+go 1.18
+
+require example.com/m v1.0.0
+-- m/sub/main.go --
+package main
+
+import "example.com/m"
+
+func main() {
+    m.M()
+}