licenseclassifier icon indicating copy to clipboard operation
licenseclassifier copied to clipboard

Trying to vendor go-licenses, which uses this, fails because the license DB is not vendored.

Open thockin opened this issue 3 years ago • 4 comments

I see how this is trying to be very clever and find the license DB in its own source code path.

This totally breaks down in the face of Go's vendoring, which elides directories that do not have linked Go code in them.

So....ideas? Wouldn't it be better to embed the DB into the binary and make it self contained?

thockin avatar Mar 19 '21 22:03 thockin

The licenseclassifier itself was fixed with this commit

The go-licenses package needs to be updated to get this change; I've sent a pull request to get this resolved.

wcn3 avatar Mar 24 '21 17:03 wcn3

Does that work with vendoring? I thought vendoring would exclude a package that was not reachable from the main package.

Indeed:

$ cat main.go
package main

import "github.com/google/licenseclassifier"

func main() {
x := licenseclassifier.License{}
_ = x
}

$ go mod init example.com/foo
go: creating new go.mod: module example.com/foo
go: to add module requirements and sums:
go mod tidy

$ go mod tidy
go: finding module for package github.com/google/licenseclassifier
go: found github.com/google/licenseclassifier in
github.com/google/licenseclassifier v0.0.0-20210324170212-2c2d728dc0d7

$ go mod vendor

$ find vendor/github.com/google/licenseclassifier/ -type d
vendor/github.com/google/licenseclassifier/
vendor/github.com/google/licenseclassifier/stringclassifier
vendor/github.com/google/licenseclassifier/stringclassifier/searchset
vendor/
github.com/google/licenseclassifier/stringclassifier/searchset/tokenizer
vendor/github.com/google/licenseclassifier/stringclassifier/internal
vendor/github.com/google/licenseclassifier/stringclassifier/internal/pq
vendor/github.com/google/licenseclassifier/internal
vendor/github.com/google/licenseclassifier/internal/sets

Empirically you need that dummy.go to not have a build tag and to export some symbol which is used by the rest of the lib. I tried it by mocking up github.com/thockin/vendortest

$ cat licenses/dummy.go
// Placeholder, allows others to pull in the licenses.db file via go.mod.
package licenses

var Dummy bool

$ cat top.go
package vendortest

import "github.com/thockin/vendortest/licenses"

type Top struct{}

var Dummy = licenses.Dummy

Probably using a type definition and an unexported alias would be even less impactful?

On Wed, Mar 24, 2021 at 10:24 AM Bill Neubauer @.***> wrote:

The licenseclassifier itself was fixed with this commit https://github.com/google/licenseclassifier/commit/df6aa8a2788bdf5ac382148c2453a407a29819b8

The go-licenses package needs to be updated to get this change; I've sent a pull request https://github.com/google/go-licenses/pull/57 to get this resolved.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/licenseclassifier/issues/27#issuecomment-806015845, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKWAVD2EYNY5XLW7NGI7DLTFIN6NANCNFSM4ZPTENUQ .

thockin avatar Mar 24 '21 19:03 thockin

See https://github.com/google/licenseclassifier/pull/32 for a change to this lib, which (when updated in go-licenses) should support being vendored.

thockin avatar Mar 25 '21 18:03 thockin

@thockin Looks like this issue can be closed

dbolkensteyn avatar Oct 12 '22 04:10 dbolkensteyn