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

licensetool: embed license DB, update for more modules #3665

Merged
merged 2 commits into from
Dec 2, 2022

Conversation

justinsb
Copy link
Contributor

We now embed some licenses using go:embed, so we don't need to set up a modules DB in every project. A local modules folder is still checked first, and TODO files are still written locally to a local modules folder.

Also add a bunch more module license information from different places I've been running the tool.

@justinsb justinsb force-pushed the embed_licensetool branch 2 times, most recently from ab6b674 to 6b8fd87 Compare November 17, 2022 15:27
We now embed some licenses using go:embed, so we don't need to set up
a modules DB in every project. A local modules folder is still checked
first, and TODO files are still written locally to a local modules
folder.
Update a bunch of licenses from different places I've been running the
licensetool.
@justinsb justinsb requested a review from mortent December 1, 2022 15:12
@@ -35,6 +36,9 @@ import (
"sigs.k8s.io/yaml"
)

//go:embed modules/*
var modulesFS embed.FS
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting: eventually we can have it in its own Go package that will make this DB portable across all the tools :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope so :-)

if err != nil && os.IsNotExist(err) {
b2, err2 := modulesFS.ReadFile(p)
if err2 == nil {
b = b2
Copy link
Contributor

Choose a reason for hiding this comment

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

so this will ensure license info from the moduleFS gets written back to local FS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ish. The workflow I use is to run it against the binary. Then I search for license: TODO go through and fill in any missing licenses that are generated. The link to the go package DB makes this easy, if a little tedious. Then I commit the files, and then yes the go:embed ensures that (once merged) they are automatically embedded in as part of go build.

if err2 == nil {
b = b2
err = err2
}
Copy link
Contributor

Choose a reason for hiding this comment

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

err2 != nil is being ignored and I believe that's intentional because err is what we care about in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is deliberate (I think), but I think I'll take a second look and maybe log a V(4) message to make the code at least more self-explanatory.

@justinsb justinsb merged commit 519b56c into kptdev:main Dec 2, 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

Successfully merging this pull request may close these issues.

2 participants