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

Go modules support? #53

Closed
Bobgy opened this issue Mar 3, 2021 · 9 comments
Closed

Go modules support? #53

Bobgy opened this issue Mar 3, 2021 · 9 comments

Comments

@Bobgy
Copy link
Collaborator

Bobgy commented Mar 3, 2021

UPDATE: I sent go-licenses/v2 proposal that takes go modules as first class citizen #70

Is there any plan for go modules support?

I'd like to get licenses for certain version of a library, because transitive dependency can be different between versions.

I believe this should address #33.

@Bobgy
Copy link
Collaborator Author

Bobgy commented Mar 3, 2021

go list -m all gives all transitive dependencies with version.

https://blog.golang.org/using-go-modules

@Bobgy
Copy link
Collaborator Author

Bobgy commented Mar 3, 2021

I built a go license tool for kubeflow.org in
https://github.com/kubeflow/testing/tree/master/py/kubeflow/testing/go-license-tools (at that time, this tool didn't exist).
I don't have much bandwidth to keep maintaining it, so I wanted to discuss if there could be better ways to collaborate.

I took the approach described in this issue:

  1. find all dependencies (and transitive dependencies) via go list -m all (for repos using go.mod)
  2. infer github repo name from the go import path
  3. use github license api to get the license

it doesn't automate as much as this tool did, because

  1. inferring github repo url from go import path was hard
  2. github license api doesn't recognize some licenses very well, especially BSD 3-clause

but maybe we can improve from there taking sth already built here.

@Bobgy

This comment has been minimized.

@Bobgy
Copy link
Collaborator Author

Bobgy commented Mar 4, 2021

Nevermind, I just tried putting a module into GOPATH and run go mod vendor,
after that, running
go-licenses csv <module-name>
generates all its dependencies' licenses.

However, urls are missing as stated

URLs may not be available if the library is not checked out as a Git repository (e.g. as is the case when Go Modules are enabled).

So what I suggested above can already be achieved by this tool.

@Bobgy
Copy link
Collaborator Author

Bobgy commented Mar 4, 2021

Hmmm, not exactly.

I noticed a dangerous behavior, some repos do not have a license file. e.g. license file is embedded in README: https://github.com/upper/db/tree/v3.0.0.

However, this tool does not give a warning of a module missing license about it when used in this way.

@Bobgy
Copy link
Collaborator Author

Bobgy commented Mar 5, 2021

I tried to implement ideas in this issue as https://github.com/Bobgy/go-mod-licenses to suit my own use-cases.

@mreiche
Copy link

mreiche commented May 3, 2021

Hey Bobgy, can you explain a little bit more in detail what you achieved?

I just want to license check my local project's dependencies from go.mod, is that the same you were asking for?
When yes, how you would do this?

My approach would be to:

  • Read all transitive dependencies
  • Perform go license check on every repo
  • Collect in CSV and make them unique

@Bobgy
Copy link
Collaborator Author

Bobgy commented May 14, 2021

@mreiche I've got a bit more requirements so did a few more complex things:

  • my process requires public URLs of the license files (like this tool provides, but works for go modules), so I had to use go import semantics to figure out corresponding public repos of go modules
  • also my process requires scanning every file of each used go module
  • also I noticed the full transitive dependency graph of go modules tend to be very large and unnecessary (some dependencies not actually used in built binary), I changed to read the list of modules actually used in a built go binary instead
  • there are a bunch more workflow related features to keep configurations for manually verified repos
  • and auto redistribute source folders needed
  • there're more that I don't have time to explain now

I've implemented a tool like described above and used it to generate licenses, example:

I want to open source my tool, but I'm currently fairly busy with other stuff. Might not have time to do that soon.

Curious if these sound useful to others.

@Bobgy
Copy link
Collaborator Author

Bobgy commented Apr 10, 2022

Implemented in #94

@Bobgy Bobgy closed this as completed Apr 10, 2022
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

No branches or pull requests

2 participants