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

Fix go generate ./... issues under root #76

Merged
merged 1 commit into from
Sep 5, 2023
Merged

Conversation

r-hang
Copy link
Contributor

@r-hang r-hang commented Sep 5, 2023

Running go generate ./... on current main fails for a couple of reasons

(1) The go:generate command in /mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go has an -aux_file argument that specifies a package faux that is not in the stdlib and therefore not discoverable in GOROOT. Fixing this with a fully qualified path causes another failure that is known and documented in mockgen/internal/tests/aux_imports_embedded_interface/README.md.

Because this failure is known, I've opted to comment out the command as documentation for reproducing the error.

(2) mockgen/internal/tests/internal_pkg/generate.go attempts to mock an interface package with reflect mode and runs into fundamental go restrictions of go build with internal package paths outside of the internal package scope allowed by go.

I've removed the generate directive here since this isn't a supported feature as the implementation of reflect mode creates a tempoorary directory and invokes go build there.

ref: reflect.go#L135
ref: #29

Not a failure fix but I've also changed type aliases of any back to type aliases of interface {}. Looking at the parsing logic, parse.go#L752 interface{} -> any causes *ast.TypeSpec to no longer type check to an *ast.InterfaceType and ends up removing generate mock code meant to test against regressions.

ref: #48

Running `go generate ./...` on current main fails for a couple of reasons

(1) The go:generate command in /mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go
has an -aux_file argument that specifies a package `faux` that is not in the
stdlib and therefore not discoverable in GOROOT. Fixing this with a fully
qualified path causes another failure that is known and documented
in mockgen/internal/tests/aux_imports_embedded_interface/README.md.

Because this failure is known, I've opted to comment out the command as
documentation for reproducing the error.

(2) mockgen/internal/tests/internal_pkg/generate.go attempts to mock an
interface package with reflect mode and runs into fundamental go
restrictions of `go build` with internal package paths outside of the
internal package scope allowed by go.

I've removed the generate directive here since this isn't a supported feature
as the implementation of reflect mode creates a tempoorary directory and
invokes `go build` there.

ref: github.com/uber-go/mock/blob/8cd1a4cf46a6b1cf232b6862f2f11e81fe77a4e4/mockgen/reflect.go#L135
ref: github.com/golang/mock/issues/29

Not a failure fix but I've also changed type aliases of `any` back to type
aliases of `interface {}`. Looking at the parsing logic, github.com/uber-go/mock/blob/8cd1a4cf46a6b1cf232b6862f2f11e81fe77a4e4/mockgen/parse.go#L752
`interface{}` -> `any` causes *ast.TypeSpec to no longer type check to an *ast.InterfaceType
and ends up removing generate mock code meant to test against regressions.

ref: github.com//pull/48
@r-hang r-hang merged commit 837f20a into main Sep 5, 2023
3 checks passed
@r-hang r-hang deleted the rhang/go-generate-fix branch September 5, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants