From 49feb60ec62a374d4ad9cf721bdc6153917c48c4 Mon Sep 17 00:00:00 2001 From: ardnew Date: Wed, 17 Jan 2024 17:44:39 -0600 Subject: [PATCH] make.go: do not recodesign when rebuilding --- _scripts/make.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/_scripts/make.go b/_scripts/make.go index f6be8727db..2a7442faf6 100644 --- a/_scripts/make.go +++ b/_scripts/make.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io" "log" "os" "os/exec" @@ -54,7 +55,7 @@ func NewMakeCommands() *cobra.Command { } else { execute("go", "build", "-ldflags", "-extldflags -static", tagFlags(), buildFlags(), DelveMainPackagePath) } - if runtime.GOOS == "darwin" && os.Getenv("CERT") != "" && canMacnative() { + if runtime.GOOS == "darwin" && os.Getenv("CERT") != "" && canMacnative() && !isCodesigned("./dlv") { codesign("./dlv") } }, @@ -70,7 +71,7 @@ func NewMakeCommands() *cobra.Command { Short: "Installs delve", Run: func(cmd *cobra.Command, args []string) { execute("go", "install", tagFlags(), buildFlags(), DelveMainPackagePath) - if runtime.GOOS == "darwin" && os.Getenv("CERT") != "" && canMacnative() { + if runtime.GOOS == "darwin" && os.Getenv("CERT") != "" && canMacnative() && !isCodesigned(installedExecutablePath()) { codesign(installedExecutablePath()) } }, @@ -225,6 +226,15 @@ func getoutput(cmd string, args ...interface{}) string { return string(out) } +func isCodesigned(path string) bool { + x := exec.Command("codesign", "--verify", path) + x.Stdout = io.Discard + x.Stderr = io.Discard + x.Env = os.Environ() + err := x.Run() + return err == nil && x.ProcessState != nil && x.ProcessState.Success() +} + func codesign(path string) { execute("codesign", "-s", os.Getenv("CERT"), path) }