sweet: shell-quote environment variable values in -shell log

Currently the environment variable values printed when -shell is passed
aren't shell-quoted. As a result, the command produced by -shell may be
not directly usable in some circumstances. Fix this by running
shellquote.Join on the variable.

Change-Id: I77a136c27cbd31388697bdd54927dd40d40535e5
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/614539
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/sweet/common/log/log.go b/sweet/common/log/log.go
index 0ff58be..ffa99bd 100644
--- a/sweet/common/log/log.go
+++ b/sweet/common/log/log.go
@@ -5,6 +5,7 @@
 package log
 
 import (
+	"fmt"
 	"log"
 	"os"
 	"os/exec"
@@ -47,7 +48,7 @@
 	actOn = on
 }
 
-func filterEnviron(env []string) []string {
+func filterAndQuoteEnviron(env []string) []string {
 	fenv := make([]string, 0, len(env))
 	for _, e := range env {
 		s := strings.SplitN(e, "=", 2)
@@ -57,7 +58,7 @@
 		if v, ok := envMap[s[0]]; ok && v == s[1] {
 			continue
 		}
-		fenv = append(fenv, e)
+		fenv = append(fenv, fmt.Sprintf("%s=%s", s[0], shellquote.Join(s[1])))
 	}
 	return fenv
 }
@@ -68,7 +69,7 @@
 	}
 	senv := ""
 	if len(cmd.Env) != 0 {
-		senv = strings.Join(filterEnviron(cmd.Env), " ")
+		senv = strings.Join(filterAndQuoteEnviron(cmd.Env), " ")
 	}
 	if cmd.Dir != "" {
 		cmdLog.Printf("pushd %s", cmd.Dir)