Skip to content

Commit a471d41

Browse files
authored
Download protoc instead of using embedded version (#12)
1 parent 436e548 commit a471d41

18 files changed

+239
-177
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Wrapper binaries are also published to Maven repo, so that they could be used in
2121

2222
## How it works
2323

24-
First of all, wrapper extracts the real `protoc` binary into the user's cache directory (including the protos provided by the upstream protoc distribution). Default cache directory on Linux is ~/.cache/protoc (unless `$XDG_CACHE_HOME` is provided). Default cache directory on macOS is ~/Library/Caches. Protoc binary is extracted only once, if there is an existing binary in the cache with the matching checksum - it will be used instead.
24+
First of all, wrapper downloads the real `protoc` binary into the user's cache directory (including the protos provided by the upstream protoc distribution). Default cache directory on Linux is ~/.cache/protoc (unless `$XDG_CACHE_HOME` is provided). Default cache directory on macOS is ~/Library/Caches. Protoc binary is downloaded only once, if there is an existing binary in the cache with the matching checksum - it will be used instead.
2525

2626
Then, wrapper parses all command line flags. If an argument looks like a path to the proto file - wrapper checks whether the path exists on the local machine. If not - then it's likely to be a remote proto file URL.
2727

cmd-git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//+build !gogit
1+
//go:build !gogit
22

33
package main
44

gen.go

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
//go:build generage
2-
// +build generage
1+
//go:build generate
32

43
package main
54

65
import (
76
"archive/zip"
87
"bytes"
9-
"crypto/md5"
108
"fmt"
119
"io/ioutil"
1210
"log"
@@ -16,7 +14,6 @@ import (
1614
)
1715

1816
const (
19-
protoBinariesbaseURL = "https://repo1.maven.org/maven2/com/google/protobuf/protoc"
2017
protoIncludesBaseUrl = "https://github.com/protocolbuffers/protobuf/releases/download"
2118
includesDir = "include"
2219
)
@@ -35,7 +32,6 @@ func main() {
3532
log.Fatal("USAGE: go run -tags generate gen.go <version>")
3633
}
3734
version := os.Args[1]
38-
generateProtoBinaries(version)
3935
generateProtoIncludes(version)
4036
}
4137

@@ -95,60 +91,3 @@ func readZipFile(zf *zip.File) ([]byte, error) {
9591
defer f.Close()
9692
return ioutil.ReadAll(f)
9793
}
98-
99-
func generateProtoBinaries(version string) {
100-
platforms := map[string]string{
101-
"linux-x86_32": "linux_386",
102-
"linux-x86_64": "linux_amd64",
103-
"linux-aarch_64": "linux_arm64",
104-
"osx-x86_64": "darwin_amd64",
105-
"osx-aarch_64": "darwin_arm64",
106-
"windows-x86_32": "windows_386",
107-
"windows-x86_64": "windows_amd64",
108-
}
109-
110-
for arch, goarch := range platforms {
111-
url := fmt.Sprintf("%[1]s/%[2]s/protoc-%[2]s-%[3]s.exe", protoBinariesbaseURL, version, arch)
112-
exe, err := download(url)
113-
if err != nil {
114-
log.Fatal(err)
115-
}
116-
117-
cksum, err := download(url + ".md5")
118-
if err != nil {
119-
log.Fatal(err)
120-
}
121-
122-
if s := fmt.Sprintf("%x", md5.Sum(exe)); s != string(cksum) {
123-
log.Fatalln("checksum mismatch: ", url, s, string(cksum))
124-
}
125-
f, err := os.Create(fmt.Sprintf("protoc_exe_%s.go", goarch))
126-
if err != nil {
127-
log.Fatal(err)
128-
}
129-
defer f.Close()
130-
fmt.Fprintln(f, "package main")
131-
fmt.Fprintln(f)
132-
fmt.Fprint(f, `var protoc = []byte("`)
133-
defer fmt.Fprintln(f, `")`)
134-
for _, b := range exe {
135-
if b == '\n' {
136-
f.WriteString(`\n`)
137-
continue
138-
}
139-
if b == '\\' {
140-
f.WriteString(`\\`)
141-
continue
142-
}
143-
if b == '"' {
144-
f.WriteString(`\"`)
145-
continue
146-
}
147-
if (b >= 32 && b <= 126) || b == '\t' {
148-
f.Write([]byte{b})
149-
continue
150-
}
151-
fmt.Fprintf(f, "\\x%02x", b)
152-
}
153-
}
154-
}

git_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"strings"
1414
"testing"
1515

16-
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
17-
"gopkg.in/src-d/go-git.v4/plumbing/transport"
18-
"gopkg.in/src-d/go-git.v4/plumbing/transport/server"
16+
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
17+
"github.com/go-git/go-git/v5/plumbing/transport"
18+
"github.com/go-git/go-git/v5/plumbing/transport/server"
1919
)
2020

2121
var gitAddr = ""

go-git.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//+build gogit
1+
//go:build gogit
22

33
package main
44

@@ -9,11 +9,11 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
git "gopkg.in/src-d/go-git.v4"
13-
plumbing "gopkg.in/src-d/go-git.v4/plumbing"
14-
transport "gopkg.in/src-d/go-git.v4/plumbing/transport"
15-
http "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
16-
ssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
12+
git "github.com/go-git/go-git/v5"
13+
plumbing "github.com/go-git/go-git/v5/plumbing"
14+
transport "github.com/go-git/go-git/v5/plumbing/transport"
15+
http "github.com/go-git/go-git/v5/plumbing/transport/http"
16+
ssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
1717
)
1818

1919
func netrcAuth(importPath string) transport.AuthMethod {

go.mod

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
module github.com/sixt/protoc/v3
22

3-
go 1.16
3+
go 1.18
44

55
require (
6+
github.com/go-git/go-git/v5 v5.4.2
7+
github.com/stretchr/testify v1.7.0
8+
)
9+
10+
require (
11+
github.com/Microsoft/go-winio v0.4.16 // indirect
12+
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
13+
github.com/acomagu/bufpipe v1.0.3 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/emirpasic/gods v1.12.0 // indirect
16+
github.com/go-git/gcfg v1.5.0 // indirect
17+
github.com/go-git/go-billy/v5 v5.3.1 // indirect
618
github.com/google/go-cmp v0.5.5 // indirect
7-
github.com/stretchr/testify v1.4.0
8-
golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a // indirect
9-
golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 // indirect
10-
golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect
11-
gopkg.in/src-d/go-git.v4 v4.13.1
19+
github.com/imdario/mergo v0.3.12 // indirect
20+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
21+
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
22+
github.com/mitchellh/go-homedir v1.1.0 // indirect
23+
github.com/pmezard/go-difflib v1.0.0 // indirect
24+
github.com/sergi/go-diff v1.1.0 // indirect
25+
github.com/xanzy/ssh-agent v0.3.0 // indirect
26+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
27+
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
28+
golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 // indirect
29+
gopkg.in/warnings.v0 v0.1.2 // indirect
30+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
1231
)

0 commit comments

Comments
 (0)