]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
Add metadata and proof-of-concept tag checkout
authorGeorge Dunlap <george.dunlap@citrix.com>
Thu, 23 Feb 2017 22:36:25 +0000 (22:36 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Thu, 23 Feb 2017 22:36:25 +0000 (22:36 +0000)
Add a metadata struct (which will eventually be stored as json),
containing the XSA number, supported Xen versions (according to what
is in security support at the time the XSA is issued), and 'recipes'
for building patched versions.

Each recipe consists of a full Xen version (down to point),
prerequisite XSAs that this patch depends on, and a string to "git am"
to various trees.

Applying the recipe will make a branch checked out from the release tag
appropriate to that repo.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
git.go
main.go
meta.go [new file with mode: 0644]
recipe.go [new file with mode: 0644]
xen.go [new file with mode: 0644]

diff --git a/git.go b/git.go
index d39b5e71966108dd05666127c9a1d09186d5ed63..589bb0de64d95c44fb08901a8f96038d6537d858 100644 (file)
--- a/git.go
+++ b/git.go
@@ -11,25 +11,32 @@ type Repo struct {
        Path string
 }
 
+
+
 func GitOpen(gpath string) (r Repo, err error) {
-       if ! path.IsAbs(gpath) {
+       if !path.IsAbs(gpath) {
                cwd, err := os.Getwd()
                if err != nil {
+                       fmt.Printf("Getwd failed?\n")
                        return r, err
                }
-               gpath = cwd+"/"+gpath
+               gpath = cwd + "/" + gpath
                gpath = path.Clean(gpath)
        }
 
+       fmt.Printf("Path: %s\n", gpath)
        r.Path = gpath
-       if ! r.Check() {
+       if !r.Check() {
                err = fmt.Errorf("Status failed!")
        }
        return
 }
 
 func (r Repo) gitCmd(args ...string) (out []byte, err error) {
-       out, err = exec.Command("git", append([]string{"-C", r.Path}, args...)...).Output()
+       x := append([]string{"-C", r.Path}, args...)
+       fmt.Println(x)
+       out, err = exec.Command("git", x...).CombinedOutput()
+       fmt.Println(string(out))
        return
 }
 
@@ -38,3 +45,17 @@ func (r Repo) Check() (ok bool) {
 
        return err == nil
 }
+
+func (r Repo) Fetch() (out []byte, err error) {
+       out, err = r.gitCmd("fetch")
+
+       fmt.Printf("%s", string(out))
+
+       return
+}
+
+func (r Repo) Checkout(ref string, branch string) (err error) {
+       _, err = r.gitCmd("checkout", "-B", branch, ref)
+
+       return
+}
diff --git a/main.go b/main.go
index 1d09bbebdc503f3c15aa1abebacd8be360999bd7..fd5240fb8f7e332809705e594d58fb6731e89053 100644 (file)
--- a/main.go
+++ b/main.go
@@ -2,21 +2,37 @@ package main
 
 import (
        "fmt"
+       "os"
 )
 
 func main() {
-       
-       xenRepo, err := GitOpen("../xen.git")
+
+       err := InitRepos()
        if err != nil {
-               fmt.Printf("Unexpected: %v\n", err)
+               fmt.Printf("Error initializing repos: %v\n", err)
+               os.Exit(1)
+       }
+
+       for i := XenVersion44; i <= XenVersionMaster; i++ {
+               fmt.Printf("%d: %v\n", int(i), i)
        }
-       fmt.Printf("%v\n", xenRepo.Check())
 
-       fakeRepo, err := GitOpen("blah.git")
-       if err == nil {
-               fmt.Printf("Unexpected success!\n")
+       meta := Metadata{
+               XSA:               209,
+               SupportedVersions: []XenVersion{XenVersion48},
+               Recipes: []Recipe{
+                       Recipe{
+                               XenVersionFull:      XenVersionFull{XenVersion48,0},
+                               QemuUpstreamPatches: "xsa209-qemuu/*.patch",
+                       },
+               },
        }
-       fmt.Printf("%v\n", fakeRepo.Check())
 
-       
+       meta.Normalize()
+
+       err = meta.Recipes[0].Apply()
+       if err != nil {
+               fmt.Printf("Applying recipe: %v\n", err)
+       }
+       defer meta.Recipes[0].Cleanup()
 }
diff --git a/meta.go b/meta.go
new file mode 100644 (file)
index 0000000..292e7e9
--- /dev/null
+++ b/meta.go
@@ -0,0 +1,17 @@
+package main
+
+import (
+       //      "encoding/json"
+)
+
+type Metadata struct {
+       XSA               int
+       SupportedVersions []XenVersion
+       Recipes           []Recipe
+}
+
+func (m *Metadata) Normalize() {
+       for i := range m.Recipes {
+               m.Recipes[i].xsa = m.XSA
+       }
+}
diff --git a/recipe.go b/recipe.go
new file mode 100644 (file)
index 0000000..99b27d4
--- /dev/null
+++ b/recipe.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+       "fmt"
+       "strconv"
+)
+
+type XenVersion int
+
+const (
+       XenVersion44 XenVersion = iota
+       XenVersion45
+       XenVersion46
+       XenVersion47
+       XenVersion48
+       XenVersionMaster
+)
+
+func (v XenVersion) String() (s string) {
+       if v == XenVersionMaster {
+               return "master"
+       }
+
+       s = "4."
+       s += strconv.Itoa(int(v - XenVersion44 + 4))
+
+       return
+}
+
+type XenVersionFull struct {
+       XenVersion
+       Point int
+}
+
+func (v XenVersionFull) String() (s string) {
+       if v.XenVersion == XenVersionMaster {
+               return "master"
+       }
+
+       s += v.XenVersion.String() + "." + strconv.Itoa(v.Point)
+
+       return
+}
+
+
+type Recipe struct {
+       XenVersionFull
+       XenPatches             string
+       QemuUpstreamPatches    string
+       QemuTraditionalPatches string
+       RequiredXSAs           []int
+       tempBranch             string // Not serialized
+       xsa                    int
+}
+
+func (r *Recipe) Apply() (err error) {
+       // Construct branchname
+       r.tempBranch = "test/" + strconv.Itoa(r.xsa) + "/" + r.XenVersion.String()
+       fmt.Printf("Test tag: %s\n", r.tempBranch)
+       
+       if r.QemuUpstreamPatches != "" {
+               // Checkout appropriate version
+               err = qemuu.CheckoutVersion(r.XenVersionFull, r.tempBranch)
+               if err != nil {
+                       return
+               }
+               // Apply prerequisite XSAs
+               // git am
+       }
+       return
+}
+
+func (r *Recipe) Cleanup() (err error) {
+       return
+       
+}
diff --git a/xen.go b/xen.go
new file mode 100644 (file)
index 0000000..ab4bdcc
--- /dev/null
+++ b/xen.go
@@ -0,0 +1,77 @@
+package main
+
+import (
+       "fmt"
+)
+
+type XRType int
+
+const (
+       XRXen XRType = iota
+       XRQemuu
+       XRQemut
+)
+
+type XenRepo struct {
+       Repo
+       XRType
+}
+
+var xen, qemuu, qemut XenRepo
+
+func XenRepoOpen(path string, t XRType) (xr XenRepo, err error) {
+       fmt.Printf("Opening %s\n", path)
+       xr.Repo, err = GitOpen(path)
+       if err != nil {
+               return
+       }
+       fmt.Printf("Fetching\n")
+       out, err := xr.Fetch()
+       if err != nil {
+               return 
+       }
+       xr.XRType = t
+       fmt.Print(string(out))
+
+       return
+}
+
+func InitRepos() (err error) {
+       xen, err = XenRepoOpen("../xen.git", XRXen)
+       if err != nil {
+               return 
+       }
+
+       qemuu, err = XenRepoOpen("../qemu-xen.git", XRQemuu)
+       if err != nil {
+               return
+       }
+
+       qemut, err = XenRepoOpen("../qemu-xen-traditional.git", XRQemut)
+       if err != nil {
+               return
+       }
+
+       return
+}
+
+func (xr *XenRepo) releaseTagPrefix() (s string) {
+       switch xr.XRType {
+       case XRXen:
+               return "RELEASE-"
+       case XRQemuu:
+               return "qemu-xen-"
+       case XRQemut:
+               return "xen-"
+       }
+
+       return
+}
+
+func (xr *XenRepo) CheckoutVersion(ver XenVersionFull, branchName string) (err error) {
+       tag := xr.releaseTagPrefix()+ver.String()
+       fmt.Printf("Creating branch %s based on tag %s\n",
+               branchName, tag)
+       err = xr.Checkout(tag, branchName)
+       return
+}