diff --git a/README.md b/README.md index 4c2e528..72ddbff 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ https://github.com/tailscale/tailscale/blob/main/cmd/tailscaled/depaware.txt Then you and others can easily see what your dependencies are, how they vary by operating system (the letters L(inux), D(arwin), -W(indows) in the left column), and whether they use unsafe/cgo (bomb -icon). +W(indows) in the left column), and whether they use (U)nsafe or runtime/(C)go. Then you hook it up to your CI so it's a build breakage if they're not up to date: diff --git a/depaware/depaware.go b/depaware/depaware.go index 8019ab6..00e6e55 100644 --- a/depaware/depaware.go +++ b/depaware/depaware.go @@ -74,7 +74,7 @@ func process(pkg string) { env := os.Environ() env = append(env, "GOARCH=amd64", "GOOS="+goos, "CGO_ENABLED=1") cfg := &packages.Config{ - Mode: packages.NeedImports | packages.NeedDeps | packages.NeedFiles | packages.NeedName, + Mode: packages.NeedImports | packages.NeedDeps | packages.NeedFiles | packages.NeedName | packages.NeedCompiledGoFiles, Env: env, BuildFlags: buildFlags, } @@ -127,9 +127,13 @@ func process(pkg string) { var osBuf bytes.Buffer for _, pkg := range d.Deps { - icon := " " + unsafeIcon := " " + cgoIcon := " " if d.UsesUnsafe[pkg] && !isGoPackage(pkg) { - icon = "💣" + unsafeIcon = "U" + } + if d.UsesCGO[pkg] && !isGoPackage(pkg) { + cgoIcon = "C" } osBuf.Reset() for _, goos := range geese { @@ -140,7 +144,7 @@ func process(pkg string) { if osBuf.Len() == len(geese) { osBuf.Reset() } - fmt.Fprintf(&buf, " %3s %s %-60s %s\n", osBuf.Bytes(), icon, pkg, d.Why(pkg, preferredWhy)) + fmt.Fprintf(&buf, " %3s %s%s %-60s %s\n", osBuf.Bytes(), unsafeIcon, cgoIcon, pkg, d.Why(pkg, preferredWhy)) } if *check { @@ -185,6 +189,7 @@ type deps struct { DepTo map[string][]string // pkg in key is imported by packages in value UsesUnsafe map[string]bool + UsesCGO map[string]bool } func (d *deps) Why(pkg string, preferredWhy map[string]string) string { @@ -221,13 +226,17 @@ func (d *deps) AddEdge(from, to string) { if d.DepTo == nil { d.DepTo = make(map[string][]string) d.UsesUnsafe = make(map[string]bool) + d.UsesCGO = make(map[string]bool) } if !stringsContains(d.DepTo[to], from) { d.DepTo[to] = append(d.DepTo[to], from) } - if to == "unsafe" || to == "C" { + if to == "unsafe" { d.UsesUnsafe[from] = true } + if to == "runtime/cgo" { + d.UsesCGO[from] = true + } } func (d *deps) AddDep(pkg, goos string) {