autotypist/globalBuildOptions.go

232 lines
6.0 KiB
Go

package main
import (
"os"
"os/user"
"path/filepath"
"go.wit.com/log"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
)
func globalBuildOptions(vbox *gui.Node) {
group1 := vbox.NewGroup("Global Build Options")
grid := group1.NewGrid("buildOptions", 0, 0)
// me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)")
me.userHomePwd = gadgets.NewOneLiner(grid, "user home")
grid.NextRow()
me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home")
grid.NextRow()
usr, _ := user.Current()
homeDir, err := os.UserHomeDir()
if err != nil {
log.Warn("Error getting home directory:", err)
homeDir = "/home/autotypist"
}
me.userHomePwd.SetText(homeDir)
srcDir := filepath.Join(homeDir, "go/src")
me.goSrcPwd.SetText(srcDir)
grid.NextRow()
me.stopOnErrors = grid.NewCheckbox("Stop on errors").SetChecked(true)
grid.NextRow()
me.autoDryRun = grid.NewCheckbox("autotypist --dry-run")
me.autoDryRun.Custom = func() {
if me.autoDryRun.Checked() {
os.Setenv("REPO_DRYRUN", "on")
} else {
os.Setenv("REPO_DRYRUN", "off")
}
}
me.autoDryRun.SetChecked(true)
grid.NextRow()
grid.NewGroup("git checkout")
// checking this will automatically make the branches off of devel
grid.NextRow()
me.autoCreateBranches = grid.NewCheckbox("auto-create {devel,user} branches").SetChecked(true)
me.autoCreateBranches.Custom = func() {
if me.autoCreateBranches.Checked() {
os.Setenv("AUTOTYPIST_CREATE_BRANCHES", "on")
} else {
os.Unsetenv("AUTOTYPIST_CREATE_BRANCHES")
}
}
grid.NextRow()
grid.NewButton("git checkout master branch", func() {
me.repos.View.ArgCheckoutMaster()
})
grid.NewLabel("") // set the order of these in the config file
grid.NextRow()
grid.NewButton("git checkout devel branch", func() {
me.repos.View.ArgCheckoutDevel()
})
grid.NewLabel("") // set the order of these in the config file
grid.NextRow()
grid.NewButton("git checkout "+usr.Username+" branch", func() {
me.repos.View.ArgCheckoutUser()
})
grid.NewLabel("")
grid.NextRow()
// select the branches you want to test, build and develop against
// let's call this the 'mode' ?
// this lets you select your user branch, but, when you are happy
// you can merge everything into the devel branch and make sure it actually
// works. Then, when that is good, merge and version everything in master
/*
if repo.Status.BranchExists(targetName) {
ok := repo.Status.CheckoutBranch(targetName)
if ok {
// checkout went fine
continue
}
log.Info("couldn't set", repo.Status.Path(), "branch to", targetName)
log.Info("but branch exists so something went wrong")
continue
}
if !me.autoCreateBranches.Checked() {
log.Info("not auto creating branch", targetName)
continue
}
// branch doesn't exist. make it
// todo: make this branch from 'devel' branch if it exists
log.Info("should make the", targetName, "branch here!")
if me.autoCreateBranches.Checked() {
log.Info("going to make the branch!")
repo.Status.RunCmd([]string{"git", "branch", targetName})
repo.Status.RunCmd([]string{"git", "checkout", targetName})
} else {
log.Info("not auto creating branch", targetName)
}
repo.Scan()
count += 1
*/
grid.NextRow()
grid.NewGroup("update all repos from upstream")
grid.NextRow()
grid.NewButton("git pull", func() {
me.Disable()
defer me.Enable()
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
repo.Run([]string{"git", "pull"})
}
})
grid.NextRow()
// TODO: fix this
grid.NewButton("git fetch", func() {
me.Disable()
defer me.Enable()
log.Warn("updating all master branches")
var count, failed int
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
var err error
var out string
count += 1
if err, out = repo.Status.FetchMaster(); err != nil {
log.Warn(repo.Name(), "fetch failed", err, out)
failed += 1
} else {
log.Warn(repo.Name(), "fetch sent:", out)
}
if err, out = repo.Status.FetchDevel(); err != nil {
log.Warn(repo.Name(), "fetch failed", err, out)
failed += 1
} else {
log.Warn(repo.Name(), "fetch sent:", out)
}
}
log.Warn("updated all master branches", count, "failed =", failed)
})
grid.NextRow()
grid.NewGroup("build")
grid.NextRow()
me.autoRebuildButton = grid.NewButton("rebuild autotypist", func() {
me.autoRebuildButton.Disable()
me.autoRebuildButton.SetLabel("running....")
attemptAutoRebuild()
me.autoRebuildButton.Enable()
me.autoRebuildButton.SetLabel("rebuild autotypist")
})
grid.NextRow()
grid.NewButton("go build", func() {
me.Disable()
defer me.Enable()
// r.showApps()
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
if repo.Hidden() {
// log.Info("skip hidden", repo.String())
} else {
log.Info("try to build", repo.Name())
if repo.Status.Build() {
log.Info("build worked", repo.Name())
} else {
log.Info("build failed", repo.Name())
go repo.Status.Xterm("bash")
return
}
}
}
log.Info("")
log.Info("every build worked !!!")
log.Info("")
})
grid.NextRow()
}
// this code isn't ready yet
/*
s.checkB = s.grid.NewButton("Check repos are working", func() {
me.Disable()
defer me.Enable()
for loop.Scan() {
if repo.GitURL() != "" {
log.Info("repo already checked. do they match?")
log.Info("go.wit.com =", repo.GoURL())
log.Info("localurl =", repo.Path())
} else {
ok, giturl := gowit.CheckRegistered(repo)
if ok {
log.Info("is url correct?", repo.Path(), "vs", giturl)
repo.giturl = giturl
if giturl != repo.Path() {
log.Info("repo check failed", repo.String())
s.unknownOL.SetText(repo.String())
s.unknownOL.Show()
s.unknownSubmitB.Show()
return
}
} else {
log.Info("repo check failed", repo.String())
repo.giturl = "look in .git/config"
s.unknownOL.SetText(repo.String())
s.unknownOL.Show()
s.unknownSubmitB.Show()
return
}
}
}
s.checkB.SetText("GOOD")
})
*/