}
func OpenRepos() (err error) {
- repos.xen, err = XenRepoOpen(config.XenPath, XRXen)
+ repos.xen, err = XenRepoOpen(config.GetXenPath(), XRXen)
if err != nil {
return
}
- repos.qemuu, err = XenRepoOpen(config.QemuuPath, XRQemuu)
+ repos.qemuu, err = XenRepoOpen(config.GetQemuuPath(), XRQemuu)
if err != nil {
return
}
- repos.qemut, err = XenRepoOpen(config.QemutPath, XRQemut)
+ repos.qemut, err = XenRepoOpen(config.GetQemutPath(), XRQemut)
if err != nil {
return
}
func main() {
var main MainFunc
loadConfig := false
+ loadXSA := false
var xsanum int
var err error
case "sync-patches":
main = MainSyncPatches
loadConfig = true
+ loadXSA = true
case "sync-branch":
main = MainSyncBranch
loadConfig = true
+ loadXSA = true
case "test-apply":
main = MainTestApply
loadConfig = true
+ loadXSA = true
case "test-build":
main = MainTestBuild
loadConfig = true
+ loadXSA = true
case "test":
main = MainTest
loadConfig = true
+ loadXSA = true
default:
fmt.Printf("Unknown command: %s\n", cmd)
os.Exit(1)
switch cmd {
case "init":
main = MainRepoInit
+ case "info":
+ loadConfig = true
+ main = MainRepoInfo
default:
fmt.Printf("Unknown command: %s\n", cmd)
os.Exit(1)
}
if loadConfig {
- // FIXME: Load this from a file
-
- config.rootDir = "/build/hg/security"
- config.XSAPath = config.rootDir+"/xsa.git"
- config.XenPath = config.rootDir+"/xen.git"
- config.QemuuPath = config.rootDir+"/qemu-xen.git"
- config.QemutPath = config.rootDir+"/qemu-xen-traditional.git"
+ err := config.Load()
+ if err != nil {
+ fmt.Printf("Error finding config: %v\n", err)
+ os.Exit(1)
+ }
+ }
+ if loadXSA {
switch xsanum {
case 206:
xsa = XSAMeta{
// Load from the current directory
func (tc *ToolConfig) Load() (err error) {
+ var b []byte
if tc.rootDir == "" {
- tc.rootDir, err = os.Getwd()
+ var rootDir string
+ rootDir, err = os.Getwd()
if err != nil {
return fmt.Errorf("Trying to get wd: %v\n", err)
}
- }
-
- var b []byte
- path := tc.rootDir+"/"+ConfigFileName
- b, err = ioutil.ReadFile(path)
- if err != nil {
- return nil
+ for {
+ configpath := rootDir + "/" + ConfigFileName
+ b, err = ioutil.ReadFile(configpath)
+ if err == nil {
+ tc.rootDir = rootDir
+ break
+ }
+
+ if !os.IsNotExist(err) {
+ return fmt.Errorf("Trying to read %s: %v\n", configpath, err)
+ }
+
+ rootDir = path.Clean(rootDir+"/..")
+ if rootDir == "/" {
+ return fmt.Errorf("Couldn't find config file\n")
+ }
+ }
+ } else {
+ configpath := tc.rootDir+"/"+ConfigFileName
+ b, err = ioutil.ReadFile(configpath)
+ if err != nil {
+ return nil
+ }
}
err = json.Unmarshal(b, tc)
return
}
-// Look for the toolconfig by going up directories until we hit the root
-func (tc *ToolConfig) Find() (err error) {
- return
-}
-
func (tc ToolConfig) GetXSAPath() (s string) {
- return path.Clean(tc.rootDir + "/" + tc.XSAPath)
+ if tc.rootDir != "" && tc.XSAPath != "" {
+ return path.Clean(tc.rootDir + "/" + tc.XSAPath)
+ }
+ return
}
func (tc ToolConfig) GetXenPath() (s string) {
- return path.Clean(tc.rootDir + "/" + tc.XenPath)
+ if tc.rootDir != "" && tc.XenPath != "" {
+ return path.Clean(tc.rootDir + "/" + tc.XenPath)
+ }
+ return
}
func (tc ToolConfig) GetQemuuPath() (s string) {
- return path.Clean(tc.rootDir + "/" + tc.QemuuPath)
+ if tc.rootDir != "" && tc.QemuuPath != "" {
+ return path.Clean(tc.rootDir + "/" + tc.QemuuPath)
+ }
+ return
}
func (tc ToolConfig) GetQemutPath() (s string) {
- return path.Clean(tc.rootDir + "/" + tc.QemutPath)
+ if tc.rootDir != "" && tc.QemutPath != "" {
+ return path.Clean(tc.rootDir + "/" + tc.QemutPath)
+ }
+ return
}
type VersionMeta struct {
for _, glob := range tr.Prereqs {
// git am
- _, err = xr.AmClean(config.XSAPath+"/"+glob)
+ _, err = xr.AmClean(config.GetXSAPath()+"/"+glob)
if err != nil {
return fmt.Errorf("Appling am %s: %v\n", glob, err)
}
for _, glob := range tr.Patches {
// git am
- _, err = xr.AmClean(config.XSAPath+"/"+glob)
+ _, err = xr.AmClean(config.GetXSAPath()+"/"+glob)
if err != nil {
return fmt.Errorf("Appling am %s: %v\n", glob, err)
}
}
var err error
- if repos.xen, err = cloneXen(config.XenPath, "git://xenbits.xen.org/xen.git", XRXen); err != nil {
+ if repos.xen, err = cloneXen(config.XenPath, "git://xenbits.xenproject.org/xen.git", XRXen); err != nil {
fmt.Printf("Trying to clone Xen: %v\n", err)
return 1
}
- if repos.qemuu, err = cloneXen(config.QemuuPath, "git://xenbits.xen.org/qemu-xen.git", XRQemuu); err != nil {
+ if repos.qemuu, err = cloneXen(config.QemuuPath, "git://xenbits.xenproject.org/qemu-xen.git", XRQemuu); err != nil {
fmt.Printf("Trying to clone Qemuu: %v\n", err)
return 1
}
- if repos.qemut, err = cloneXen(config.QemutPath, "git://xenbits.xen.org/qemu-xen-traditional.git", XRQemut); err != nil {
+ if repos.qemut, err = cloneXen(config.QemutPath, "git://xenbits.xenproject.org/qemu-xen-traditional.git", XRQemut); err != nil {
fmt.Printf("Trying to clone Qemut: %v\n", err)
return 1
}
return 0
}
+
+func MainRepoInfo(xsanum int, args []string) (ret int) {
+ fmt.Printf("rootDir: %s\n", config.rootDir)
+ fmt.Printf("XSA repo: %s\n", config.GetXSAPath())
+ fmt.Printf("Xen repo: %s\n", config.GetXenPath())
+ fmt.Printf("Qemu Upstream repo: %s\n", config.GetQemuuPath())
+ fmt.Printf("Qemu Traditional repo: %s\n", config.GetQemutPath())
+ return 0
+}