]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
ToolConfig: Add MirrorDir and ProxyURL options
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 23 Jun 2017 16:56:29 +0000 (17:56 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 26 Jun 2017 11:22:20 +0000 (12:22 +0100)
If available, use in Repo.Build when building Xen to create .config.

To do this:

- Make a XenBuildConfig type that contains methods for adding configs
for URLs, as well as both the repo path and revision (for qemu-based patches)

- Write unit tests for these methods

Use these in Repo.Build.

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

diff --git a/meta.go b/meta.go
index 53ce3216fe3f38fd0d0c01390563c012075f4eaf..391078ff1542da9ec253a10307b14df622809ccf 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -40,6 +40,21 @@ func (t Tree) String() string {
        }
 }
 
+func (t Tree) RepoName() string {
+       switch t {
+       case TreeXen:
+               return "xen.git"
+       case TreeQemuU:
+               return "qemu-xen.git"
+       case TreeQemuT:
+               return "qemu-xen-traditional.git"
+       case TreeXSA:
+               return "xsa.git"
+       default:
+               return "[INVALID]"
+       }
+}
+
 func forEachTreeList(tl []Tree, f func(Tree) error) (err error) {
        for _, t := range tl {
                err = f(t)
@@ -60,6 +75,10 @@ func ForEachTree(f func(Tree) error) (err error) {
 
 type ToolConfig struct {
        Paths map[Tree]string
+       Cache struct {
+               MirrorDir string
+               ProxyURL  string
+       }
        // Not saved
        rootDir string
 }
@@ -131,6 +150,7 @@ func (tc *ToolConfig) Save() (err error) {
        }
 
        path := tc.rootDir + "/" + ConfigFileName
+       fmt.Printf("Writing config to path %s\n", path)
        err = ioutil.WriteFile(path, b, 0666)
        if err != nil {
                return fmt.Errorf("Writing config: %v", err)
index 4d03d86fb4a4528b509cb2308243230ce917bfb4..af2e31001bfe39147d8e552e46ec03315f9f5cc3 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -499,34 +499,30 @@ func (r *Recipe) Build(prefix string) (err error) {
                }
        }
 
-       // FIXME: Make configurable
-       mirrorpath := "/build/mirror/"
-
        // Make .config file with path to repos
-       var config string
-
-       config += "OVMF_UPSTREAM_URL ?= file://" + mirrorpath + "ovmf.git\n"
-       config += "SEABIOS_UPSTREAM_URL ?= file://" + mirrorpath + "seabios.git\n"
-       config += "MINIOS_UPSTREAM_URL ?= file://" + mirrorpath + "mini-os.git\n"
-
-       if tr, prs := r.Recipes[TreeQemuU]; prs && tr.HasPatches() {
-               config += "QEMU_UPSTREAM_URL ?= file://" + G.repos.XenRepos[TreeQemuU].GetPath() + "\n"
-               config += "QEMU_UPSTREAM_REVISION = origin/" + branch + "\n"
-       } else {
-               config += "QEMU_UPSTREAM_URL ?= file://" + mirrorpath + "qemu-xen.git\n"
+       var config XenBuildConfig
+
+       // Inherits `branch` and `config`
+       gitURLXSARepoConfig := func(configSpec string, tree Tree) {
+               if tr, prs := r.Recipes[tree]; prs && tr.HasPatches() {
+                       config.AddRepoPathAndRevision(configSpec,
+                               "file://"+G.repos.XenRepos[tree].GetPath(),
+                               branch)
+               } else {
+                       config.AddRepoCachedURL(configSpec, tree.RepoName())
+               }
        }
 
-       if tr, prs := r.Recipes[TreeQemuT]; prs && tr.HasPatches() {
-               config += "QEMU_TRADITIONAL_URL ?= file://" + G.repos.XenRepos[TreeQemuT].GetPath() + "\n"
-               config += "QEMU_TRADITIONAL_REVISION = origin/" + branch + "\n"
-       } else {
-               config += "QEMU_TRADITIONAL_URL ?= file://" + mirrorpath + "qemu-xen-traditional.git\n"
-       }
+       config.AddRepoCachedURL("OVMF_UPSTREAM", "ovmf.git")
+       config.AddRepoCachedURL("SEABIOS_UPSTREAM", "seabios.git")
+       config.AddRepoCachedURL("MINIOS_UPSTREAM", "mini-os.git")
 
-       fmt.Printf("Writing config file:\n%s\n", config)
+       gitURLXSARepoConfig("QEMU_UPSTREAM", TreeQemuU)
+       gitURLXSARepoConfig("QEMU_TRADITIONAL", TreeQemuT)
 
-       err = ioutil.WriteFile(xenrepo.GetPath()+"/.config", []byte(config), 0666)
-       if err != nil {
+       fmt.Printf("Writing build config file:\n%s\n", config)
+
+       if err = config.Write(xenrepo.GetPath()); err != nil {
                return fmt.Errorf("Writing config: %v\n", err)
        }
 
index 5d9fae1728ea0bc35d6bff11bb831a5de5d66390..5493a0713891658d3af562d48f6d57f0e6a5423a 100644 (file)
@@ -122,6 +122,10 @@ 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()
+
        updateBranches := func(t Tree) (err error) {
                var r *Repo
                if t == TreeXSA {
diff --git a/xen.go b/xen.go
index 19b726b49c560c335e30a9a607f07db7658f223a..d1aa76eca481d45c13847bf7708c73fe03fa235c 100644 (file)
--- a/xen.go
+++ b/xen.go
@@ -2,6 +2,7 @@ package main
 
 import (
        "fmt"
+       "io/ioutil"
        "math"
        "regexp"
        "strconv"
@@ -296,3 +297,42 @@ func (xr *XenRepo) GetVersions() (versions []XenVersionFull, err error) {
 
        return
 }
+
+// FIXME: The ideal here would actually be to pull all URLs with a git
+// reference out of Config.mk and add the git proxy if available
+type XenBuildConfig struct {
+       config string
+}
+
+func gitURL(repo string) (url string) {
+       cacheConfig := &G.config.Tool.Cache
+       if cacheConfig.MirrorDir != "" {
+               return "file://" + cacheConfig.MirrorDir + repo
+       }
+
+       // FIXME: Pull this out of Config.mk
+
+       url = "git://xenbits.xenproject.org/" + repo
+
+       if cacheConfig.ProxyURL != "" {
+               url = cacheConfig.ProxyURL + url
+       }
+
+       return
+}
+
+// Not really sure what to call "OVMF_UPSTREAM" part of
+// "OVMF_UPSTREAM_URL" and "OVMF_UPSTREAM_REPO"
+func (c *XenBuildConfig) AddRepoCachedURL(configSpec string, repo string) {
+       c.config += configSpec + "_URL ?= " + gitURL(repo) + "\n"
+}
+
+func (c *XenBuildConfig) AddRepoPathAndRevision(configSpec string, path string, revision string) {
+       c.config += configSpec + "_URL ?= file://" + path + "\n"
+       c.config += configSpec + "_REVISION ?= " + revision + "\n"
+}
+
+func (c *XenBuildConfig) Write(buildpath string) (err error) {
+       err = ioutil.WriteFile(buildpath+"/.config", []byte(c.config), 0666)
+       return
+}
index 6d18f04263f8a23ecb8ee262288ac6b15d160849..9b8d1bb717b77de2960d089d42f4174e51797a81 100644 (file)
@@ -217,3 +217,37 @@ func TestTagsToVersions(t *testing.T) {
        }
        // FIXME: if lengths are unequal, print the missing bits
 }
+
+func TestXenBuildConfig(t *testing.T) {
+       t.Logf("Testing config generation")
+
+       t.Logf(" ...with no proxy")
+
+       cacheConfig := &G.config.Tool.Cache
+
+       cacheConfig.MirrorDir = ""
+       cacheConfig.ProxyURL = ""
+
+       var config XenBuildConfig
+
+       cacheTest := func(expected string) {
+               config.AddRepoCachedURL("TEST", "test.git")
+
+               if config.config != expected {
+                       t.Errorf("Expected %s, got %s", expected, config.config)
+               }
+               config.config = ""
+       }
+       cacheTest("TEST_URL ?= git://xenbits.xenproject.org/test.git\n")
+
+       cacheConfig.MirrorDir = "/build/mirror/"
+       cacheTest("TEST_URL ?= file:///build/mirror/test.git\n")
+
+       cacheConfig.ProxyURL = "git://drall/?"
+       // MirrorDir overrides ProxyURL
+       cacheTest("TEST_URL ?= file:///build/mirror/test.git\n")
+
+       cacheConfig.MirrorDir = ""
+       // Now ProxyUrl should show up
+       cacheTest("TEST_URL ?= git://drall/?git://xenbits.xenproject.org/test.git\n")
+}