summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-06-02 17:57:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-06-02 17:59:12 +0900
commit83e9af6601f2a7b7fc0fff06fc6767b7054a5467 (patch)
treeac014e169ae994f3ff433f6b2476d0f352f153e8
parent8bbf9335e13f4d56fd7008757d4a9ead34e6381c (diff)
Add git revision to --version output
-rw-r--r--Makefile26
-rwxr-xr-xinstall2
-rw-r--r--main.go4
-rw-r--r--src/core.go8
4 files changed, 25 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 660af461..f2426e87 100644
--- a/Makefile
+++ b/Makefile
@@ -9,14 +9,19 @@ $(error "$$GOOS is not defined.")
endif
endif
-ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
+ROOT_DIR := $(shell dirname $(MAKEFILE))
GOPATH := $(ROOT_DIR)/gopath
SRC_LINK := $(GOPATH)/src/github.com/junegunn/fzf/src
VENDOR_LINK := $(GOPATH)/src/github.com/junegunn/fzf/vendor
+export GOPATH
GLIDE_YAML := glide.yaml
GLIDE_LOCK := glide.lock
-SOURCES := $(wildcard *.go src/*.go src/*/*.go) $(SRC_LINK) $(VENDOR_LINK) $(GLIDE_LOCK)
+SOURCES := $(wildcard *.go src/*.go src/*/*.go) $(SRC_LINK) $(VENDOR_LINK) $(GLIDE_LOCK) $(MAKEFILE)
+
+REVISION := $(shell git log -n 1 --pretty=format:%h -- $(SOURCES))
+BUILD_FLAGS := -a -ldflags "-X main.revision=$(REVISION) -w -extldflags=$(LDFLAGS)" -tags "$(TAGS)"
BINARY32 := fzf-$(GOOS)_386
BINARY64 := fzf-$(GOOS)_amd64
@@ -31,7 +36,6 @@ RELEASEARM5 := fzf-$(VERSION)-$(GOOS)_arm5
RELEASEARM6 := fzf-$(VERSION)-$(GOOS)_arm6
RELEASEARM7 := fzf-$(VERSION)-$(GOOS)_arm7
RELEASEARM8 := fzf-$(VERSION)-$(GOOS)_arm8
-export GOPATH
# https://en.wikipedia.org/wiki/Uname
UNAME_M := $(shell uname -m)
@@ -60,8 +64,8 @@ target:
ifeq ($(GOOS),windows)
release: target/$(BINARY32) target/$(BINARY64)
- cd target && cp -f $(BINARY32) fzf.exe && zip $(RELEASE32).zip bin/fzf.exe
- cd target && cp -f $(BINARY64) fzf.exe && zip $(RELEASE64).zip bin/fzf.exe
+ cd target && cp -f $(BINARY32) fzf.exe && zip $(RELEASE32).zip fzf.exe
+ cd target && cp -f $(BINARY64) fzf.exe && zip $(RELEASE64).zip fzf.exe
cd target && rm -f fzf.exe
else ifeq ($(GOOS),linux)
release: target/$(BINARY32) target/$(BINARY64) target/$(BINARYARM5) target/$(BINARYARM6) target/$(BINARYARM7) target/$(BINARYARM8)
@@ -110,23 +114,23 @@ clean:
rm -rf target
target/$(BINARY32): $(SOURCES)
- GOARCH=386 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=386 go build $(BUILD_FLAGS) -o $@
target/$(BINARY64): $(SOURCES)
- GOARCH=amd64 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=amd64 go build $(BUILD_FLAGS) -o $@
# https://github.com/golang/go/wiki/GoArm
target/$(BINARYARM5): $(SOURCES)
- GOARCH=arm GOARM=5 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=arm GOARM=5 go build $(BUILD_FLAGS) -o $@
target/$(BINARYARM6): $(SOURCES)
- GOARCH=arm GOARM=6 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=arm GOARM=6 go build $(BUILD_FLAGS) -o $@
target/$(BINARYARM7): $(SOURCES)
- GOARCH=arm GOARM=7 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=arm GOARM=7 go build $(BUILD_FLAGS) -o $@
target/$(BINARYARM8): $(SOURCES)
- GOARCH=arm64 go build -a -ldflags "-w -extldflags=$(LDFLAGS)" -tags "$(TAGS)" -o $@
+ GOARCH=arm64 go build $(BUILD_FLAGS) -o $@
bin/fzf: target/$(BINARY) | bin
cp -f target/$(BINARY) bin/fzf
diff --git a/install b/install
index 9a512076..516c4cb5 100755
--- a/install
+++ b/install
@@ -72,7 +72,7 @@ ask() {
check_binary() {
echo -n " - Checking fzf executable ... "
local output
- output=$("$fzf_base"/bin/fzf --version 2>&1)
+ output=$("$fzf_base"/bin/fzf --version 2>&1 | awk '{print $1}')
if [ $? -ne 0 ]; then
echo "Error: $output"
binary_error="Invalid binary"
diff --git a/main.go b/main.go
index 29d4767c..3b59244d 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,8 @@ package main
import "github.com/junegunn/fzf/src"
+var revision string
+
func main() {
- fzf.Run(fzf.ParseOptions())
+ fzf.Run(fzf.ParseOptions(), revision)
}
diff --git a/src/core.go b/src/core.go
index 2b91ab6e..6c3b321e 100644
--- a/src/core.go
+++ b/src/core.go
@@ -43,12 +43,16 @@ Matcher -> EvtHeader -> Terminal (update header)
*/
// Run starts fzf
-func Run(opts *Options) {
+func Run(opts *Options, revision string) {
sort := opts.Sort > 0
sortCriteria = opts.Criteria
if opts.Version {
- fmt.Println(version)
+ if len(revision) > 0 {
+ fmt.Printf("%s (%s)\n", version, revision)
+ } else {
+ fmt.Println(version)
+ }
os.Exit(exitOk)
}