From 781c1e96247532256974e864c5ba6e653e103b9d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Feb 2025 12:14:14 -0800 Subject: [PATCH] tstest/deptest: add DepChecker.ExtraEnv option for callers to set For tests (in another repo) that use cgo, we'd like to set CGO_ENABLED=1 explicitly when evaluating cross-compiled deps with "go list". Updates tailscale/corp#26717 Updates tailscale/corp#26737 Change-Id: Ic21a54379ae91688d2456985068a47e73d04a645 Signed-off-by: Brad Fitzpatrick --- tstest/deptest/deptest.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tstest/deptest/deptest.go b/tstest/deptest/deptest.go index 2393733e6..4effd4a78 100644 --- a/tstest/deptest/deptest.go +++ b/tstest/deptest/deptest.go @@ -27,6 +27,7 @@ type DepChecker struct { BadDeps map[string]string // package => why WantDeps set.Set[string] // packages expected Tags string // comma-separated + ExtraEnv []string // extra environment for "go list" (e.g. CGO_ENABLED=1) } func (c DepChecker) Check(t *testing.T) { @@ -43,6 +44,7 @@ func (c DepChecker) Check(t *testing.T) { if c.GOARCH != "" { extraEnv = append(extraEnv, "GOARCH="+c.GOARCH) } + extraEnv = append(extraEnv, c.ExtraEnv...) cmd.Env = append(os.Environ(), extraEnv...) out, err := cmd.Output() if err != nil {