This repository was archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
add version command to give dep
's version
#51
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dep | ||
dep | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Set an output prefix, which is the local directory if not specified | ||
PREFIX?=$(shell pwd) | ||
|
||
# Setup name variables for the package/tool | ||
NAME := dep | ||
PKG := github.com/golang/$(NAME) | ||
|
||
# Set any default go build tags | ||
BUILDTAGS := | ||
|
||
# Set the build dir, where built cross-compiled binaries will be output | ||
BUILDDIR := ${PREFIX}/build | ||
|
||
# Populate version variables | ||
# Add to compile time flags | ||
VERSION := $(shell cat VERSION) | ||
GITCOMMIT := $(shell git rev-parse --short HEAD) | ||
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no) | ||
ifneq ($(GITUNTRACKEDCHANGES),) | ||
GITCOMMIT := $(GITCOMMIT)-dirty | ||
endif | ||
CTIMEVAR=-X main.GITCOMMIT=$(GITCOMMIT) -X main.VERSION=$(VERSION) | ||
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)" | ||
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static" | ||
|
||
# List the GOOS and GOARCH to build | ||
GOOSARCHES = darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 linux/arm linux/arm64 linux/amd64 linux/386 solaris/amd64 windows/amd64 windows/386 | ||
|
||
.PHONY: build | ||
build: $(NAME) ## Builds a dynamic executable | ||
|
||
$(NAME): *.go VERSION | ||
@echo "+ $@" | ||
go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) . | ||
|
||
.PHONY: static | ||
static: ## Builds a static executable | ||
@echo "+ $@" | ||
CGO_ENABLED=0 go build \ | ||
-tags "$(BUILDTAGS) static_build" \ | ||
${GO_LDFLAGS_STATIC} -o $(NAME) . | ||
|
||
define buildrelease | ||
mkdir -p $(BUILDDIR)/$(1)/$(2); | ||
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \ | ||
-o $(BUILDDIR)/$(1)/$(2)/$(NAME) \ | ||
-a -tags "$(BUILDTAGS) static_build netgo" \ | ||
-installsuffix netgo ${GO_LDFLAGS_STATIC} .; | ||
endef | ||
|
||
.PHONY: cross | ||
cross: *.go VERSION ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary) | ||
@echo "+ $@" | ||
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)))) | ||
|
||
.PHONY: clean | ||
clean: ## Cleanup any build binaries | ||
@echo "+ $@" | ||
$(RM) $(NAME) | ||
$(RM) -r $(BUILDDIR) | ||
|
||
.PHONY: help | ||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
// VERSION indicates which version of the binary is running. | ||
VERSION string | ||
|
||
// GITCOMMIT indicates which git hash the binary was built off of | ||
GITCOMMIT string | ||
) | ||
|
||
var versionCmd = &command{ | ||
fn: runVersion, | ||
name: "version", | ||
short: ` | ||
Version prints the version, git commit, runtime OS and ARCH. | ||
`, | ||
long: `Version prints the version, git commit, runtime OS and ARCH.`, | ||
} | ||
|
||
func runVersion(args []string) error { | ||
fmt.Printf("dep version %s %s %s/%s\n", VERSION, GITCOMMIT, runtime.GOOS, runtime.GOARCH) | ||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment that describes what this does.