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>
}
}
+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)
type ToolConfig struct {
Paths map[Tree]string
+ Cache struct {
+ MirrorDir string
+ ProxyURL string
+ }
// Not saved
rootDir string
}
}
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)
}
}
- // 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)
}
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 {
import (
"fmt"
+ "io/ioutil"
"math"
"regexp"
"strconv"
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
+}
}
// 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")
+}