]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
repo init: Add --mirrordir and --gitproxy options
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 23 Jun 2017 16:56:36 +0000 (17:56 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 26 Jun 2017 11:22:59 +0000 (12:22 +0100)
...to set the appropriate proxy location.  Also add options to systemtest
to allow testing with those options.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
meta.go
repo.go
systemtest.go

diff --git a/meta.go b/meta.go
index 391078ff1542da9ec253a10307b14df622809ccf..a365eda6d1a51e02727d1666e23d305f3e4bd4b8 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -76,6 +76,7 @@ func ForEachTree(f func(Tree) error) (err error) {
 type ToolConfig struct {
        Paths map[Tree]string
        Cache struct {
+               // TODO Consider adding `json:",omitempty"`
                MirrorDir string
                ProxyURL  string
        }
diff --git a/repo.go b/repo.go
index 85e45dd99d642b3ff50fe585e03e69ec2797b7b8..5c345be5c349564b192006bfff5219a65ffeb609 100644 (file)
--- a/repo.go
+++ b/repo.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "flag"
        "fmt"
        "os"
 )
@@ -12,44 +13,52 @@ import (
 // Then attempt to clone the repositories and set them up so that push
 // is disabled by default.  Don't overwrite existing repositories
 // unless -f is specified.
+const EmptyString = "NONE"
+
 func MainRepoInit(unused *XSAMeta, args []string) (ret int) {
-       force := false
-
-       for len(args) > 0 {
-               arg := args[0]
-               args = args[1:]
-               switch arg {
-               case "-f":
-                       force = true
-               default:
-                       fmt.Printf("repoinit: Unknown argument: %s\n", arg)
-                       return 1
+       flags := flag.NewFlagSet("xsatool repo init", flag.ContinueOnError)
+
+       force := flags.Bool("force", false, "Re-clone repositories even if they already exist")
+
+       mirrorDir := flags.String("mirrordir", EmptyString,
+               "Directory containing git mirrors, used for building")
+       proxyURL := flags.String("gitproxy", EmptyString,
+               "Git proxy prefix, used for building")
+
+       if err := flags.Parse(args); err != nil {
+               if err != flag.ErrHelp {
+                       fmt.Printf("Error parsing args: %v\n", err)
                }
+               return 1
        }
 
-       fmt.Printf("Trying local config...\n")
        if err := G.config.Tool.Load(); err != nil {
                if os.IsNotExist(err) {
+                       fmt.Printf("Initializing new tool config")
                        G.config.Tool.Init()
                } else {
                        fmt.Printf("Error opening config file: %v\n", err)
                        return 1
                }
+       } else {
+               fmt.Printf("Using existing tool config in %s\n", G.config.Tool.rootDir)
+       }
+
+       if *mirrorDir != EmptyString {
+               G.config.Tool.Cache.MirrorDir = *mirrorDir
        }
 
-       defaultPath := map[Tree]string{
-               TreeXen:   "xen.git",
-               TreeQemuU: "qemu-xen.git",
-               TreeQemuT: "qemu-xen-traditional.git",
-               TreeXSA:   "xsa.git",
+       if *proxyURL != EmptyString {
+               G.config.Tool.Cache.ProxyURL = *proxyURL
        }
+
        setDefaultPath := func(tree Tree) (err error) {
                _, prs := G.config.Tool.Paths[tree]
                if prs {
                        fmt.Printf("Already set to %s\n", G.config.Tool.Paths[tree])
                } else {
-                       G.config.Tool.Paths[tree] = defaultPath[tree]
-                       fmt.Printf("Setting default: %s\n", defaultPath[tree])
+                       G.config.Tool.Paths[tree] = tree.RepoName()
+                       fmt.Printf("Setting default: %s\n", tree.RepoName())
                }
                return
        }
@@ -59,7 +68,7 @@ func MainRepoInit(unused *XSAMeta, args []string) (ret int) {
        checkDir := func(target string) (clone bool, err error) {
                _, err = os.Stat(target)
                if err == nil {
-                       if !force {
+                       if !*force {
                                fmt.Printf("%s exists, not forcing\n", target)
                                return false, nil
                        }
index 5493a0713891658d3af562d48f6d57f0e6a5423a..fdf50aa2c80bed99a8c60ca14ae0e5beafda6018 100644 (file)
@@ -20,8 +20,10 @@ func (st *SystemTest) Errorf(s string, args ...interface{}) {
 // if it exists (and leave clones for future callers)?
 
 var TestFlags struct {
-       Clean bool
-       Build bool
+       Clean     bool
+       Build     bool
+       MirrorDir string
+       ProxyURL  string
 }
 
 type InitialTreeState map[Tree]*map[string]string
@@ -103,8 +105,18 @@ func InitRepo(st *SystemTest) bool {
                st.Errorf("Getting topdir")
        }
 
+       repoargs := []string{"repo", "init"}
+
+       if TestFlags.MirrorDir != EmptyString {
+               repoargs = append(repoargs, "--mirrordir="+TestFlags.MirrorDir)
+       }
+
+       if TestFlags.ProxyURL != EmptyString {
+               repoargs = append(repoargs, "--gitproxy="+TestFlags.ProxyURL)
+       }
+
        // Initialize a current version of the repo
-       if ret := MainHarness("repo", "init"); ret != 0 {
+       if ret := MainHarness(repoargs...); ret != 0 {
                st.Errorf("repo init failed: %d\n", ret)
                return false
        }
@@ -122,9 +134,28 @@ func InitRepo(st *SystemTest) bool {
                return false
        }
 
-       //G.config.Tool.Cache.MirrorDir = "/build/mirror/"
-       //G.config.Tool.Cache.ProxyURL = "git://drall.uk.xensource.com:9419/"
-       //G.config.Tool.Save()
+       if TestFlags.MirrorDir != EmptyString &&
+               G.config.Tool.Cache.MirrorDir != TestFlags.MirrorDir {
+               st.Errorf("Unexpected MirrorDir: wanted %s, got %s!\n",
+                       TestFlags.MirrorDir,
+                       G.config.Tool.Cache.MirrorDir)
+               return false
+       }
+
+       if TestFlags.ProxyURL != EmptyString &&
+               G.config.Tool.Cache.ProxyURL != TestFlags.ProxyURL {
+               st.Errorf("Unexpected ProxyURL: wanted %s, got %s!\n",
+                       TestFlags.ProxyURL,
+                       G.config.Tool.Cache.ProxyURL)
+               return false
+       }
+
+       // Most repos are open after `repo init`, but xsa.git may not
+       // be if it wasn't cloned.
+       if err := OpenRepos(); err != nil {
+               st.Errorf("Opening repos: %v\n", err)
+               return false
+       }
 
        updateBranches := func(t Tree) (err error) {
                var r *Repo
@@ -564,6 +595,11 @@ func MainSystemTest(args []string) (ret int) {
        flags.BoolVar(&TestFlags.Clean, "clean", false, "Delete and re-clone repository before test.  Slower but more complete")
        flags.BoolVar(&TestFlags.Build, "build", false, "Do builds.")
 
+       flags.StringVar(&TestFlags.MirrorDir, "mirrordir", EmptyString,
+               "Pass specified --mirrordir to `repo init`")
+       flags.StringVar(&TestFlags.ProxyURL, "gitproxy", EmptyString,
+               "Pass specified --gitproxy to `repo init`")
+
        if err := flags.Parse(args); err != nil {
                if err != flag.ErrHelp {
                        fmt.Printf("Error parsing args: %v\n", err)