Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit b5af0d8

Browse files
authored
build, vendor: use go modules for vendoring (#1532)
1 parent b635061 commit b5af0d8

File tree

606 files changed

+58954
-13742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

606 files changed

+58954
-13742
lines changed

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
linters-settings:
2+
goconst:
3+
# minimal length of string constant, 3 by default
4+
min-len: 3
5+
# minimal occurrences count to trigger, 3 by default
6+
min-occurrences: 5
7+
8+
issues:
9+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
10+
max-issues-per-linter: 0
11+
12+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
13+
max-same-issues: 0

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
language: go
22
go_import_path: github.com/ethersphere/swarm
33
sudo: false
4+
env:
5+
global:
6+
- GO111MODULE=on
7+
- GOFLAGS=-mod=vendor
48
branches:
59
only:
610
- master

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ swarm:
1111

1212
alltools:
1313
build/env.sh go run build/ci.go install ./cmd/...
14+
15+
# Wrap go modules vendor command to copy forked cgo libraries
16+
# from go module cache and correct their file permissons.
17+
.PHONY: vendor
18+
vendor: export GO111MODULE=on
19+
vendor:
20+
@go mod vendor
21+
@cp -rf "$(shell GO111MODULE=on go list -f {{.Dir}} github.com/karalabe/hid)/hidapi" vendor/github.com/karalabe/hid/hidapi
22+
@chmod -R u+w vendor/github.com/karalabe/hid/hidapi
23+
@cp -rf "$(shell GO111MODULE=on go list -f {{.Dir}} github.com/karalabe/hid)/libusb" vendor/github.com/karalabe/hid/libusb
24+
@chmod -R u+w vendor/github.com/karalabe/hid/libusb
25+
@cp -rf "$(shell GO111MODULE=on go list -f {{.Dir}} github.com/ethereum/go-ethereum/crypto/secp256k1)/libsecp256k1" vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1
26+
@chmod -R u+w vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ $ git clone [email protected]:nirname/swarm.git $GOPATH/src/github.com/ethersphere/
189189

190190
### Vendored Dependencies
191191

192-
All dependencies are tracked in the `vendor` directory. We use `govendor` to manage them.
192+
All dependencies are tracked in the `vendor` directory. We use `go mod` to manage depenedencies, except for `go mod vendor` command. Vendoring is done by Makefile rule `make vendor` which uses `go mod vendor` and additionally copies cgo dependencies into `vendor` directory from go modules cache.
193193

194-
If you want to add a new dependency, run `govendor fetch <import-path>`, then commit the result.
194+
If you want to add a new dependency, run `GO111MODULE=on go get <import-path>`, vendor it `make vednor`, then commit the result.
195195

196-
If you want to update all dependencies to their latest upstream version, run `govendor fetch +v`.
196+
If you want to update all dependencies to their latest upstream version, run `GO111MODULE=on go get -u all` and vendor them with `make vendor`.
197197

198198

199199
### Testing

api/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func checkResponse(t *testing.T, resp *testResponse, exp *Response) {
9696
}
9797
if resp.Content != exp.Content {
9898
// if !bytes.Equal(resp.Content, exp.Content)
99-
t.Errorf("incorrect content. expected '%s...', got '%s...'", string(exp.Content), string(resp.Content))
99+
t.Errorf("incorrect content. expected '%s...', got '%s...'", exp.Content, resp.Content)
100100
}
101101
}
102102

