8000 `LICENSE` file in repo root is ignored · Issue #186 · google/go-licenses · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

LICENSE file in repo root is ignored #186

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

Open
derpsteb opened this issue Feb 15, 2023 · 4 comments · May be fixed by #328
Open

LICENSE file in repo root is ignored #186

derpsteb opened this issue Feb 15, 2023 · 4 comments · May be fixed by #328

Comments

@derpsteb
Copy link

Hey everyone,

according to the Go Modules Reference the go command would use a LICENSE file from the repo root if it can not find one in the module's directory and is currently not in the repo's root dir.

However, it seems like go-licenses currently does not replicate this behavior. At least I am getting an error along the lines of:
Failed to find license for modulename: cannot find a known open source license for "path/to/module" whose name matches regexp ^(?i)((UN)?LICEN(S|C)E|COPYING|README|NOTICE).*$ and locates up until "path/to/module/.."

Even though the root folder of the repo that contains the submodule modulename has a valid LICENSE file in the root folder.

Should I look elsewhere for a reason or is this really not supported? :P

Best.

@Bobgy
Copy link
Collaborator
Bobgy commented Feb 22, 2023

The mentioned behavior is already replicated by go when it downloads module caches.

Are you talking about modules in your main repo?

@Bobgy
Copy link
Collaborator
Bobgy commented Feb 22, 2023

Besides, can you share a repo that can reproduce this error?

@derpsteb
Copy link
Author
derpsteb commented Feb 24, 2023

To reproduce the error you could run:

git clone https://github.com/edgelesssys/constellation.git && cd constellation && rm ./operators/constellation-node-operator/api/LICENSE && go-licenses check ./...

Sorry, the repo is a bit big, but it should be easily reproduce the problem.
We have a monorepo and the offending module is a submodule within that repo.

@jmdeal
Copy link
jmdeal commented Feb 16, 2024

As another example, we're taking a dependency on github.com/awslabs/amazon-eks-ami/nodeadm. The repo, https://github.com/awslabs/amazon-eks-ami has a LICENSE file in its root but go-licenses returns the following error:

E0216 14:22:47.917881   39990 library.go:122] Failed to find license for github.com/awslabs/amazon-eks-ami/nodeadm/api/v1alpha1: cannot find a known open source license for "/Users/jmdeal/go/pkg/mod/github.com/awslabs/amazon-eks-ami/nodeadm@v0.0.0-20240212193458-d97e2ad07de4/api/v1alpha1" whose name matches regexp ^(?i)((UN)?LICEN(S|C)E|COPYING|README|NOTICE).*$ and locates up until "/Users/jmdeal/go/pkg/mod/github.com/awslabs/amazon-eks-ami/nodeadm@v0.0.0-20240212193458-d97e2ad07de4"

Additionally, when I looked in the local copy of the module the LICENSE file did in-fact exist.

gwatts added a commit to gwatts/go-licenses that referenced this issue May 9, 2025
resolves google#73, resolves google#186

For modules that are not at the root of the repo, Go will make a copy of
the LICENSE file from the repo root into the module's directory when
creating the .zip file (see https://go.dev/ref/mod#vcs-license)

This throws off URL generation, as FileURL will create a link to a repo
URL to the license that doesn't exist as the file was synthesized by Go.

Attempt to detect this case by examining the zip file that Go creates -
As it stands, it appends the LICENSE file to the zip's file directory;
we can generally assume that if we see such an addition, it's a result
of Go copying it there and therefore it's not a real file in the repo,
instead being copied from the root.

If we find that to be the case, generate a link to the original LICENSE
file at the root of the repo instead.

The complex e2e test here exercises this nicely (updated links didn't
work before, now they do).
gwatts added a commit to gwatts/go-licenses that referenced this issue May 9, 2025
resolves google#73, resolves google#186

For modules that are not at the root of the repo, Go will make a copy of
the LICENSE file from the repo root into the module's directory when
creating the .zip file (see https://go.dev/ref/mod#vcs-license)

This throws off URL generation, as FileURL will create a link to a repo
URL to the license that doesn't exist as the file was synthesized by Go.

Attempt to detect this case by examining the zip file that Go creates -
As it stands, it appends the LICENSE file to the zip's file directory;
we can generally assume that if we see such an addition, it's a result
of Go copying it there and therefore it's not a real file in the repo,
instead being copied from the root.

If we find that to be the case, generate a link to the original LICENSE
file at the root of the repo instead.

The complex e2e test here exercises this nicely (updated links didn't
work before, now they do).
@gwatts gwatts linked a pull request May 9, 2025 that will close this issue
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 a pull request may close this issue.

3 participants
0