--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/31160B8D-8DBC-43C7-8396-F74B2B8AFD92%40newclarity.net.
On Aug 30, 2024, at 2:43 AM, Axel Wagner <axel.wa...@googlemail.com> wrote:I don't think that error message comes from gofmt. As far as I am aware, gofmt only parses source code, it does not even do type-checking.
FWIW you might be interested in https://github.com/golang/go/issues/48429, which gives a less hacky way to track tool dependencies and which (as far as I know) has been accepted and is being implemented, with some delays due to team changes. So, for the concrete issue, a solution is already being worked on.
On Aug 30, 2024, at 9:14 AM, peterGo <go.pe...@gmail.com> wrote:
Let's use official Go sources.
go/src/cmd/tools/tools.go:
Indent the tools.go import statement by a tab to force a reformat.
$ go fmt
tools.go
$
Attempt to build package tools.
$ go build
package cmd/tools: build constraints exclude all Go files in /home/peter/go/src/cmd/tools
$ go build -tags=tools
tools.go:11:8: import "golang.org/x/tools/cmd/bisect" is a program, not an importable package
$
Looks like a go build generated error.
Hi Alex & Peter,Thank you both for your replies.On Aug 30, 2024, at 2:43 AM, Axel Wagner <axel.wa...@googlemail.com> wrote:I don't think that error message comes from gofmt. As far as I am aware, gofmt only parses source code, it does not even do type-checking.As you sure about that? Running this:go fmt ./tools.goGenerates this error for me using go1.23.0 (vs. go1.22.x):tools.go:9:2: import "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen" is a program, not an importable package
FWIW you might be interested in https://github.com/golang/go/issues/48429, which gives a less hacky way to track tool dependencies and which (as far as I know) has been accepted and is being implemented, with some delays due to team changes. So, for the concrete issue, a solution is already being worked on.Thank you for that link. I will look into that for longer term.Shorter term, though it would be nice to find a way to resolve this.
On Aug 31, 2024, at 9:45 AM, Axel Wagner <axel.wa...@googlemail.com> wrote:On Sat, 31 Aug 2024 at 14:22, Mike Schinkel <mi...@newclarity.net> wrote:Hi Alex & Peter,Thank you both for your replies.On Aug 30, 2024, at 2:43 AM, Axel Wagner <axel.wa...@googlemail.com> wrote:I don't think that error message comes from gofmt. As far as I am aware, gofmt only parses source code, it does not even do type-checking.As you sure about that? Running this:go fmt ./tools.goGenerates this error for me using go1.23.0 (vs. go1.22.x):tools.go:9:2: import "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen" is a program, not an importable packageYou are right, I can reproduce that. As Jan, I was using `gofmt`, not `go fmt`. That's interesting.It seems the main difference is that `go fmt` accepts packages (and so it actually does have to look at import paths to a degree at least) while `gofmt` accepts files.Good to know. I think it probably shouldn't actually check the imports beyond finding the package you want to format. Perhaps that can be fixed.
Perhaps you can get your editor to run `gofmt` instead of `go fmt`?
I'm sceptical that there will be a shorter-term way to change anything on the Go side - if this ends up being considered an issue to fix, it would only get fixed in Go 1.24 at the earliest. And I would kind of hope that, until then, #48429 is merged.
On Aug 31, 2024, at 12:30 PM, peterGo <go.pe...@gmail.com> wrote:
Mike,
I get the same results for go1.22 and go1.23 as I got for go (devel go1.24).
I indented the src/cmd/tools/tools.go file import statement by a tab to force a reformat.