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

fix(build): preserve the GOFLAGS environment variable #7903

Closed
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ipfs/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH := $(realpath $(d)):$(PATH)
# DEPS_OO_$(d) += merkledag/pb/merkledag.pb.go namesys/pb/namesys.pb.go
# DEPS_OO_$(d) += pin/internal/pb/header.pb.go unixfs/pb/unixfs.pb.go

$(d)_flags =-ldflags="-X "github.com/ipfs/go-ipfs".CurrentCommit=$(git-hash)"
$(d)_flags =-ldflags=-X="github.com/ipfs/go-ipfs.CurrentCommit=$(git-hash)"

$(d)-try-build $(IPFS_BIN_$(d)): GOFLAGS += $(cmd/ipfs_flags)

Expand Down
29 changes: 13 additions & 16 deletions mk/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ GOCC ?= go
GOTAGS ?=
GOTFLAGS ?=

# Unexport GOFLAGS so we only apply it where we actually want it.
unexport GOFLAGS
# Override so we can combine with the user's go flags.
# Try to make building as reproducible as possible by stripping the go path.
override GOFLAGS += "-asmflags=all='-trimpath=$(GOPATH)'" "-gcflags=all='-trimpath=$(GOPATH)'"

go-global-flags :=
ifeq ($(tarball-is),1)
GOFLAGS += -mod=vendor
go-global-flags += -mod=vendor
endif

# match Go's default GOPATH behaviour
Expand All @@ -26,28 +21,30 @@ TEST_GO :=
TEST_GO_BUILD :=
CHECK_GO :=

go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
# Go tags cannot be set in GOFLAGS.
go-tags-flag=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
# These flags _may_ contain spaces so we can't use GOFLAGS either.
go-build-flags=$(go-global-flags) "-asmflags=all='-trimpath=$(GOPATH)'" "-gcflags=all='-trimpath=$(GOPATH)'" $(go-tags-flag)

# ignores GOFLAGS...
go-pkg-name=$(shell $(GOCC) list $(go-build-flags) github.com/ipfs/go-ipfs/$(1))
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
go-pkgs=$(shell $(GOCC) list github.com/ipfs/go-ipfs/...)

go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
go-flags-with-tags=$(GOFLAGS)$(go-tags)

define go-build-relative
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(call go-pkg-name,$<)"
$(GOCC) build $(go-build-flags) -o "$@" "$(call go-pkg-name,$<)"
endef

define go-build
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(1)"
$(GOCC) build $(go-build-flags) -o "$@" "$(1)"
endef

define go-try-build
$(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
$(GOCC) build $(go-build-flags) -o /dev/null "$(call go-pkg-name,$<)"
endef

test_go_test: $$(DEPS_GO)
$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
$(GOCC) test $(go-build-flags) $(GOTFLAGS) ./...
.PHONY: test_go_test

test_go_build: $$(TEST_GO_BUILD)
Expand Down
2 changes: 1 addition & 1 deletion plugin/loader/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export IPFS_PLUGINS
$(d)/preload.go: d:=$(d)
$(d)/preload.go: $(d)/preload_list $(d)/preload.sh ALWAYS
$(d)/preload.sh > $@
go fmt $@ >/dev/null
$(GOCC) fmt $(go-global-flags) $@ >/dev/null

DEPS_GO += $(d)/preload.go

Expand Down
2 changes: 1 addition & 1 deletion plugin/plugins/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins))
$($(d)_plugins_main): d:=$(d)
$($(d)_plugins_main):
$(d)/gen_main.sh "$(dir $@).." "$(call go-pkg-name,$(dir $@)/..)"
$(GOCC) fmt $@ >/dev/null
$(GOCC) fmt $(go-global-flags) $@ >/dev/null

$($(d)_plugins_so): %.so : %/main/main.go
$($(d)_plugins_so): $$(DEPS_GO) ALWAYS
Expand Down