api/http/middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func InitUploadTag(h http.Handler, tags *chunk.Tags) http.Handler {
113113
uri := GetURI(r.Context())
114114
if uri != nil {
115115
log.Debug("got uri from context")
116-
if uri.Addr == "encrypt" {
116+
if uri.Addr == encryptAddr {
117117
estimatedTotal = calculateNumberOfChunks(r.ContentLength, true)
118118
} else {
119119
estimatedTotal = calculateNumberOfChunks(r.ContentLength, false)
@@ -138,7 +138,7 @@ func InitUploadTag(h http.Handler, tags *chunk.Tags) http.Handler {
138138
func InstrumentOpenTracing(h http.Handler) http.Handler {
139139
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
140140
uri := GetURI(r.Context())
141-
if uri == nil || r.Method == "" || (uri != nil && uri.Scheme == "") {
141+
if uri == nil || r.Method == "" || uri.Scheme == "" {
142142
h.ServeHTTP(w, r) // soft fail
143143
return
144144
}

api/http/server.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ var (
6767
const (
6868
SwarmTagHeaderName = "x-swarm-tag" // Presence of this in header indicates the tag
6969
PinHeaderName = "x-swarm-pin" // Presence of this in header indicates pinning required
70+
71+
encryptAddr = "encrypt"
72+
tarContentType = "application/x-tar"
7073
)
7174

7275
type methodHandler map[string]http.Handler
@@ -193,7 +196,7 @@ type Server struct {
193196

194197
func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request) {
195198
log.Debug("handleBzzGet", "ruid", GetRUID(r.Context()), "uri", r.RequestURI)
196-
if r.Header.Get("Accept") == "application/x-tar" {
199+
if r.Header.Get("Accept") == tarContentType {
197200
uri := GetURI(r.Context())
198201
_, credentials, _ := r.BasicAuth()
199202
reader, err := s.api.GetDirectoryTar(r.Context(), s.api.Decryptor(r.Context(), credentials), uri)
@@ -208,7 +211,7 @@ func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request) {
208211
}
209212
defer reader.Close()
210213

211-
w.Header().Set("Content-Type", "application/x-tar")
214+
w.Header().Set("Content-Type", tarContentType)
212215

213216
fileName := uri.Addr
214217
if found := path.Base(uri.Path); found != "" && found != "." && found != "/" {
@@ -256,7 +259,7 @@ func (s *Server) HandlePostRaw(w http.ResponseWriter, r *http.Request) {
256259

257260
toEncrypt := false
258261
uri := GetURI(r.Context())
259-
if uri.Addr == "encrypt" {
262+
if uri.Addr == encryptAddr {
260263
toEncrypt = true
261264
}
262265

@@ -269,7 +272,7 @@ func (s *Server) HandlePostRaw(w http.ResponseWriter, r *http.Request) {
269272
return
270273
}
271274

272-
if uri.Addr != "" && uri.Addr != "encrypt" {
275+
if uri.Addr != "" && uri.Addr != encryptAddr {
273276
postRawFail.Inc(1)
274277
respondError(w, r, "raw POST request addr can only be empty or \"encrypt\"", http.StatusBadRequest)
275278
return
@@ -327,15 +330,15 @@ func (s *Server) HandlePostFiles(w http.ResponseWriter, r *http.Request) {
327330

328331
toEncrypt := false
329332
uri := GetURI(r.Context())
330-
if uri.Addr == "encrypt" {
333+
if uri.Addr == encryptAddr {
331334
toEncrypt = true
332335
}
333336

334337
// Set the pinCounter if there is a pin header present in the request
335338
headerPin := r.Header.Get(PinHeaderName)
336339

337340
var addr storage.Address
338-
if uri.Addr != "" && uri.Addr != "encrypt" {
341+
if uri.Addr != "" && uri.Addr != encryptAddr {
339342
addr, err = s.api.Resolve(r.Context(), uri.Addr)
340343
if err != nil {
341344
postFilesFail.Inc(1)
@@ -354,7 +357,7 @@ func (s *Server) HandlePostFiles(w http.ResponseWriter, r *http.Request) {
354357
}
355358
newAddr, err := s.api.UpdateManifest(r.Context(), addr, func(mw *api.ManifestWriter) error {
356359
switch contentType {
357-
case "application/x-tar":
360+
case tarContentType:
358361
_, err := s.handleTarUpload(r, mw)
359362
if err != nil {
360363
respondError(w, r, fmt.Sprintf("error uploading tarball: %v", err), http.StatusInternalServerError)

api/http/server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestBzzWithFeed(t *testing.T) {
101101
`)
102102

103103
// POST data to bzz and get back a content-addressed **manifest hash** pointing to it.
104-
resp, err := http.Post(fmt.Sprintf("%s/bzz:/", srv.URL), "text/plain", bytes.NewReader([]byte(dataBytes)))
104+
resp, err := http.Post(fmt.Sprintf("%s/bzz:/", srv.URL), "text/plain", bytes.NewReader(dataBytes))
105105
if err != nil {
106106
t.Fatal(err)
107107
}
@@ -188,7 +188,7 @@ func TestBzzWithFeed(t *testing.T) {
188188
if err != nil {
189189
t.Fatal(err)
190190
}
191-
if !bytes.Equal(retrievedData, []byte(dataBytes)) {
191+
if !bytes.Equal(retrievedData, dataBytes) {
192192
t.Fatalf("retrieved data mismatch, expected %x, got %x", dataBytes, retrievedData)
193193
}
194194
}
@@ -746,7 +746,7 @@ func testBzzTar(encrypted bool, t *testing.T) {
746746
//post tar stream
747747
url := srv.URL + "/bzz:/"
748748
if encrypted {
749-
url = url + "encrypt"
749+
url = url + encryptAddr
750750
}
751751
req, err := http.NewRequest("POST", url, buf)
752752
if err != nil {
@@ -863,7 +863,7 @@ func TestBzzCorrectTagEstimate(t *testing.T) {
863863
defer cancel()
864864
addr := ""
865865
if v.toEncrypt {
866-
addr = "encrypt"
866+
addr = encryptAddr
867867
}
868868
req, err := http.NewRequest("POST", srv.URL+"/bzz:/"+addr, pr)
869869
if err != nil {

build/ci.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ func executablePath(name string) string {
109109
func main() {
110110
log.SetFlags(log.Lshortfile)
111111

112+
// Use modules in subcommands.
113+
os.Setenv("GO111MODULE", "on")
114+
goflgs := "-mod=vendor"
115+
if v := os.Getenv("GOFLAGS"); v != "" && v != "-mod=vendor" {
116+
goflgs = v + " " + goflgs
117+
}
118+
os.Setenv("GOFLAGS", goflgs)
119+
112120
if _, err := os.Stat(filepath.Join("build", "ci.go")); os.IsNotExist(err) {
113121
log.Fatal("this script must be run from the root of the repository")
114122
}
@@ -284,12 +292,13 @@ func doLint(cmdline []string) {
284292
packages = flag.CommandLine.Args()
285293
}
286294
// Get metalinter and install all supported linters
287-
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v2"))
288-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), "--install")
295+
lintcmd := goTool("get", "github.com/golangci/golangci-lint/cmd/golangci-lint")
296+
lintcmd.Env = append(lintcmd.Env, "GO111MODULE=off") // do not interfere with project modules
297+
build.MustRun(lintcmd)
289298

290299
// Run fast linters batched together
291300
configs := []string{
292-
"--vendor",
301+
"run",
293302
"--tests",
294303
"--deadline=2m",
295304
"--disable-all",
@@ -299,14 +308,16 @@ func doLint(cmdline []string) {
299308
"--enable=gofmt",
300309
"--enable=misspell",
301310
"--enable=goconst",
302-
"--min-occurrences=6", // for goconst
303311
}
304-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
312+
build.MustRunCommand(filepath.Join(GOBIN, "golangci-lint"), append(configs, packages...)...)
305313

306314
// Run slow linters one by one
307-
for _, linter := range []string{"unconvert", "gosimple"} {
308-
configs = []string{"--vendor", "--tests", "--deadline=10m", "--disable-all", "--enable=" + linter}
309-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
315+
for _, linter := range []string{
316+
"unconvert",
317+
"gosimple",
318+
} {
319+
configs = []string{"run", "--tests", "--deadline=10m", "--disable-all", "--enable=" + linter}
320+
build.MustRunCommand(filepath.Join(GOBIN, "golangci-lint"), append(configs, packages...)...)
310321
}
311322
}
312323

@@ -644,6 +655,7 @@ func doXgo(cmdline []string) {
644655

645656
// Make sure xgo is available for cross compilation
646657
gogetxgo := goTool("get", "github.com/karalabe/xgo")
658+
gogetxgo.Env = append(gogetxgo.Env, "GO111MODULE=off") // do not interfere with project modules
647659
build.MustRun(gogetxgo)
648660

649661
// If all tools building is requested, build everything the builder wants

build/env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ fi
2121
# Set up the environment to use the workspace.
2222
GOPATH="$workspace"
2323
export GOPATH
24+
export GO111MODULE=on
25+
export GOFLAGS=-mod=vendor
2426

2527
# Run the command inside the workspace.
2628
cd "$ethdir/swarm"

0 commit comments

Comments
 (0)