mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
Merge pull request #87 from jsonnet-bundler/ldflag-version
feat(cli): --version using ldflags
This commit is contained in:
commit
cd5e2945d2
5 changed files with 39 additions and 86 deletions
53
Makefile
53
Makefile
|
|
@ -1,31 +1,36 @@
|
|||
all: check-license build generate test
|
||||
.PHONY: all check-license crossbuild build install test generate embedmd
|
||||
|
||||
SHELL=/bin/bash
|
||||
|
||||
GITHUB_URL=github.com/jsonnet-bundler/jsonnet-bundler
|
||||
GOOS?=$(shell uname -s | tr A-Z a-z)
|
||||
GOARCH?=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
|
||||
VERSION := $(shell git describe --tags --dirty --always)
|
||||
OUT_DIR=_output
|
||||
BIN?=jb
|
||||
VERSION?=$(shell cat VERSION)
|
||||
PKGS=$(shell go list ./... | grep -v /vendor/)
|
||||
|
||||
check-license:
|
||||
@echo ">> checking license headers"
|
||||
@./scripts/check_license.sh
|
||||
all: check-license build generate test
|
||||
|
||||
crossbuild:
|
||||
@GOOS=linux ARCH=amd64 $(MAKE) -s build
|
||||
# Binaries
|
||||
LDFLAGS := '-s -w -extldflags "-static" -X main.Version=${VERSION}'
|
||||
cross: clean
|
||||
CGO_ENABLED=0 gox \
|
||||
-output="$(OUT_DIR)/jb-{{.OS}}-{{.Arch}}" \
|
||||
-ldflags=$(LDFLAGS) \
|
||||
-arch="amd64 arm64 arm" -os="linux" \
|
||||
-osarch="darwin/amd64" \
|
||||
./cmd/$(BIN)
|
||||
|
||||
static:
|
||||
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o $(OUT_DIR)/$(BIN) ./cmd/$(BIN)
|
||||
|
||||
build:
|
||||
@$(eval OUTPUT=$(OUT_DIR)/$(GOOS)/$(GOARCH)/$(BIN))
|
||||
@echo ">> building for $(GOOS)/$(GOARCH) to $(OUTPUT)"
|
||||
@mkdir -p $(OUT_DIR)/$(GOOS)/$(GOARCH)
|
||||
@CGO_ENABLED=0 go build --installsuffix cgo -o $(OUTPUT) $(GITHUB_URL)/cmd/$(BIN)
|
||||
CGO_ENABLED=0 go build -o $(OUT_DIR)/$(BIN) ./cmd/$(BIN)
|
||||
|
||||
install: build
|
||||
@$(eval OUTPUT=$(OUT_DIR)/$(GOOS)/$(GOARCH)/$(BIN))
|
||||
install: static
|
||||
@echo ">> copying $(BIN) into $(GOPATH)/bin/$(BIN)"
|
||||
@cp $(OUTPUT) $(GOPATH)/bin/$(BIN)
|
||||
cp $(OUT_DIR)/$(BIN) $(GOPATH)/bin/$(BIN)
|
||||
|
||||
# Tests
|
||||
test:
|
||||
@echo ">> running all unit tests"
|
||||
go test -v $(PKGS)
|
||||
|
|
@ -34,12 +39,22 @@ test-integration:
|
|||
@echo ">> running all integration tests"
|
||||
go test -v -tags=integration $(PKGS)
|
||||
|
||||
# Documentation
|
||||
generate: embedmd
|
||||
@echo ">> generating docs"
|
||||
@./scripts/generate-help-txt.sh
|
||||
@$(GOPATH)/bin/embedmd -w `find ./ -path ./vendor -prune -o -name "*.md" -print`
|
||||
$(GOPATH)/bin/embedmd -w `find ./ -path ./vendor -prune -o -name "*.md" -print`
|
||||
|
||||
check-license:
|
||||
@echo ">> checking license headers"
|
||||
@./scripts/check_license.sh
|
||||
|
||||
embedmd:
|
||||
@go get github.com/campoy/embedmd
|
||||
pushd /tmp && GO111MODULES=on go get github.com/campoy/embedmd && popd
|
||||
|
||||
.PHONY: all check-license crossbuild build install test generate embedmd
|
||||
# Other
|
||||
clean:
|
||||
rm -rf $(OUT_DIR) $(BIN)
|
||||
|
||||
drone:
|
||||
drone jsonnet --format
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -30,6 +31,8 @@ const (
|
|||
rewriteActionName = "rewrite"
|
||||
)
|
||||
|
||||
var Version = "dev"
|
||||
|
||||
func main() {
|
||||
os.Exit(Main())
|
||||
}
|
||||
|
|
@ -41,7 +44,7 @@ func Main() int {
|
|||
|
||||
color.Output = color.Error
|
||||
|
||||
a := newApp()
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager").Version(Version)
|
||||
a.HelpFlag.Short('h')
|
||||
|
||||
a.Flag("jsonnetpkg-home", "The directory used to cache packages in.").
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build go1.12
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func newApp() *kingpin.Application {
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
d, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
return a.Version(d.Main.Version)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !go1.12
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func newApp() *kingpin.Application {
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
return a
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BINARY_NAME=jb
|
||||
GOOS=$(go env GOOS)
|
||||
GOARCH=$(go env GOARCH)
|
||||
|
||||
HELP_FILE=$PWD/_output/help.txt
|
||||
echo "$ $BINARY_NAME -h" > $HELP_FILE
|
||||
$PWD/_output/$GOOS/$GOARCH/$BINARY_NAME 2>> $HELP_FILE
|
||||
$PWD/_output/$BINARY_NAME 2>> $HELP_FILE
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue