Add git revision to --version output
This commit is contained in:
parent
8bbf9335e1
commit
83e9af6601
26
Makefile
26
Makefile
@ -9,14 +9,19 @@ $(error "$$GOOS is not defined.")
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
||||||
|
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
||||||
GOPATH := $(ROOT_DIR)/gopath
|
GOPATH := $(ROOT_DIR)/gopath
|
||||||
SRC_LINK := $(GOPATH)/src/github.com/junegunn/fzf/src
|
SRC_LINK := $(GOPATH)/src/github.com/junegunn/fzf/src
|
||||||
VENDOR_LINK := $(GOPATH)/src/github.com/junegunn/fzf/vendor
|
VENDOR_LINK := $(GOPATH)/src/github.com/junegunn/fzf/vendor
|
||||||
|
export GOPATH
|
||||||
|
|
||||||
GLIDE_YAML := glide.yaml
|
GLIDE_YAML := glide.yaml
|
||||||
GLIDE_LOCK := glide.lock
|
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
|
BINARY32 := fzf-$(GOOS)_386
|
||||||
BINARY64 := fzf-$(GOOS)_amd64
|
BINARY64 := fzf-$(GOOS)_amd64
|
||||||
@ -31,7 +36,6 @@ RELEASEARM5 := fzf-$(VERSION)-$(GOOS)_arm5
|
|||||||
RELEASEARM6 := fzf-$(VERSION)-$(GOOS)_arm6
|
RELEASEARM6 := fzf-$(VERSION)-$(GOOS)_arm6
|
||||||
RELEASEARM7 := fzf-$(VERSION)-$(GOOS)_arm7
|
RELEASEARM7 := fzf-$(VERSION)-$(GOOS)_arm7
|
||||||
RELEASEARM8 := fzf-$(VERSION)-$(GOOS)_arm8
|
RELEASEARM8 := fzf-$(VERSION)-$(GOOS)_arm8
|
||||||
export GOPATH
|
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/Uname
|
# https://en.wikipedia.org/wiki/Uname
|
||||||
UNAME_M := $(shell uname -m)
|
UNAME_M := $(shell uname -m)
|
||||||
@ -60,8 +64,8 @@ target:
|
|||||||
|
|
||||||
ifeq ($(GOOS),windows)
|
ifeq ($(GOOS),windows)
|
||||||
release: target/$(BINARY32) target/$(BINARY64)
|
release: target/$(BINARY32) target/$(BINARY64)
|
||||||
cd target && cp -f $(BINARY32) fzf.exe && zip $(RELEASE32).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 bin/fzf.exe
|
cd target && cp -f $(BINARY64) fzf.exe && zip $(RELEASE64).zip fzf.exe
|
||||||
cd target && rm -f fzf.exe
|
cd target && rm -f fzf.exe
|
||||||
else ifeq ($(GOOS),linux)
|
else ifeq ($(GOOS),linux)
|
||||||
release: target/$(BINARY32) target/$(BINARY64) target/$(BINARYARM5) target/$(BINARYARM6) target/$(BINARYARM7) target/$(BINARYARM8)
|
release: target/$(BINARY32) target/$(BINARY64) target/$(BINARYARM5) target/$(BINARYARM6) target/$(BINARYARM7) target/$(BINARYARM8)
|
||||||
@ -110,23 +114,23 @@ clean:
|
|||||||
rm -rf target
|
rm -rf target
|
||||||
|
|
||||||
target/$(BINARY32): $(SOURCES)
|
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)
|
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
|
# https://github.com/golang/go/wiki/GoArm
|
||||||
target/$(BINARYARM5): $(SOURCES)
|
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)
|
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)
|
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)
|
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
|
bin/fzf: target/$(BINARY) | bin
|
||||||
cp -f target/$(BINARY) bin/fzf
|
cp -f target/$(BINARY) bin/fzf
|
||||||
|
2
install
2
install
@ -72,7 +72,7 @@ ask() {
|
|||||||
check_binary() {
|
check_binary() {
|
||||||
echo -n " - Checking fzf executable ... "
|
echo -n " - Checking fzf executable ... "
|
||||||
local output
|
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
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: $output"
|
echo "Error: $output"
|
||||||
binary_error="Invalid binary"
|
binary_error="Invalid binary"
|
||||||
|
4
main.go
4
main.go
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import "github.com/junegunn/fzf/src"
|
import "github.com/junegunn/fzf/src"
|
||||||
|
|
||||||
|
var revision string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fzf.Run(fzf.ParseOptions())
|
fzf.Run(fzf.ParseOptions(), revision)
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,16 @@ Matcher -> EvtHeader -> Terminal (update header)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Run starts fzf
|
// Run starts fzf
|
||||||
func Run(opts *Options) {
|
func Run(opts *Options, revision string) {
|
||||||
sort := opts.Sort > 0
|
sort := opts.Sort > 0
|
||||||
sortCriteria = opts.Criteria
|
sortCriteria = opts.Criteria
|
||||||
|
|
||||||
if opts.Version {
|
if opts.Version {
|
||||||
|
if len(revision) > 0 {
|
||||||
|
fmt.Printf("%s (%s)\n", version, revision)
|
||||||
|
} else {
|
||||||
fmt.Println(version)
|
fmt.Println(version)
|
||||||
|
}
|
||||||
os.Exit(exitOk)
|
os.Exit(exitOk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user