From 7e65a11df5afa03bcea529842c09fa512df5d8cb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 22 Feb 2023 17:34:55 -0800 Subject: [PATCH] tool/gocross: write the wrapper script directly, rather than printing Turns out directing the printed script into the bootstrap location leads to irritating "text file busy" problems and then having to muck about with tempfiles and chmod and all that. Instead, have gocross write everything with the right values. Signed-off-by: David Anderson --- tool/gocross/gocross.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tool/gocross/gocross.go b/tool/gocross/gocross.go index a1e22c819..4a073875b 100644 --- a/tool/gocross/gocross.go +++ b/tool/gocross/gocross.go @@ -17,6 +17,8 @@ import ( "os" "path/filepath" runtimeDebug "runtime/debug" + + "tailscale.com/atomicfile" ) func main() { @@ -56,8 +58,15 @@ func main() { } fmt.Println(filepath.Join(toolchain, "bin/go")) os.Exit(0) - case "gocross-print-wrapper-script": - fmt.Println(wrapperScript) + case "gocross-write-wrapper-script": + if len(os.Args) != 3 { + fmt.Fprintf(os.Stderr, "usage: gocross write-wrapper-script \n") + os.Exit(1) + } + if err := atomicfile.WriteFile(os.Args[2], wrapperScript, 0755); err != nil { + fmt.Fprintf(os.Stderr, "writing wrapper script: %v\n", err) + os.Exit(1) + } os.Exit(0) } } @@ -98,7 +107,7 @@ func main() { } //go:embed gocross-wrapper.sh -var wrapperScript string +var wrapperScript []byte func debug(format string, args ...interface{}) { debug := os.Getenv("GOCROSS_DEBUG")