The original motivation here is to fix #283, which is that if you try to use bindings to bind to a type in the same package as the generated code, we generate a self-import, which Go doesn't allow. Fixing that is easy -- the three lines in imports.go -- once you know the package-path of the generated code. (The test that that all fits together is in integration-tests because that was the easiest place to set up the right situation.)
Determining the package-path is not too much harder: you ask go/packages, which we already use for package_bindings. But once we're doing that, and handling errors, it's kinda silly that we ask you to specify the package your generated code will use, because we have that too, usually. So I rewrote that handling too, making package now rarely necessary (see for example the example config), and warning if it looks wrong. This is the changes in config.go, and is the more substantial non-test change. (I also renamed some of the testdata dirs to be valid package-names, to exercise more of that code, or in the case of find-config, just for consistency.)
I have:
[x] Written a clear PR title and description (above)
The original motivation here is to fix #283, which is that if you try to use
bindings
to bind to a type in the same package as the generated code, we generate a self-import, which Go doesn't allow. Fixing that is easy -- the three lines inimports.go
-- once you know the package-path of the generated code. (The test that that all fits together is in integration-tests because that was the easiest place to set up the right situation.)Determining the package-path is not too much harder: you ask
go/packages
, which we already use forpackage_bindings
. But once we're doing that, and handling errors, it's kinda silly that we ask you to specify the package your generated code will use, because we have that too, usually. So I rewrote that handling too, makingpackage
now rarely necessary (see for example theexample
config), and warning if it looks wrong. This is the changes inconfig.go
, and is the more substantial non-test change. (I also renamed some of the testdata dirs to be valid package-names, to exercise more of that code, or in the case offind-config
, just for consistency.)I have: