Skip to content

Commit

Permalink
all: build Windows protoc-gen-go as a .exe in a zip
Browse files Browse the repository at this point in the history
Add a .exe suffix to the protoc-gen-go Windows binary.
Use zip instead of tar for the Windows release archive.

Fixes golang/protobuf#1323

Change-Id: If42fa6dfd8b5496148310fa2a3359161f1124229
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321530
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
  • Loading branch information
neild committed May 20, 2021
1 parent 24d799b commit 50a8591
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions integration_test.go
Expand Up @@ -8,6 +8,7 @@ package main

import (
"archive/tar"
"archive/zip"
"bytes"
"compress/gzip"
"crypto/sha256"
Expand Down Expand Up @@ -392,18 +393,31 @@ func mustHandleFlags(t *testing.T) {
t.Fatal(err)
}
out := new(bytes.Buffer)
gz, _ := gzip.NewWriterLevel(out, gzip.BestCompression)
gz.Comment = fmt.Sprintf("protoc-gen-go VERSION=%v GOOS=%v GOARCH=%v", v, goos, goarch)
tw := tar.NewWriter(gz)
tw.WriteHeader(&tar.Header{
Name: "protoc-gen-go",
Mode: int64(0775),
Size: int64(len(in)),
})
tw.Write(in)
tw.Close()
gz.Close()
if err := ioutil.WriteFile(binPath+".tar.gz", out.Bytes(), 0664); err != nil {
suffix := ""
comment := fmt.Sprintf("protoc-gen-go VERSION=%v GOOS=%v GOARCH=%v", v, goos, goarch)
switch goos {
case "windows":
suffix = ".zip"
zw := zip.NewWriter(out)
zw.SetComment(comment)
fw, _ := zw.Create("protoc-gen-go.exe")
fw.Write(in)
zw.Close()
default:
suffix = ".tar.gz"
gz, _ := gzip.NewWriterLevel(out, gzip.BestCompression)
gz.Comment = comment
tw := tar.NewWriter(gz)
tw.WriteHeader(&tar.Header{
Name: "protoc-gen-go",
Mode: int64(0775),
Size: int64(len(in)),
})
tw.Write(in)
tw.Close()
gz.Close()
}
if err := ioutil.WriteFile(binPath+suffix, out.Bytes(), 0664); err != nil {
t.Fatal(err)
}
}
Expand Down

0 comments on commit 50a8591

Please sign in to comment.