From 5eeb58fab886bc1349b2b32105738fb4d9510bfc Mon Sep 17 00:00:00 2001 From: Donal Cahill Date: Sun, 27 Mar 2022 15:53:46 +0100 Subject: [PATCH 1/2] change go get to go install --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2e59ac0..3ba75c5 100644 --- a/main.go +++ b/main.go @@ -90,7 +90,7 @@ func buildExecutable() { } // go get the rsrc lib - execCommand("go", "get", "github.com/akavel/rsrc") + execCommand("go", "install", "github.com/akavel/rsrc") // create the rsrc.syso to set the icon of upcoming executable gopath := os.Getenv("GOPATH") From f404a2079ac18a7c54888bfa2f5d4cbebb83b060 Mon Sep 17 00:00:00 2001 From: Donal Cahill Date: Sun, 27 Mar 2022 16:24:57 +0100 Subject: [PATCH 2/2] check if an icon was found before using it --- main.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 3ba75c5..9dc1080 100644 --- a/main.go +++ b/main.go @@ -89,14 +89,23 @@ func buildExecutable() { forceExitIfError("the git binary is required to be added into PATH env var") } - // go get the rsrc lib - execCommand("go", "install", "github.com/akavel/rsrc") - - // create the rsrc.syso to set the icon of upcoming executable - gopath := os.Getenv("GOPATH") - rsrcFilename := "rsrc.syso" - rsrcExecFile := filepath.Join(gopath, "bin", strings.Split(rsrcFilename, ".")[0]) - execCommand(rsrcExecFile, "-ico", icon) + iconFlags := "" + if icon != "" { + // go get the rsrc lib + execCommand("go", "install", "github.com/akavel/rsrc") + + // create the rsrc.syso to set the icon of upcoming executable + gopath := os.Getenv("GOPATH") + rsrcFilename := "rsrc.syso" + rsrcExecFile := filepath.Join(gopath, "bin", strings.Split(rsrcFilename, ".")[0]) + execCommand(rsrcExecFile, "-ico", icon) + + // remove syso file later + defer os.Remove(rsrcFilename) + + // set ldflags + iconFlags = fmt.Sprintf(` -X "main.icon=%s"`, icon) + } // remove existing file os.Remove(filename) @@ -105,12 +114,9 @@ func buildExecutable() { execCommand( "go", "build", - "-ldflags", fmt.Sprintf(`-X "main.isRuntime=true" -X "main.osName=%s" -X "main.url=%s" -X "main.icon=%s"`, runtime.GOOS, url, icon), + "-ldflags", fmt.Sprintf(`-X "main.isRuntime=true" -X "main.osName=%s" -X "main.url=%s"`, runtime.GOOS, url)+iconFlags, "-o", filename, ) - - // remove syso file - os.Remove(rsrcFilename) } else { // build the executable file