]> git.lizzy.rs Git - micro.git/commitdiff
Resolve versions in plugin manager
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 5 Feb 2019 03:26:06 +0000 (22:26 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 25 Dec 2019 22:05:10 +0000 (17:05 -0500)
Makefile
cmd/micro/debug.go
cmd/micro/micro.go
internal/manager/fetch.go
internal/manager/manager_test.go
internal/manager/plugin.go
internal/util/util.go

index 6c55074742d077d09645bfe7b39f342847c374b0..72547cd0cb7f232c3cd73d8e501abe6f58e0909f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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:
index 1751de13adeb56ce7ee5ccbdecd980acb8a0c11e..7c13d9ced3ee848841c394f6d09b4dd03e7c3b1e 100644 (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)
index ef83f9aedfc5add672cdd905b7607e78ac363de2..e2a961f71852c8e7043d1717b7b3157efb3a8a02 100644 (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)
        }
 
index 529c64dc4296d878a026e2af4d81c2bf7f8d9eb1..6dc4b9346a4b390687e0a67b146585c1f1421e76 100644 (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 {
index ddd644cdb1d1f99b834665f4079509e3daece718..96e9003d6315f472a3413d6946d2d53dde40f4b1 100644 (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()
index 5913e3785a7f7d7c2ae28d7b4792024dbf6a440b..db307815519875118cf49aab173ea52855c248cf 100644 (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 {
index 0d23028e7db21654655a25f8cd97eb4e05988867..dbaf9087790de5c62e9fe37b3d26144fda7f1c3e 100644 (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 {