type ToolConfig struct {
Paths map[Tree]string
Cache struct {
+ // TODO Consider adding `json:",omitempty"`
MirrorDir string
ProxyURL string
}
package main
import (
+ "flag"
"fmt"
"os"
)
// 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
}
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
}
// 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
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
}
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
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)