Resolve versions in plugin manager

This commit is contained in:
Zachary Yedidia 2019-02-04 22:26:06 -05:00
parent cf2d5dbfe2
commit 4497daaef1
7 changed files with 71 additions and 32 deletions

View File

@ -9,7 +9,7 @@ ADDITIONAL_GO_LINKER_FLAGS := $(shell GOOS=$(shell go env GOHOSTOS) \
GOARCH=$(shell go env GOHOSTARCH) \
go run tools/info-plist.go "$(VERSION)")
GOBIN ?= $(shell go env GOPATH)/bin
GOVARS := -X main.Version=$(VERSION) -X main.CommitHash=$(HASH) -X 'main.CompileDate=$(DATE)' -X main.Debug=OFF
GOVARS := -X github.com/zyedidia/micro/internal/util.Version=$(VERSION) -X github.com/zyedidia/micro/internal/util.CommitHash=$(HASH) -X 'github.com/zyedidia/micro/internal/util.CompileDate=$(DATE)' -X github.com/zyedidia/micro/internal/util.Debug=OFF
# Builds micro after checking dependencies but without updating the runtime
build:

View File

@ -3,6 +3,8 @@ package main
import (
"log"
"os"
"github.com/zyedidia/micro/internal/util"
)
// NullWriter simply sends writes into the void
@ -15,7 +17,7 @@ func (NullWriter) Write(data []byte) (n int, err error) {
// InitLog sets up the debug log system for micro if it has been enabled by compile-time variables
func InitLog() {
if Debug == "ON" {
if util.Debug == "ON" {
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)

View File

@ -13,21 +13,11 @@ import (
"github.com/zyedidia/micro/internal/buffer"
"github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/micro/internal/util"
"github.com/zyedidia/tcell"
)
var (
// These variables should be set by the linker when compiling
// Version is the version number or commit hash
Version = "0.0.0-unknown"
// CommitHash is the commit this version was built on
CommitHash = "Unknown"
// CompileDate is the date this binary was compiled on
CompileDate = "Unknown"
// Debug logging
Debug = "ON"
// Event channel
events chan tcell.Event
autosave chan bool
@ -70,9 +60,9 @@ func InitFlags() {
if *flagVersion {
// If -version was passed
fmt.Println("Version:", Version)
fmt.Println("Commit hash:", CommitHash)
fmt.Println("Compiled on", CompileDate)
fmt.Println("Version:", util.Version)
fmt.Println("Commit hash:", util.CommitHash)
fmt.Println("Compiled on", util.CompileDate)
os.Exit(0)
}

View File

@ -1,12 +1,14 @@
package manager
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"github.com/blang/semver"
"github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/util"
git "gopkg.in/src-d/go-git.v4"
)
@ -56,11 +58,26 @@ func (i *PluginInfo) FetchRepo() error {
}
func (p *Plugin) ResolveVersion() error {
return nil
i := p.info
vs := i.Versions
for _, v := range vs {
microrange, err := semver.ParseRange(v.Require["micro"])
if err != nil {
return err
}
if microrange(util.SemVersion) {
p.version = v.Vers
fmt.Println("resolve version to ", v.Vstr)
return nil
}
}
return ErrRequireUnsat
}
func (p *Plugin) WriteVersion() error {
return ioutil.WriteFile(path.Join(p.dir, versionfile), []byte(p.version.String()), os.ModePerm)
return ioutil.WriteFile(path.Join(p.dir, versionfile), []byte(p.version.String()), 0644)
}
func (p *Plugin) FetchDeps() error {

View File

@ -3,11 +3,15 @@ package manager
import (
"testing"
"github.com/blang/semver"
"github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/util"
)
func init() {
config.InitConfigDir("./")
util.Version = "1.3.1"
util.SemVersion, _ = semver.Make(util.Version)
}
var sampleJson = []byte(`{
@ -47,17 +51,17 @@ func TestParse(t *testing.T) {
}
}
// func TestFetch(t *testing.T) {
// i, err := NewPluginInfoFromUrl("http://zbyedidia.webfactional.com/micro/test.json")
// if err != nil {
// t.Error(err)
// }
//
// err = i.FetchRepo()
// if err != nil {
// t.Error(err)
// }
// }
func TestFetch(t *testing.T) {
i, err := NewPluginInfoFromUrl("http://zbyedidia.webfactional.com/micro/test.json")
if err != nil {
t.Error(err)
}
err = i.FetchRepo()
if err != nil {
t.Error(err)
}
}
// func TestList(t *testing.T) {
// is, err := ListInstalledPlugins()

View File

@ -20,6 +20,7 @@ var (
ErrMissingVersions = errors.New("Missing or empty versions field")
ErrMissingTag = errors.New("Missing or empty tag field")
ErrMissingRequire = errors.New("Missing or empty require field")
ErrRequireUnsat = errors.New("Version require could not be satisfied")
)
const (
@ -95,12 +96,12 @@ func (i *PluginInfo) makeVersions() error {
return ErrMissingVersions
}
for _, v := range i.Versions {
for j, v := range i.Versions {
sv, err := semver.Make(v.Vstr)
if err != nil {
return err
}
v.Vers = sv
i.Versions[j].Vers = sv
if len(v.Tag) == 0 {
return ErrMissingTag
} else if v.Require == nil {

View File

@ -2,6 +2,7 @@ package util
import (
"errors"
"fmt"
"os"
"os/user"
"path/filepath"
@ -11,9 +12,33 @@ import (
"time"
"unicode/utf8"
"github.com/blang/semver"
runewidth "github.com/mattn/go-runewidth"
)
var (
// These variables should be set by the linker when compiling
// Version is the version number or commit hash
Version = "0.0.0-unknown"
// Semantic version
SemVersion semver.Version
// CommitHash is the commit this version was built on
CommitHash = "Unknown"
// CompileDate is the date this binary was compiled on
CompileDate = "Unknown"
// Debug logging
Debug = "ON"
)
func init() {
var err error
SemVersion, err = semver.Make(Version)
if err != nil {
fmt.Println("Invalid version: ", Version, err)
}
}
// SliceEnd returns a byte slice where the index is a rune index
// Slices off the start of the slice
func SliceEnd(slc []byte, index int) []byte {