Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go build either looks for go.mod in the directory specified by -C or doesn't depending on where -C appears relative to -gcflags #60392

Closed
aarzilli opened this issue May 24, 2023 · 3 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@aarzilli
Copy link
Contributor

aarzilli commented May 24, 2023

$ go version
go version devel go1.21-40bdc56180 Tue May 23 13:22:25 2023 +0000 linux/amd64

but also reproduces with 1.20. Reproducer:

$ mkdir example
$ cd example
$ go mod init example
$ cat - > main.go
package main
func main() { println("hello world") }
^D
$ cd ..
$ go build -C example -gcflags=""
(succeeds)
$ go build -gcflags="" -C example
go: go.mod file not found in current directory or any parent directory; see 'go help modules'

Originally reported at go-delve/delve#3380 (comment)

@aarzilli
Copy link
Contributor Author

cc @bcmills

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels May 29, 2023
@seankhliao
Copy link
Member

both -C and the build flags are processed as they are set, doesn't seem like an easy fix

flags.Func("C", "AddChdirFlag", os.Chdir)

cmd.Flag.Var(&load.BuildGcflags, "gcflags", "")

return f.set(v, base.Cwd())

@bcmills
Copy link
Contributor

bcmills commented Jan 23, 2024

The documentation for go build currently states:

If used, [the -C] flag must be the first one in the command line.

That restriction was added in https://go.dev/cl/500915 for #57001.

Closing as probably fixed, but please let us know if you can still reproduce similar problems using Go 1.21 or higher.

@bcmills bcmills closed this as completed Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants