]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Load xsatool config from a file
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 31 Mar 2017 14:28:42 +0000 (15:28 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 31 Mar 2017 14:28:42 +0000 (15:28 +0100)
Recursively look for ".xsatool" in all directories going up until
there are no more.

Add 'repo info' command to read config and print info

Also:

 - Use config.GetXXXPath() to get normalized path rather than
   accessing config.XXXPath directly

 - Change config.GetXXXPath() to return NULL if either config.rootDir
   or config.XXXPath are undefined

 - Separate out XSA fake loading into a separate flag

 - use xenproject.org rather than xen.org for default configuration

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

diff --git a/main.go b/main.go
index a503a4dcfe7d0ab79a63bc56abe132abe3905ef4..8f87918853051b30aa456649e472d614963c2367 100644 (file)
--- a/main.go
+++ b/main.go
@@ -12,17 +12,17 @@ var repos struct {
 }
 
 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
        }
@@ -51,6 +51,7 @@ var xsa XSAMeta
 func main() {
        var main MainFunc
        loadConfig := false
+       loadXSA := false
        var xsanum int
        var err error
        
@@ -80,19 +81,24 @@ func main() {
                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)
@@ -101,6 +107,9 @@ func main() {
                switch cmd {
                case "init":
                        main = MainRepoInit
+               case "info":
+                       loadConfig = true
+                       main = MainRepoInfo
                default:
                        fmt.Printf("Unknown command: %s\n", cmd)
                        os.Exit(1)
@@ -108,14 +117,14 @@ func main() {
        }
        
        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{
diff --git a/meta.go b/meta.go
index 82158332bc898b105b6514314b804347d523761d..32573eedff48005750a614a7cd5c2966571c2da3 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -22,18 +22,36 @@ const ConfigFileName = ".xsatool"
 
 // 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)
@@ -58,25 +76,32 @@ func (tc *ToolConfig) Save() (err error) {
        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 {
index fc739f2bdb0c0885100508d4debde10c0b21bbd8..609ac95c88f6d603c2c1eec9b083f59556880c24 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -330,7 +330,7 @@ func (r *Recipe) Apply(prefix string) (err error) {
 
                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)
                        }
@@ -345,7 +345,7 @@ func (r *Recipe) Apply(prefix string) (err error) {
 
                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)
                        }
diff --git a/repo.go b/repo.go
index 25ea3ff2ee0e713f4e61974c05d2d9abd65e9e6b..ba3ef05515af394792d7a31d15907da0b1bc829f 100644 (file)
--- a/repo.go
+++ b/repo.go
@@ -92,15 +92,15 @@ func MainRepoInit(xsanum int, args []string) (ret int) {
        }
 
        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
        }
@@ -116,3 +116,12 @@ func MainRepoInit(xsanum int, args []string) (ret int) {
        
        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
+}