Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 611448 - golang-vcs.eclass, golang-vcs-snapshot.eclass: incorrect use of $EGO_PN
Summary: golang-vcs.eclass, golang-vcs-snapshot.eclass: incorrect use of $EGO_PN
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-03 04:39 UTC by Alex Efros
Modified: 2017-04-12 17:43 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Efros 2017-03-03 04:39:57 UTC
These eclasses handle EGO_PN as synonym for repo path with optionally appended "/...", but this is incorrect: both golang-base.eclass and golang-build.eclass define EGO_PN as "the import path for the go package(s) to build". Moreover, example in golang-vcs.eclass shows usage of multiple import paths in EGO_PN (which is correct and should be supported), but later in code it uses ${EGO_PN%/...} which won't work correctly in this case.

Repo may contains a lot of go packages, and sometimes we need to build/install only few of them, like "github.com/user/project/cmd/smallapp" or "github.com/user/project/cmd/...". If we'll have to always use "github.com/user/project/..." then this may result in fetching a lot of unneeded dependencies and building a lot of unneeded packages.

To fix these issues we should remove ${EGO_PN%/...} everywhere and add separate variable for "repo" itself. `go get` automatically discover repo url from import path, but this is complicated process which involved downloading from network and I'm not sure it's good idea to do the same while emerging package. So, best way is probably to add one more global variable like EGO_REPO:

  EGO_REPO="github.com/user/project"
  EGO_PN="${EGO_REPO}/cmd/one ${EGO_REPO}/cmd/two"

and then use ${EGO_REPO} instead of ${EGO_PN%/...} everywhere.
Comment 1 William Hubbs gentoo-dev 2017-04-12 16:44:44 UTC
(In reply to Alex Efros from comment #0)
> These eclasses handle EGO_PN as synonym for repo path with optionally
> appended "/...", but this is incorrect: both golang-base.eclass and
> golang-build.eclass define EGO_PN as "the import path for the go package(s)
> to build". Moreover, example in golang-vcs.eclass shows usage of multiple
> import paths in EGO_PN (which is correct and should be supported), but later
> in code it uses ${EGO_PN%/...} which won't work correctly in this case.

I have been thinking about this, and I think the best way is going to be to go the other way. EGO_PN should only have one entry which is the import path of the project you are writing the ebuild for

If "go get github.com/user/project" installs the project correctly, github.com/user/project is what you should be using for EGO_PN.

> Repo may contains a lot of go packages, and sometimes we need to
> build/install only few of them, like "github.com/user/project/cmd/smallapp"
> or "github.com/user/project/cmd/...". If we'll have to always use
> "github.com/user/project/..." then this may result in fetching a lot of
> unneeded dependencies and building a lot of unneeded packages.
> 
> To fix these issues we should remove ${EGO_PN%/...} everywhere and add
> separate variable for "repo" itself. `go get` automatically discover repo
> url from import path, but this is complicated process which involved
> downloading from network and I'm not sure it's good idea to do the same
> while emerging package. So, best way is probably to add one more global
> variable like EGO_REPO:
> 
>   EGO_REPO="github.com/user/project"
>   EGO_PN="${EGO_REPO}/cmd/one ${EGO_REPO}/cmd/two"
> 
> and then use ${EGO_REPO} instead of ${EGO_PN%/...} everywhere.

Can you point to an ebuild in the tree that illustrates the issues you are talking about so I can take a look at it?

Thanks,

William
Comment 2 Alex Efros 2017-04-12 17:34:02 UTC
(In reply to William Hubbs from comment #1)
> Can you point to an ebuild in the tree that illustrates the issues you are
> talking about so I can take a look at it?

https://gpo.zugaina.org/Overlays/powerman/net-analyzer/alertmanager
https://gpo.zugaina.org/Overlays/powerman/net-analyzer/process-exporter

Even if these packages are not in official tree yet, chances are they'll be there anyway - alertmanager is practically a must-have add-on for net-analyzer/prometheus, which is in official tree.
Comment 3 Alex Efros 2017-04-12 17:43:08 UTC
(In reply to William Hubbs from comment #1)
> If "go get github.com/user/project" installs the project correctly,
> github.com/user/project is what you should be using for EGO_PN.

Well, that's not correct for Go projects in general. There is no rule or even established convention it should work this way. Most Go projects on github document required `go get` command to install that package in README, and often it looks like `go get github.com/user/project/cmd/...` or `go get github.com/user/project` instead of `go get github.com/user/project/...`. Usually this is because of vendor/ directory which contains a lot of projects which have own binaries in cmd/ with own dependencies which shouldn't (actually - must not) be installed at all.