From 8f8dee83035d30e4b82c370489ceabec687eb6ad Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 22 Aug 2022 20:23:16 +0200 Subject: [PATCH] aerc: fix build when GOFLAGS contains spaces Due to multiple levels of nested quoting, it is not possible to escape spaces and/or quotes from GOFLAGS and pass the value to go build -ldflags to set a compile time variable. Encode main.Flags in base64 and decode it when reading it. Fixes: d7e6dc3649ea ("aerc: add build info to version string") Signed-off-by: Robin Jarry Acked-by: Moritz Poldrack --- Makefile | 3 ++- aerc.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 551fb1e..e21c1e6 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,11 @@ MANDIR?=$(PREFIX)/share/man GO?=go GOFLAGS?= BUILD_OPTS?=-trimpath +flags!=echo -- $(GOFLAGS) | base64 | tr -d '\n' # ignore environment variable GO_LDFLAGS:= GO_LDFLAGS+=-X main.Version=$(VERSION) -GO_LDFLAGS+=-X main.Flags=$(GOFLAGS) +GO_LDFLAGS+=-X main.Flags=$(flags) GO_LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR) GO_LDFLAGS+=$(GO_EXTRA_LDFLAGS) diff --git a/aerc.go b/aerc.go index 865f066..4c9debf 100644 --- a/aerc.go +++ b/aerc.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/base64" "errors" "fmt" "os" @@ -95,7 +96,8 @@ var Flags string func buildInfo() string { info := Version - if strings.Contains(Flags, "notmuch") { + flags, _ := base64.StdEncoding.DecodeString(Flags) + if strings.Contains(string(flags), "notmuch") { info += " +notmuch" } info += fmt.Sprintf(" (%s %s %s)",