Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
19 changes: 14 additions & 5 deletions depaware/depaware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down