Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tools.go #2781

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/actions/go-check-setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: go check setup
description: prepares environment for go-check workflow

runs:
using: "composite"
steps:
- name: Install Protoc
uses: trail-of-forks/setup-protoc@a97892a429d98fae78d26f40334ab7eb616d08b9 # include https://github.com/arduino/setup-protoc/pull/58
with:
version: '21.12'
repo-token: ${{ github.token }}
- name: Install Protobuf compiler
- name: Install tools
shell: bash
run: go install google.golang.org/protobuf/cmd/protoc-gen-go
run: cd tools; make install
- name: Set env
shell: bash
run: echo "PATH=$PWD/tools/bin:$PATH" >> $GITHUB_ENV
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tools/bin/

*.swp
.idea
*.qlog
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/pb/crypto.pb.go

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

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 -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 -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 -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 -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 -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 -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
4 changes: 2 additions & 2 deletions core/peer/pb/peer_record.pb.go

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

4 changes: 2 additions & 2 deletions core/record/pb/envelope.pb.go

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

4 changes: 2 additions & 2 deletions 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ require (
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/tools v0.21.0
google.golang.org/protobuf v1.34.1
)

Expand Down Expand Up @@ -123,6 +122,7 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions 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 -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
4 changes: 2 additions & 2 deletions 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 -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 -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
4 changes: 2 additions & 2 deletions p2p/protocol/circuitv2/pb/circuit.pb.go

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

4 changes: 2 additions & 2 deletions p2p/protocol/circuitv2/pb/voucher.pb.go

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

4 changes: 2 additions & 2 deletions p2p/protocol/holepunch/pb/holepunch.pb.go

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

4 changes: 2 additions & 2 deletions p2p/protocol/identify/pb/identify.pb.go

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

4 changes: 2 additions & 2 deletions 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 -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 -package libp2pquic -destination mock_connection_gater_test.go github.com/libp2p/go-libp2p/core/connmgr ConnectionGater && go run golang.org/x/tools/cmd/goimports -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
4 changes: 2 additions & 2 deletions 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 -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 -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
9 changes: 0 additions & 9 deletions tools.go

This file was deleted.

47 changes: 47 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export GOBIN := $(abspath .)/bin
export PATH := $(GOBIN):$(PATH)

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:
cd .. && go generate ./...
Loading