Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make.go: skip codesigning when testing an existing build #3639

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
14 changes: 12 additions & 2 deletions _scripts/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -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")
}
},
Expand All @@ -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())
}
},
Expand Down Expand Up @@ -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)
}
Expand Down