Skip to content

Add canonical import path#36194

Merged
tianon merged 1 commit intomoby:masterfrom
dnephin:add-canonical-import
Feb 7, 2018
Merged

Add canonical import path#36194
tianon merged 1 commit intomoby:masterfrom
dnephin:add-canonical-import

Conversation

@dnephin
Copy link
Copy Markdown
Member

@dnephin dnephin commented Feb 2, 2018

Internally all packages are imported as github.com/docker/docker, so the package statement should document this by using canonical import paths.

go build will report an error when a package is used from a path that doesn't match the canonical path.

@tiborvass
Copy link
Copy Markdown
Contributor

@dnephin need to change the swagger generator?

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Feb 2, 2018

ping @moby/moby-maintainers

@tianon
Copy link
Copy Markdown
Member

tianon commented Feb 2, 2018

It's really verbose to include it in every .go file, but IMO this is a good idea both now and if/when #35361 happens, and should help folks who put it at the wrong place figure out exactly what they need to change things to in order to fix their builds (and not end up with two copies of this repo cloned accidentally, for example).

So, TLDR; +1!

@thaJeztah
Copy link
Copy Markdown
Member

Looks like the files generated by swagger need to be updated;

21:13:27 The result of hack/generate-swagger-api.sh differs
21:13:27 
21:13:27  M api/types/container/container_changes.go
21:13:27  M api/types/container/container_create.go
21:13:27  M api/types/container/container_top.go
21:13:27  M api/types/container/container_update.go
21:13:27  M api/types/container/container_wait.go
21:13:27  M api/types/error_response.go
21:13:27  M api/types/graph_driver_data.go
21:13:27  M api/types/id_response.go
21:13:27  M api/types/image/image_history.go
21:13:27  M api/types/image_delete_response_item.go
21:13:27  M api/types/image_summary.go
21:13:27  M api/types/plugin.go
21:13:27  M api/types/plugin_device.go
21:13:27  M api/types/plugin_env.go
21:13:27  M api/types/plugin_interface_type.go
21:13:27  M api/types/plugin_mount.go
21:13:27  M api/types/port.go
21:13:27  M api/types/service_update_response.go
21:13:27  M api/types/volume.go
21:13:27 
21:13:27 Please update api/swagger.yaml with any api changes, then 
21:13:27 run `hack/generate-swagger-api.sh`.

@thaJeztah
Copy link
Copy Markdown
Member

Oh, never mind, I see @tiborvass already commented that 😊

@AkihiroSuda
Copy link
Copy Markdown
Member

We should not modify pb.go files

@tiborvass
Copy link
Copy Markdown
Contributor

@dnephin I wonder if we really need to add the canonical import path on all files, or whether we could simply put it in the files at the root. Wouldn't that solve the issue of go-getting two copies?

@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Feb 4, 2018

I don't think so. I think if you were to import any package outside the root you'd run into the same problem. I'm not sure if it needs to be in every file, or "at least one file per package", but it seems like it's more obvious if it's in every file.

I'll test some things to confirm.

@dnephin dnephin force-pushed the add-canonical-import branch from 1816082 to 6acf52b Compare February 5, 2018 21:06
@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Feb 5, 2018

Ok, I've reverted the change on generated files (swagger and .pb.go). Let's see if validation is happy now.

I looked at modifying the swagger-gen templates, the problem is getting the relative directory name to use in the canonical import path.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin dnephin force-pushed the add-canonical-import branch from 6acf52b to 4f0d95f Compare February 5, 2018 21:52
@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Feb 6, 2018

This is green

Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦁

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tianon ?

@tianon
Copy link
Copy Markdown
Member

tianon commented Feb 7, 2018

LGTM 👍

@tianon tianon merged commit 3a633a7 into moby:master Feb 7, 2018
@dnephin dnephin deleted the add-canonical-import branch February 7, 2018 21:13
@thaJeztah
Copy link
Copy Markdown
Member

Can we add a validation step in CI that checks if new files that were added have the canonical path set?

@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Feb 7, 2018

yes, I'll look at adding that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants