]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
main: Implement 'init' command
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 19 May 2017 14:01:17 +0000 (15:01 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 19 May 2017 14:01:17 +0000 (15:01 +0100)
New method of creating a new xsa:  "xsatool NNN init [trees]"

This will:
- For a given set of trees
- And all the currently-supported versions
- Create an XSA that contains all the currently-outstanding XSAs for that tree and set of versions
- And create branches for all of those versions in the correct tree
- And add it to the list of currently-outstanding XSAs

At that point, the user can go into the appropriate tree and create patches.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
main.go
recipe.go
xsa.go

diff --git a/main.go b/main.go
index 780fe35ab30e2b182cf47c1c2fc31cd493ecbbc1..80b2a35281dd5e8cd314082a58ccfd48bd2036da 100644 (file)
--- a/main.go
+++ b/main.go
@@ -89,21 +89,11 @@ func XsaMain(args []string) int {
 
        if xsanum, err = strconv.Atoi(tgt); err == nil {
                switch cmd {
-               case "new":
-                       xsa.XSA = xsanum
-                       main = func(xsa *XSAMeta, args []string) int {
-                               if xsa.XSA == 0 {
-                                       fmt.Printf("Error: Need an XSA\n")
-                                       return 1
-                               }
-                               fmt.Printf("Would make new XSA %d\n", xsanum)
-                               return 0
-                       }
-               case "new-recipe":
-                       main = MainNewRecipe
+               case "init":
+                       main = MainInit
                        loadConfig = true
+                       loadGlobal = true
                        loadXSA = true
-
                case "sync-patches":
                        main = MainSyncPatches
                        loadConfig = true
index c92ccc029c6891cf859f5e862eea8c9412a03594..6edc0f831d21c28363c0881787c04dfa863cdee1 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -288,11 +288,17 @@ func (r *Recipe) IsApplied(prefix string) (err error) {
        return
 }
 
-func (r *Recipe) branchName(prefix string) (branch, baseline string) {
+func BranchName(prefix string, xsa int, v XenVersion) (branch, baseline string) {
        // Construct branchname
-       branch = prefix + "/" + strconv.Itoa(r.xsa) + "/" + r.XenVersionFull.XenVersion().String()
+       branch = prefix + "/" + strconv.Itoa(xsa) + "/" + v.String()
        baseline = branch + "-baseline"
 
+       return
+}
+
+func (r *Recipe) branchName(prefix string) (branch, baseline string) {
+       branch, baseline = BranchName(prefix, r.xsa, r.XenVersionFull.XenVersion())
+
        fmt.Printf("Branchnames: %s %s\n", branch, baseline)
 
        return
@@ -371,14 +377,6 @@ func (r *Recipe) GetTreeRecipe(tree Tree) (tr *TreeRecipe, err error) {
        return
 }
 
-func (r *Recipe) CreateBranch(prefix string, tree Tree) (err error) {
-       tr, err := r.GetTreeRecipe(tree)
-       if err != nil {
-               return err
-       }
-       return r.apply(G.repos.XenRepos[tree], tr, prefix)
-}
-
 func (r *Recipe) Build(prefix string) (err error) {
        branch, _ := r.branchName(prefix)
 
diff --git a/xsa.go b/xsa.go
index 3d1b48792418f8904706d7c5056bf320faf92011..36ec47746804b093a24a949648d17584f4e84f29 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -68,23 +68,14 @@ func MainSyncBranch(xsa *XSAMeta, args []string) (ret int) {
        return 0
 }
 
-// xsatool NNN new-recipe $FULLVERSION {xen,qemuu,qemut} [prerequisites]
-func MainNewRecipe(xsa *XSAMeta, args []string) (ret int) {
-       if len(args) < 2 {
-               fmt.Printf("Not enough argruments\n")
-               return 1
-       }
-
-       // FIXME: Check to make sure this is a valid full Xen version
-       fv := XenVersionFull(args[0])
-       args = args[1:]
-
-       v := fv.XenVersion()
-       if v == "error" {
-               fmt.Printf("Cannot get Xen release from %s\n", string(fv))
+// xsatool NNN init {xen,qemuu,qemut}
+func MainInit(xsa *XSAMeta, args []string) (ret int) {
+       if len(args) < 1 {
+               fmt.Printf("Not enough arguments\n")
                return 1
        }
 
+       // FIXME parse multiple trees
        tree, err := TreeFromString(args[0])
        if err != nil {
                fmt.Printf("Getting tree: %v\n", err)
@@ -92,32 +83,57 @@ func MainNewRecipe(xsa *XSAMeta, args []string) (ret int) {
        }
        args = args[1:]
 
+       sm := &G.config.Security
+
        // FIXME -- deal with multiple components
-       r := xsa.GetRecipe(v)
-
-       if r != nil {
-               // FIXME: Deal with colliding version numbers (only want one fullversion per
-               // xenversion)
-               fmt.Printf("Loaded existing metadata: %v\n", *r)
-               tr, prs := r.Recipes[tree]
-               if prs && tr.HasPatches() {
-                       fmt.Printf("Recipe for release %v component %s already exists (full version %v)\n",
-                               v, tree, r.XenVersionFull)
-                       return 1
+
+       // Check to see if there are already components
+       if len(xsa.Trees) != 0 {
+               // FIXME deal with this better
+               // Always overwrite old versions...?
+               fmt.Printf("Recipe for XSA %d exists!\n", xsa.XSA)
+               return 1
+       }
+
+       // Initialize a new xsa
+       xsa.Trees = []Tree{tree}
+       xsa.Recipes = make(map[XenVersion]*Recipe)
+
+       for v := range sm.Versions {
+               vm := sm.Versions[v]
+
+               xsa.SupportedVersions = append(xsa.SupportedVersions, v)
+
+               r := xsa.NewRecipe(vm.Latest)
+
+               for _, t := range xsa.Trees {
+                       tr := &TreeRecipe{}
+                       tr.Prereqs = append([]int{}, vm.XSAs[t]...)
+                       tr.Patches = []string{}
+
+                       r.Recipes[t] = tr
+
                }
-       } else {
-               r = xsa.NewRecipe(fv)
-               fmt.Printf("Made new metadata: %v\n", *r)
-               if r.xsa != xsa.XSA {
-                       fmt.Printf("xsanum didn't get set!\n")
+
+               err = r.Apply("xsa")
+               if err != nil {
+                       fmt.Printf("Applying initial recipe for version %v\n", v)
                        return 1
                }
        }
 
-       // FIXME: Deal with prerequisites
+       // Check out "xsa/NNN/master" on all relevant trees
+       branch, _ := BranchName("xsa", xsa.XSA, XenVersion("master"))
+       for _, t := range xsa.Trees {
+               _, err = G.repos.XenRepos[t].Checkout(branch)
+               if err != nil {
+                       fmt.Printf("Checkout out branch %s\n", branch)
+                       return 1
+               }
+       }
 
-       // Make appropriate branches (including prerequisites)
-       r.CreateBranch("xsa", tree)
+       fmt.Printf("Branch(es) %s created in the appropriate repositories."+
+               "  Create fix and run sync-patches.\n", branch)
 
        // Save 'empty' recipe
        err = xsa.Save()
@@ -126,5 +142,13 @@ func MainNewRecipe(xsa *XSAMeta, args []string) (ret int) {
                return 1
        }
 
+       sm.AddXSA(xsa)
+
+       err = sm.Save()
+       if err != nil {
+               fmt.Printf("Error saving global metadata: %v\n", err)
+               return 1
+       }
+
        return
 }