Skip to content

Commit

Permalink
Merge 59db6b6 into 7e6f3ec
Browse files Browse the repository at this point in the history
  • Loading branch information
cfromknecht committed Apr 8, 2020
2 parents 7e6f3ec + 59db6b6 commit 070afbc
Show file tree
Hide file tree
Showing 14 changed files with 1,253 additions and 775 deletions.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -22,7 +22,9 @@ ANDROID_BUILD_DIR := $(MOBILE_BUILD_DIR)/android
ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar

COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)"
COMMIT_HASH := $(shell git rev-parse HEAD)
LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT) \
-X $(PKG)/build.CommitHash=$(COMMIT_HASH)"

BTCD_COMMIT := $(shell cat go.mod | \
grep $(BTCD_PKG) | \
Expand Down
77 changes: 42 additions & 35 deletions build/version.go
Expand Up @@ -6,61 +6,68 @@
package build

import (
"bytes"
"fmt"
"strings"
)

// Commit stores the current commit hash of this build, this should be set using
// the -ldflags during compilation.
var Commit string
var (
// Commit stores the current commit of this build, which includes the
// msot recent tag, the number of commits since that tag (if non-zero),
// the commit hash, and a dirty marker. This should be set using the
// -ldflags during compilation.
Commit string

// semanticAlphabet
// CommitHash stores the current commit hash of this build, this should
// be set using the -ldflags during compilation.
CommitHash string
)

// semanticAlphabet is the set of characters that are permitted for use in an
// AppPreRelease.
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"

// These constants define the application version and follow the semantic
// versioning 2.0.0 spec (http://semver.org/).
const (
appMajor uint = 0
appMinor uint = 9
appPatch uint = 0
// AppMajor defines the major version of this binary.
AppMajor uint = 0

// AppMinor defines the minor version of this binary.
AppMinor uint = 9

// AppPatch defines the application patch for this binary.
AppPatch uint = 0

// appPreRelease MUST only contain characters from semanticAlphabet
// AppPreRelease MUST only contain characters from semanticAlphabet
// per the semantic versioning spec.
appPreRelease = "beta"
AppPreRelease = "beta"
)

func init() {
// Assert that AppPreRelease is valid according to the semantic
// versioning guidelines for pre-release version and build metadata
// strings. In particular it MUST only contain characters in
// semanticAlphabet.
for _, r := range AppPreRelease {
if !strings.ContainsRune(semanticAlphabet, r) {
panic(fmt.Errorf("rune: %v is not in the semantic "+
"alphabet", r))
}
}
}

// Version returns the application version as a properly formed string per the
// semantic versioning 2.0.0 spec (http://semver.org/).
func Version() string {
// Start with the major, minor, and patch versions.
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
version := fmt.Sprintf("%d.%d.%d", AppMajor, AppMinor, AppPatch)

// Append pre-release version if there is one. The hyphen called for
// by the semantic versioning spec is automatically appended and should
// not be contained in the pre-release string. The pre-release version
// is not appended if it contains invalid characters.
preRelease := normalizeVerString(appPreRelease)
if preRelease != "" {
version = fmt.Sprintf("%s-%s", version, preRelease)
// Append pre-release version if there is one. The hyphen called for by
// the semantic versioning spec is automatically appended and should not
// be contained in the pre-release string.
if AppPreRelease != "" {
version = fmt.Sprintf("%s-%s", version, AppPreRelease)
}

// Append commit hash of current build to version.
version = fmt.Sprintf("%s commit=%s", version, Commit)

return version
}

// normalizeVerString returns the passed string stripped of all characters which
// are not valid according to the semantic versioning guidelines for pre-release
// version and build metadata strings. In particular they MUST only contain
// characters in semanticAlphabet.
func normalizeVerString(str string) string {
var result bytes.Buffer
for _, r := range str {
if strings.ContainsRune(semanticAlphabet, r) {
result.WriteRune(r)
}
}
return result.String()
}
35 changes: 35 additions & 0 deletions cmd/lncli/cmd_version.go
@@ -0,0 +1,35 @@
package main

import (
"context"

"github.com/lightningnetwork/lnd/lnrpc/verrpc"
"github.com/urfave/cli"
)

var versionCommand = cli.Command{
Name: "version",
Category: "Info",
Usage: "Display deamon version info.",
Description: `
Returns version information about the running daemon.
`,
Action: actionDecorator(version),
}

func version(ctx *cli.Context) error {
conn := getClientConn(ctx, false)
defer conn.Close()

client := verrpc.NewVersionerClient(conn)

ctxb := context.Background()
resp, err := client.GetVersion(ctxb, &verrpc.VersionRequest{})
if err != nil {
return err
}

printRespJSON(resp)

return nil
}
1 change: 1 addition & 0 deletions cmd/lncli/main.go
Expand Up @@ -301,6 +301,7 @@ func main() {
restoreChanBackupCommand,
bakeMacaroonCommand,
trackPaymentCommand,
versionCommand,
}

// Add any extra commands determined by build flags.
Expand Down

0 comments on commit 070afbc

Please sign in to comment.