Closed ZekeLu closed 1 year ago
is this worth fixing over using go run -C ./m1 .
?
This issue is forked from this stackoverflow question. I don't use it myself. I don't understand why the OP wants to specify the -modfile
flag yet. I will copy your suggestion there. Thank you!
Update: In fact, it works without the -modfile
flag. Don't need to apply the -C
flag.
What did you expect to see?
It runs the program or displays more friendly error message.
Thanks for the report! I agree that a clearer error message would be good to have here. (CC @matloob)
Change https://go.dev/cl/493315 mentions this issue: cmd/go/internal/modload: reject the -modfile flag in workspace mode
I don't understand why the OP wants to specify the
-modfile
flag yet.
This is clear now. The OP found that one of his module is built with an unexpected third-party module due to the minimal version selection (MVS) in workspace, and he tried to workaround it with the -modfile
flag. Now he understand how MVS works, and there is not need for the -modfile
flag (or anything else) now.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. And reproduce on gotip too.
What operating system and processor architecture are you using (
go env
)?go env
What did you do?
I run
go run
with the-modfile
flag in a workspace:
``` ├── go.work ├── m1 │ ├── go.mod │ └── main.go └── m2 ├── go.mod └── main.go ``` **go.work**: ``` go 1.20 use ( ./m1 ./m2 ) ``` **m1/go.mod**: ``` module example.com/m1 go 1.20 ``` **m1/main.go**: ```go package main import "fmt" func main() { fmt.Println("Hello m1") } ``` **m2/go.mod**: ``` module example.com/m2 go 1.20 ``` **m2/main.go**: ```go package main import "fmt" func main() { fmt.Println("Hello m2") } ```directory structure and files
What did you expect to see?
It runs the program or displays more friendly error message.
What did you see instead?
What's wrong?
https://github.com/golang/go/blob/2fd8c5b2d80809040e348a431ff292efbeb6e82c/src/cmd/go/internal/modload/init.go#L530-L535
When
-modfile
is specified, the funcmodFilePath
ignores the parametermodRoot
and returns the specified mod file stored incfg.ModFile
directly. This is incorrect in workspace mode when there are multiple mod roots (specified by the use directive) because all the mod roots will be resolved to the samego.mod
file.https://github.com/golang/go/blob/2fd8c5b2d80809040e348a431ff292efbeb6e82c/src/cmd/go/internal/modload/init.go#L730-L731
I would like to work on this issue. But I'm not sure what should we do about it. The most simple fix is to prevent the
-modfile
flag in workspace mode. Opinions?