Skip to content

Commit

Permalink
Merge pull request #44 from desmos-labs/riccardo/makefile-improvements
Browse files Browse the repository at this point in the history
Makefile improvements
  • Loading branch information
kwunyeung authored Nov 21, 2019
2 parents 8fdb136 + eb4859b commit d3f8199
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 28 deletions.
36 changes: 23 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
#!/usr/bin/make -f

PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin

export GO111MODULE = on

include Makefile.ledger
include contrib/devtools/Makefile

########################################
### Build flags

ifneq ($(GOSUM),)
ldflags += -X github.com/cosmos/cosmos-sdk/version.VendorDirHash=$(shell $(GOSUM) go.sum)
endif

ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

# process linker flags
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

# Process linker flags
ldflags = -X "github.com/cosmos/cosmos-sdk/version.Name=Desmos" \
-X "github.com/cosmos/cosmos-sdk/version.ServerName=desmosd" \
-X "github.com/cosmos/cosmos-sdk/version.ClientName=desmoscli" \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)"

ifneq ($(GOSUM),)
ldflags += -X github.com/cosmos/cosmos-sdk/version.VendorDirHash=$(shell $(GOSUM) go.sum)
endif

ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

########################################
### All

all: lint install

########################################
Expand Down Expand Up @@ -70,10 +79,11 @@ go.sum: go.mod
@go mod verify
@go mod tidy

lint:
golangci-lint run
lint: golangci-lint
$(BINDIR)/golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify
.PHONY: lint

########################################
### Testing
Expand Down
2 changes: 0 additions & 2 deletions Makefile.ledger
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
LEDGER_ENABLED ?= true

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
Expand Down
52 changes: 52 additions & 0 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
###
# Find OS and Go environment
# GO contains the Go binary
# FS contains the OS file separator
###
ifeq ($(OS),Windows_NT)
GO := $(shell where go.exe 2> NUL)
FS := "\\"
else
GO := $(shell command -v go 2> /dev/null)
FS := "/"
endif

ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif

GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
GOLANGCI_LINT_HASHSUM := 8d21cc95da8d3daf8321ac40091456fc26123c964d7c2281d339d431f2f4c840

###
# Functions
###

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)

###
# tools
###

TOOLS_DESTDIR ?= $(GOPATH)/bin

GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint

all: tools

tools: golangci-lint

golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(mkfile_dir)/install-golangci-lint.sh
@echo "Installing golangci-lint..."
@bash $(mkfile_dir)/install-golangci-lint.sh $(TOOLS_DESTDIR) $(GOLANGCI_LINT_HASHSUM)



tools-clean:
rm -f $(GOLANGCI_LINT)
rm -f tools-stamp

.PHONY: all tools tools-clean
33 changes: 33 additions & 0 deletions contrib/devtools/install-golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -euo pipefail

installer="$(mktemp)"
trap "rm -f ${installer}" EXIT

GOBIN="${1}"
CURL="$(which curl)"
HASHSUM="${2}"

f_sha256() {
local l_file
l_file=$1
python -sBc "import hashlib;print(hashlib.sha256(open('$l_file','rb').read()).hexdigest())"
}

get_latest_release() {
"${CURL}" --silent "https://api.github.com/repos/$1/releases/latest" | \
grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}

VERSION="$(get_latest_release golangci/golangci-lint)"

echo "Downloading golangci-lint ${VERSION} installer ..." >&2
"${CURL}" -sfL "https://raw.githubusercontent.com/golangci/golangci-lint/${VERSION}/install.sh" > "${installer}"

echo "Checking hashsum ..." >&2
[ "${HASHSUM}" = "$(f_sha256 ${installer})" ]
chmod +x "${installer}"

