summaryrefslogtreecommitdiff
path: root/doDownloadForge.go
blob: f6903706ee3c737807293ad3f5bbab4b916ea1e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

// An app to submit patches for the 30 GO GUI repos

import (
	"errors"
	"os"

	"go.wit.com/lib/fhelp"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

// download forge. A good way to check things work
func doDownloadForge() (string, error) {
	log.Info("download here")
	if path, err := fhelp.CheckCmd("go-clone"); err != nil {
		log.Info("go-clone missing", path, err)
		cmd := []string{"go", "install", "go.wit.com/apps/go-clone@latest"}
		shell.RunRealtime(cmd)
	}
	if _, err := fhelp.CheckCmd("autogenpb"); err != nil {
		cmd := []string{"go", "install", "go.wit.com/apps/autogenpb@latest"}
		shell.RunRealtime(cmd)
	}
	if _, err := fhelp.CheckCmd("go-mod-clean"); err != nil {
		cmd := []string{"go", "install", "go.wit.com/apps/go-mod-clean@latest"}
		shell.RunRealtime(cmd)
	}
	if path, err := fhelp.CheckCmd("go-clone"); err != nil {
		log.Info("can't prep build. you probably need ~/go/bin in your PATH", path, err)
		return "", errors.New("prep build failed")
	}
	var basecmd []string
	var cmd []string
	if me.forge.IsGoWork() {
		log.Info("Using go.work directory")
		basecmd = []string{"go-clone", "--work"}
	} else {
		basecmd = []string{"go-clone"}
	}
	// log.Info("Running:", cmd)
	// shell.RunRealtime(cmd)

	r := shell.Run([]string{"forge", "show"})
	if r.Error != nil {
		return "download go-mod-clean failed", r.Error
	}

	cmd = append(basecmd, "go.wit.com/apps/go-mod-clean")
	log.Info("Running:", cmd)
	r = shell.RunRealtime(cmd)
	if r.Error != nil {
		return "download go-mod-clean failed", r.Error
	}

	cmd = append(basecmd, "go.wit.com/apps/autogenpb")
	log.Info("Running:", cmd)
	r = shell.RunRealtime(cmd)
	if r.Error != nil {
		return "download autogenpb failed", r.Error
	}

	cmd = append(basecmd, "go.wit.com/apps/forge")
	log.Info("Running:", cmd)
	r = shell.RunRealtime(cmd)
	if r.Error != nil {
		me.sh.BadExit("download forge failed", r.Error)
	}

	cmd = append(basecmd, "go.wit.com/toolkits/gocui")
	log.Info("Running:", cmd)
	r = shell.RunRealtime(cmd)
	if r.Error != nil {
		me.sh.BadExit("download CUI GO plugin toolkit failed", r.Error)
	}

	cmd = append(basecmd, "go.wit.com/toolkits/andlabs")
	log.Info("Running:", cmd)
	r = shell.RunRealtime(cmd)
	if r.Error != nil {
		me.sh.BadExit("download GTK GO plugin toolkit failed", r.Error)
	}

	if (me.forge == nil) || (me.forge.Repos == nil) {
		log.Info("RUN forge --rebuild again. it might work after a few tries")
		return "forge is new. this may not work yet", errors.New("forge init not working yet")
	}
	repo := me.forge.Repos.FindByNamespace("go.wit.com/apps/forge")
	if repo != nil {
		r := shell.Run([]string{"forge", "show"})
		return "failed the first go around. run it again. this feature is new", r.Error
	}
	// yay. it might work
	os.Chdir(repo.FullPath)
	r = shell.Run([]string{"make", "generate"})
	return "make generate might have worked", r.Error
}