Skip to content

Commit

Permalink
Extend Makefile with protoc
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed May 15, 2024
1 parent d3b364b commit 4158607
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin/

*.swp
.idea
*.qlog
Expand Down
42 changes: 39 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
export GOBIN := $(abspath .)/bin
export PATH := $(GOBIN):$(PATH)

.PHONY: install
install:
ifeq ($(OS),Windows_NT)
UNAME_OS := windows
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
UNAME_ARCH := x86_64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),ARM64)
UNAME_ARCH := aarch64
endif
PROTOC_BUILD := win64

BIN_DIR := $(abspath .)/bin
export PATH := $(BIN_DIR);$(PATH)
TMP_PROTOC := $(TEMP)/protoc-$(RANDOM)
else
UNAME_OS := $(shell uname -s)
UNAME_ARCH := $(shell uname -m)
PROTOC_BUILD := $(shell echo ${UNAME_OS}-${UNAME_ARCH} | tr '[:upper:]' '[:lower:]' | sed 's/darwin/osx/' | sed 's/arm64/aarch_64/' | sed 's/aarch64/aarch_64/')

BIN_DIR := $(abspath .)/bin
export PATH := $(BIN_DIR):$(PATH)
TMP_PROTOC := $(shell mktemp -d)
endif

.PHONY: install-protoc
install-protoc: protoc-plugins
@mkdir -p $(BIN_DIR)
ifeq ($(OS),Windows_NT)
@mkdir -p $(TMP_PROTOC)
endif
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v26.0/protoc-26.0-${PROTOC_BUILD}.zip -o $(TMP_PROTOC)/protoc.zip
@unzip $(TMP_PROTOC)/protoc.zip -d $(TMP_PROTOC)
@cp -f $(TMP_PROTOC)/bin/protoc $(BIN_DIR)/protoc
@chmod +x $(BIN_DIR)/protoc

protoc-plugins:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.0

.PHONY: install
install: install-protoc
go install go.uber.org/mock/mockgen@v0.4.0

.PHONY: generate
generate: install
generate:
go generate ./...
2 changes: 1 addition & 1 deletion core/crypto/pb/crypto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 0 additions & 67 deletions core/network/mocks/gomock_reflect_27034970/prog.go

This file was deleted.

12 changes: 6 additions & 6 deletions core/network/mocks/network.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mocknetwork

//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager"
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope"
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope"
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope"
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope"
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan"
//go:generate mockgen -package mocknetwork -destination mock_resource_manager.go github.com/libp2p/go-libp2p/core/network ResourceManager
//go:generate mockgen -package mocknetwork -destination mock_conn_management_scope.go github.com/libp2p/go-libp2p/core/network ConnManagementScope
//go:generate mockgen -package mocknetwork -destination mock_stream_management_scope.go github.com/libp2p/go-libp2p/core/network StreamManagementScope
//go:generate mockgen -package mocknetwork -destination mock_peer_scope.go github.com/libp2p/go-libp2p/core/network PeerScope
//go:generate mockgen -package mocknetwork -destination mock_protocol_scope.go github.com/libp2p/go-libp2p/core/network ProtocolScope
//go:generate mockgen -package mocknetwork -destination mock_resource_scope_span.go github.com/libp2p/go-libp2p/core/network ResourceScopeSpan
2 changes: 1 addition & 1 deletion core/peer/pb/peer_record.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/record/pb/envelope.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/sec/insecure/pb/plaintext.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/host/autonat/pb/autonat.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/host/basic/mock_nat_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions p2p/host/basic/mocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//go:build gomock || generate

package basichost

//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -build_flags=\"-tags=gomock\" -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT"
//go:generate mockgen -package basichost -destination mock_nat_test.go github.com/libp2p/go-libp2p/p2p/host/basic NAT
type NAT nat
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/pb/pstore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/host/pstoremanager/pstoremanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.uber.org/mock/gomock"
)

//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore"
//go:generate mockgen -package pstoremanager_test -destination mock_peerstore_test.go github.com/libp2p/go-libp2p/core/peerstore Peerstore

func TestGracePeriod(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/nat/nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"go.uber.org/mock/gomock"
)

//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT"
//go:generate mockgen -package nat -destination mock_nat_test.go github.com/libp2p/go-nat NAT

func setupMockNAT(t *testing.T) (mockNAT *MockNAT, reset func()) {
t.Helper()
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/circuitv2/pb/circuit.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/protocol/circuitv2/pb/voucher.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/protocol/holepunch/pb/holepunch.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/protocol/identify/pb/identify.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/security/noise/pb/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/test/transport/gating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.uber.org/mock/gomock"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater
//go:generate mockgen -package transport_integration -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater

func stripCertHash(addr ma.Multiaddr) ma.Multiaddr {
for {
Expand Down
2 changes: 1 addition & 1 deletion p2p/test/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func TestMoreStreamsThanOurLimits(t *testing.T) {
var err error
// maxRetries is an arbitrary retry amount if there's any error.
maxRetries := streamCount * 4
shouldRetry := func(err error) bool {
shouldRetry := func(error) bool {
didErr = true
sawFirstErr.Store(true)
maxRetries--
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/quic/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"go.uber.org/mock/gomock"
)

//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports@v0.20.0 -w mock_connection_gater_test.go"
//go:generate mockgen -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater

type connTestCase struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webrtc/pb/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestResourceManagerListening(t *testing.T) {
}

// TODO: unify somehow. We do the same in libp2pquic.
//go:generate sh -c "go run go.uber.org/mock/mockgen@v0.4.0 -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports@v0.20.0 -w mock_connection_gater_test.go"
//go:generate mockgen -package libp2pwebtransport_test -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater

func TestConnectionGaterDialing(t *testing.T) {
ctrl := gomock.NewController(t)
Expand Down

0 comments on commit 4158607

Please sign in to comment.