echo "Launching installer ..." >&2
exec "${installer}" -d -b "${GOBIN}" "${VERSION}"
6 changes: 3 additions & 3 deletions x/magpie/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func TestKeeper_SaveSession(t *testing.T) {
k.Cdc.MustUnmarshalBinaryBare(store.Get([]byte(types.SessionStorePrefix+session.SessionID.String())), &stored)
assert.Equal(t, session, stored)

var storedLastId types.SessionID
k.Cdc.MustUnmarshalBinaryBare(store.Get([]byte(types.LastSessionIDStoreKey)), &storedLastId)
assert.Equal(t, session.SessionID, storedLastId)
var storedLastID types.SessionID
k.Cdc.MustUnmarshalBinaryBare(store.Get([]byte(types.LastSessionIDStoreKey)), &storedLastID)
assert.Equal(t, session.SessionID, storedLastID)
}

func TestKeeper_GetSession(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion x/magpie/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package types

import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// MsgCreateSession defines the MsgCreateSession message
Expand Down
3 changes: 2 additions & 1 deletion x/magpie/internal/types/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package types_test

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/x/magpie/internal/types"
"github.com/stretchr/testify/assert"
"testing"
)

// ------------------
Expand Down
1 change: 1 addition & 0 deletions x/posts/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (k Keeper) GetPosts(ctx sdk.Context) []types.Post {
// SaveLike allows to save the given like inside the store.
// It assumes that the given like is valid.
// If another like from the same owner and for the same post exists, returns an error.
// nolint: interfacer
func (k Keeper) SaveLike(ctx sdk.Context, postID types.PostID, like types.Like) sdk.Error {
store := ctx.KVStore(k.StoreKey)
key := []byte(types.LikesStorePrefix + postID.String())
Expand Down
12 changes: 6 additions & 6 deletions x/posts/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestKeeper_GetLastPostId(t *testing.T) {
tests := []struct {
name string
existingId types.PostID
existingID types.PostID
expected types.PostID
}{
{
Expand All @@ -24,7 +24,7 @@ func TestKeeper_GetLastPostId(t *testing.T) {
},
{
name: "Existing ID returns correct value",
existingId: types.PostID(3),
existingID: types.PostID(3),
expected: types.PostID(3),
},
}
Expand All @@ -34,9 +34,9 @@ func TestKeeper_GetLastPostId(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
ctx, k := SetupTestInput()

if test.existingId.Valid() {
if test.existingID.Valid() {
store := ctx.KVStore(k.StoreKey)
store.Set([]byte(types.LastPostIDStoreKey), k.Cdc.MustMarshalBinaryBare(test.existingId))
store.Set([]byte(types.LastPostIDStoreKey), k.Cdc.MustMarshalBinaryBare(test.existingID))
}

actual := k.GetLastPostID(ctx)
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestKeeper_GetPosts(t *testing.T) {

store := ctx.KVStore(k.StoreKey)
for _, p := range test.posts {
store.Set([]byte(types.PostStorePrefix+p.PostID.String()), k.Cdc.MustMarshalBinaryBare(&p))
store.Set([]byte(types.PostStorePrefix+p.PostID.String()), k.Cdc.MustMarshalBinaryBare(p))
}

posts := k.GetPosts(ctx)
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestKeeper_GetLikes(t *testing.T) {
ctx, k := SetupTestInput()
store := ctx.KVStore(k.StoreKey)
for postID, likes := range test.likes {
store.Set([]byte(types.LikesStorePrefix+postID.String()), k.Cdc.MustMarshalBinaryBare(&likes))
store.Set([]byte(types.LikesStorePrefix+postID.String()), k.Cdc.MustMarshalBinaryBare(likes))
}

likesData := k.GetLikes(ctx)
Expand Down
4 changes: 2 additions & 2 deletions x/posts/internal/types/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ type Post struct {
Owner sdk.AccAddress `json:"owner"`
}

func NewPost(ID, parentID PostID, message string, created int64, owner sdk.AccAddress) Post {
func NewPost(id, parentID PostID, message string, created int64, owner sdk.AccAddress) Post {
return Post{
PostID: ID,
PostID: id,
ParentID: parentID,
Message: message,
Created: created,
Expand Down

0 comments on commit d3f8199

Please sign in to comment.