// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "fmt" "os" "path/filepath" "strings" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func doBuild() error { if argv.Build.Install != nil { if err := doInstall(); err != nil { log.Info("doInstall() failed", err) badExit(err) } okExit("EVERYTHING BUILT!") } if argv.Build.MacBuild != nil { log.Info("todo: add mac builds") return nil } if argv.Build.Debian != nil { doDebian() okExit("") } return nil } func doInstallRepo(check *gitpb.Repo) error { repotype := check.GetRepoType() if repotype == "binary" || repotype == "plugin" { // we only want to process things that can be compiled with 'go build' } else { // log.Info("skipping repo", check.GetGoPath(), repotype) return nil } if me.forge.Config.IsReadOnly(check.GetGoPath()) { // ignore read only stuff return nil } if argv.Verbose || argv.Force { verbose := []string{"-v", "-x"} if err := me.forge.Install(check, verbose); err != nil { log.Warn("INSTALL FAILED", check.GetGoPath(), err) return err } } else { if err := me.forge.Install(check, nil); err != nil { log.Warn("INSTALL FAILED", check.GetGoPath(), err) return err } } return nil } func doInstallScan() { all := me.forge.Repos.SortByFullPath() for all.Scan() { check := all.Next() repotype := check.GetRepoType() if repotype == "binary" || repotype == "plugin" { // we only want to process things that can be compiled with 'go build' } else { // log.Info("skipping repo", check.GetGoPath(), repotype) continue } if me.forge.Config.IsReadOnly(check.GetGoPath()) { // ignore read only stuff continue } if check.GetState() == "" || check.GetState() == "PERFECT" { check.State = "need to build" } // var cmd []string var start string var end string manufactured := check.GetCurrentVersion() ver := trimNonNumericFromStart(manufactured) name := me.forge.Config.DebName(check.GetGoPath()) var realver string if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil { realver = installedPackage.Version } if actualp := me.machine.FindByVersion(name, ver); actualp != nil { end += " (version match) " + actualp.Version + " " + ver + " " check.State = "on mirrors" } else { if realver != "" { end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver) } // end += "" + ver + " " } if me.machine.IsInstalled(name) { if actualp := me.machine.FindInstalledByName(name); actualp != nil { if ver != actualp.Version { end += "(installed " + actualp.Version + ") " } else { end += "(installed ok) " } } else { end += "(installed) " } } debname := name + "_" + ver + "_amd64.deb" // debnames[check] = debname outdir := getOutdir(check) _, err := os.Stat(filepath.Join(outdir, debname)) if err == nil { // log.Info("exists", filepath.Join(outdir, debname)) check.State = "in incoming" } else { // log.Info(debname, "does not exist") } state := check.GetState() // todo: get all this shit into the protobuf start = fmt.Sprintf("%-18.18s %-24s %-50s", state, ver, debname) if strings.HasPrefix(check.GetState(), "unknown bran") { state = "need to build" } if state == "need to build" { end = "(will build)" + end } end = strings.TrimSpace(end) if end == "" { end = check.GetState() } log.Info(start, check.GetRepoType(), end) if name == "" { // err := fmt.Sprintf("name is blank error %+v", repo) log.Warn("name is blank error", check.GetGoPath()) } } } func doInstall() error { initForge() doInstallScan() found := gitpb.NewRepos() for check := range me.forge.Repos.IterAll() { if me.forge.Config.IsReadOnly(check.GetGoPath()) { continue } if !check.IsBinary() { continue } if check.IsGoPlugin() { continue } found.Append(check) } me.forge.PrintForgedTable(found) if argv.DryRun { okExit("") } me.forge.ConfigRill(16, 16) stats := me.forge.RunOnRepos(found, doInstallRepo) for s, stat := range stats { if stat.Err == nil { continue } dur := stat.End.Sub(stat.Start) log.Info("CRAP. INSTALL FAILED", shell.FormatDuration(dur), s, stat.Err) badExit(stat.Err) } os.Remove(filepath.Join(me.homedir, "go/bin/forged")) return nil }