Merge pull request #958 from filecoin-project/revert-909-feat/version2

Revert "Refactor versions"
This commit is contained in:
Łukasz Magiera 2019-12-17 16:20:20 +01:00 committed by GitHub
commit 30537dd97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 42 deletions

View File

@ -4,9 +4,10 @@ import (
"context"
"fmt"
"github.com/filecoin-project/lotus/build"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/filecoin-project/lotus/build"
)
type Permission = string
@ -39,7 +40,7 @@ type Version struct {
// this api
//
// See APIVersion in build/version.go
APIVersion build.Version
APIVersion uint32
// TODO: git commit / os / genesis cid?
@ -48,5 +49,6 @@ type Version struct {
}
func (v Version) String() string {
return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String())
vM, vm, vp := build.VersionInts(v.APIVersion)
return fmt.Sprintf("%s+api%d.%d.%d", v.Version, vM, vm, vp)
}

View File

@ -50,7 +50,7 @@ func (ts *testSuite) testVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if v.Version != build.BuildVersion {
if v.Version != build.Version {
t.Error("Version didn't work properly")
}
}

View File

@ -1,44 +1,34 @@
package build
import "fmt"
var CurrentCommit string
// BuildVersion is the local build version, set by build system
const BuildVersion = "0.1.2"
// Version is the local build version, set by build system
const Version = "0.1.2"
var UserVersion = BuildVersion + CurrentCommit
var UserVersion = Version + CurrentCommit
type Version uint32
func newVer(major, minor, patch uint8) Version {
return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch))
}
// Ints returns (major, minor, patch) versions
func (ve Version) Ints() (uint32, uint32, uint32) {
v := uint32(ve)
return (v & majorOnlyMask) >> 16, (v & minorOnlyMask) >> 8, v & patchOnlyMask
}
func (ve Version) String() string {
vmj, vmi, vp := ve.Ints()
return fmt.Sprintf("%d.%d.%d", vmj, vmi, vp)
}
func (ve Version) EqMajorMinor(v2 Version) bool {
return ve&minorMask == v2&minorMask
}
// APIVersion is a semver version of the rpc api exposed
var APIVersion Version = newVer(0, 1, 2)
// APIVersion is a hex semver version of the rpc api exposed
//
// M M P
// A I A
// J N T
// O O C
// R R H
// |\vv/|
// vv vv
const APIVersion = 0x000102
const (
majorMask = 0xff0000
minorMask = 0xffff00
patchMask = 0xffffff
MajorMask = 0xff0000
MinorMask = 0xffff00
PatchMask = 0xffffff
majorOnlyMask = 0xff0000
minorOnlyMask = 0x00ff00
patchOnlyMask = 0x0000ff
MajorOnlyMask = 0xff0000
MinorOnlyMask = 0x00ff00
PatchOnlyMask = 0x0000ff
)
// VersionInts returns (major, minor, patch) versions
func VersionInts(version uint32) (uint32, uint32, uint32) {
return (version & MajorOnlyMask) >> 16, (version & MinorOnlyMask) >> 8, version & PatchOnlyMask
}

View File

@ -25,7 +25,7 @@ func main() {
app := &cli.App{
Name: "lotus-shed",
Usage: "A place for all the lotus tools",
Version: build.BuildVersion,
Version: build.Version,
Commands: local,
}

View File

@ -136,7 +136,7 @@ var initCmd = &cli.Command{
return err
}
if v.APIVersion.EqMajorMinor(build.APIVersion) {
if v.APIVersion&build.MinorMask != build.APIVersion&build.MinorMask {
return xerrors.Errorf("Remote API version didn't match (local %x, remote %x)", build.APIVersion, v.APIVersion)
}

View File

@ -2,7 +2,6 @@ package impl
import (
"context"
"github.com/gbrlsnchs/jwt/v3"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
@ -85,7 +84,7 @@ func (a *CommonAPI) ID(context.Context) (peer.ID, error) {
func (a *CommonAPI) Version(context.Context) (api.Version, error) {
return api.Version{
Version: build.UserVersion,
Version: build.Version,
APIVersion: build.APIVersion,
BlockDelay: build.BlockDelay,