Skip to content

Commit 4f88b5a

Browse files
committed
autogen: update license overview
1 parent 534e095 commit 4f88b5a

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

.bin/list-licenses

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ fi
1616

1717
# list Go licenses
1818
if [ -f go.mod ]; then
19-
# List all direct Go module dependencies, transform their paths to root module paths
20-
# (e.g., github.com/ory/x instead of github.com/ory/x/foo/bar), and generate a license report
21-
# for each unique root module. This ensures that the license report is generated for the root
22-
# module of a repository, where licenses are typically defined.
23-
go_modules=$(
24-
go list -f "{{if not .Indirect}}{{.Path}}{{end}}" -m ... |
25-
sort -u |
26-
awk -F/ '{ if ($1 == "github.com" && NF >= 3) { print $1"/"$2"/"$3 } else { print } }' |
27-
sort -u
19+
# For each direct Go module dependency, pick one importable package and let
20+
# go-licenses report on it. Calling `go-licenses report <module>` directly
21+
# does not work for two common cases:
22+
# - Versioned modules carry a /vN suffix that must be present verbatim
23+
# (github.com/golang-jwt/jwt/v5, github.com/dgraph-io/ristretto/v2).
24+
# - Some module roots have no Go file of their own; only sub-packages
25+
# are importable (cloud.google.com/go/secretmanager -> .../apiv1).
26+
# Walking the actual import graph with `go list -deps` sidesteps both.
27+
go_packages=$(
28+
go list -deps -f '{{if .Module}}{{if not .Module.Main}}{{if not .Module.Indirect}}{{.Module.Path}}|{{.ImportPath}}{{end}}{{end}}{{end}}' ./... |
29+
sort -u -t'|' -k1,1 |
30+
cut -d'|' -f2
2831
)
29-
if [ -z "$go_modules" ]; then
32+
if [ -z "$go_packages" ]; then
3033
echo "No Go modules found" >&2
3134
else
32-
# Workaround until https://github.com/google/go-licenses/issues/307 is fixed
33-
# .bin/go-licenses report "$module_name" --template .bin/license-template-go.tpl 2>/dev/null
34-
#
35-
echo "$go_modules" | xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' | grep -v '^$'
35+
echo "$go_packages" | xargs -I {} sh -c '.bin/go-licenses report --template .bin/license-template-go.tpl {}' | grep -v '^$'
3636
echo
3737
fi
3838
fi

0 commit comments

Comments
 (0)