From 2db877caa332c8968ee1b1eb08ef40a219ff3eec Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 20 Sep 2021 14:35:19 -0700 Subject: [PATCH] version: fix CmdName on the tailscale-ipn.exe binary Don't return "wg64", "wg32", etc. Signed-off-by: Brad Fitzpatrick --- version/cmdname.go | 13 +++++++++++-- version/modinfo_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/version/cmdname.go b/version/cmdname.go index a0ae1a7f4..d712902aa 100644 --- a/version/cmdname.go +++ b/version/cmdname.go @@ -26,13 +26,16 @@ func CmdName() string { if err != nil { return "cmd" } + return cmdName(e) +} +func cmdName(exe string) string { // fallbackName, the lowercase basename of the executable, is what we return if // we can't find the Go module metadata embedded in the file. - fallbackName := filepath.Base(strings.TrimSuffix(strings.ToLower(e), ".exe")) + fallbackName := filepath.Base(strings.TrimSuffix(strings.ToLower(exe), ".exe")) var ret string - info, err := findModuleInfo(e) + info, err := findModuleInfo(exe) if err != nil { return fallbackName } @@ -45,6 +48,12 @@ func CmdName() string { break } } + if strings.HasPrefix(ret, "wg") && fallbackName == "tailscale-ipn" { + // The tailscale-ipn.exe binary for internal build system packaging reasons + // has a path of "tailscale.io/win/wg64", "tailscale.io/win/wg32", etc. + // Ignore that name and use "tailscale-ipn" instead. + return fallbackName + } if ret == "" { return fallbackName } diff --git a/version/modinfo_test.go b/version/modinfo_test.go index 117b46ca1..67df39707 100644 --- a/version/modinfo_test.go +++ b/version/modinfo_test.go @@ -5,6 +5,7 @@ package version import ( + "flag" "os/exec" "path/filepath" "runtime" @@ -36,3 +37,18 @@ func exe() string { } return "" } + +var findModuleInfoName = flag.String("module-info-file", "", "if non-empty, test findModuleInfo against this filename") + +func TestFindModuleInfoManual(t *testing.T) { + exe := *findModuleInfoName + if exe == "" { + t.Skip("skipping without --module-info-file filename") + } + cmd := cmdName(exe) + mod, err := findModuleInfo(exe) + if err != nil { + t.Fatal(err) + } + t.Logf("Got %q from: %s", cmd, mod) +}