From 02327e13b6fd260c85d1863f615b637d4bc74c5a Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Wed, 7 Nov 2018 04:02:18 -0500 Subject: [PATCH 1/3] Makefile OS compatibility update --- Makefile | 42 ++++++++++++++++++++++++------------------ PENDING.md | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index af4ea71c9887..61ce09976756 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,9 @@ PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation') PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') -VERSION := $(shell git describe --tags --long | sed 's/v\(.*\)/\1/') -BUILD_TAGS = netgo ledger +VERSION := $(subst v,,$(shell git describe --tags --long)) +BUILD_TAGS = netgo BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION}" -GCC := $(shell command -v gcc 2> /dev/null) LEDGER_ENABLED ?= true -UNAME_S := $(shell uname -s) GOTOOLS = \ github.com/golang/dep/cmd/dep \ github.com/alecthomas/gometalinter \ @@ -20,23 +18,31 @@ ci: get_tools get_vendor_deps install test_cover test_lint test ######################################## ### Build/Install -check-ledger: +# Add ledger support - Makefile variable changes are out of a target's scope. There is no point in putting this into a target. ifeq ($(LEDGER_ENABLED),true) - ifeq ($(UNAME_S),OpenBSD) - $(info "OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)") -TMP_BUILD_TAGS := $(BUILD_TAGS) -BUILD_TAGS = $(filter-out ledger, $(TMP_BUILD_TAGS)) - else - ifndef GCC - $(error "gcc not installed for ledger support, please install or set LEDGER_ENABLED to false in the Makefile") - endif - endif -else -TMP_BUILD_TAGS := $(BUILD_TAGS) -BUILD_TAGS = $(filter-out ledger, $(TMP_BUILD_TAGS)) + ifeq ($(OS),Windows_NT) + GCCEXE = $(shell where gcc.exe 2> NUL) + ifeq ($(GCCEXE),) + $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + BUILD_TAGS += ledger + endif + else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S),OpenBSD) + $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) + else + GCC = $(shell command -v gcc 2> /dev/null) + ifeq ($(GCC),) + $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + BUILD_TAGS += ledger + endif + endif + endif endif -build: check-ledger update_gaia_lite_docs +build: ifeq ($(OS),Windows_NT) go build $(BUILD_FLAGS) -o build/gaiad.exe ./cmd/gaia/cmd/gaiad go build $(BUILD_FLAGS) -o build/gaiacli.exe ./cmd/gaia/cmd/gaiacli diff --git a/PENDING.md b/PENDING.md index 7a4f32a62b9a..6b0813c2c169 100644 --- a/PENDING.md +++ b/PENDING.md @@ -41,6 +41,7 @@ IMPROVEMENTS * Gaia - #2637 [x/gov] Switched inactive and active proposal queues to an iterator based queue + - #2672 [Makefile] Updated for better Windows compatibility and ledger support logic * SDK - \#2573 [x/distribution] add accum invariance From 74549faac9712b975e29af1e6f5e978bee64653a Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Wed, 7 Nov 2018 22:42:43 -0500 Subject: [PATCH 2/3] Cross-compiling get_tools Makefile added --- Makefile | 4 ++-- PENDING.md | 2 +- scripts/Makefile | 54 ++++++++++++++++++++++++++++++++++++++++++++ scripts/get_tools.sh | 49 ---------------------------------------- 4 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 scripts/Makefile delete mode 100755 scripts/get_tools.sh diff --git a/Makefile b/Makefile index 61ce09976756..687eec1517ff 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ check_tools: update_tools: @echo "--> Updating tools to correct version" - ./scripts/get_tools.sh + $(MAKE) -C scripts get_tools update_dev_tools: @echo "--> Downloading linters (this may take awhile)" @@ -116,7 +116,7 @@ update_dev_tools: get_tools: @echo "--> Installing tools" - ./scripts/get_tools.sh + $(MAKE) -C scripts get_tools get_dev_tools: @echo "--> Downloading linters (this may take awhile)" diff --git a/PENDING.md b/PENDING.md index 6b0813c2c169..f0ffa8fcf2d8 100644 --- a/PENDING.md +++ b/PENDING.md @@ -41,7 +41,7 @@ IMPROVEMENTS * Gaia - #2637 [x/gov] Switched inactive and active proposal queues to an iterator based queue - - #2672 [Makefile] Updated for better Windows compatibility and ledger support logic + - #2672 [Makefile] Updated for better Windows compatibility and ledger support logic, get_tools was rewritten as a cross-compatible Makefile. * SDK - \#2573 [x/distribution] add accum invariance diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 000000000000..9abc497e45d4 --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,54 @@ +### +# 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 + +### +# Functions +### + +go_get = $(if $(findstring Windows_NT,$(OS)),\ +IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\ +IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\ +,\ +mkdir -p $(GITHUBDIR)$(FS)$(1) &&\ +(test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\ +)\ +cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3) + +go_install = $(call go_get,$(1),$(2),$(3)) && cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && $(GO) install + +### +# get_tools +### +all: get_tools +get_tools: dep gometalinter statik + +dep: + $(call go_get,golang,dep,22125cfaa6ddc71e145b1535d4b7ee9744fefff2) + cd $(GITHUBDIR)$(FS)golang$(FS)dep$(FS)cmd$(FS)dep && $(GO) install + +#v2.0.11 +gometalinter: + $(call go_install,alecthomas,gometalinter,17a7ffa42374937bfecabfb8d2efbd4db0c26741) + +statik: + $(call go_install,rakyll,statik,v0.1.5) + +.PHONY: all get_tools dep gometalinter statik + diff --git a/scripts/get_tools.sh b/scripts/get_tools.sh deleted file mode 100755 index 79ab32deca5d..000000000000 --- a/scripts/get_tools.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This file downloads all of the binary dependencies we have, and checks out a -# specific git hash. -# -# repos it installs: -# github.com/golang/dep/cmd/dep -# gopkg.in/alecthomas/gometalinter.v2 -# github.com/rakyll/statiik - -## check if GOPATH is set -if [ -z ${GOPATH+x} ]; then - echo "please set GOPATH (https://github.com/golang/go/wiki/SettingGOPATH)" - exit 1 -fi - -mkdir -p "$GOPATH/src/github.com" -cd "$GOPATH/src/github.com" || exit 1 - -installFromGithub() { - repo=$1 - commit=$2 - # optional - subdir=$3 - echo "--> Installing $repo ($commit)..." - if [ ! -d "$repo" ]; then - mkdir -p "$repo" - git clone "https://github.com/$repo.git" "$repo" - fi - if [ ! -z ${subdir+x} ] && [ ! -d "$repo/$subdir" ]; then - echo "ERROR: no such directory $repo/$subdir" - exit 1 - fi - pushd "$repo" && \ - git fetch origin && \ - git checkout -q "$commit" && \ - if [ ! -z ${subdir+x} ]; then cd "$subdir" || exit 1; fi && \ - go install && \ - if [ ! -z ${subdir+x} ]; then cd - || exit 1; fi && \ - popd || exit 1 - echo "--> Done" - echo "" -} - -installFromGithub golang/dep 22125cfaa6ddc71e145b1535d4b7ee9744fefff2 cmd/dep -## gometalinter v2.0.11 -installFromGithub alecthomas/gometalinter 17a7ffa42374937bfecabfb8d2efbd4db0c26741 -installFromGithub rakyll/statik v0.1.5 \ No newline at end of file From 9bbd3e37112b52cb1b4b50cc8a1bdc0221a254e0 Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Thu, 8 Nov 2018 10:20:14 -0500 Subject: [PATCH 3/3] Removed comment from Makefile as per bez's request --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 687eec1517ff..62e145738ffc 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,6 @@ ci: get_tools get_vendor_deps install test_cover test_lint test ######################################## ### Build/Install -# Add ledger support - Makefile variable changes are out of a target's scope. There is no point in putting this into a target. ifeq ($(LEDGER_ENABLED),true) ifeq ($(OS),Windows_NT) GCCEXE = $(shell where gcc.exe 2> NUL)