First ability to build itself.

master
Zed A. Shaw 3 weeks ago
parent 8d4e22c382
commit 81a3c7086d
  1. 4
      .gitignore
  2. 25
      .ttarpit.json
  3. 3
      config/settings.go
  4. 43
      main.go
  5. 10
      tools/cmd/tester/main.go

4
.gitignore vendored

@ -31,5 +31,5 @@ config.toml
public public
*.idx *.idx
*.sqlite3 *.sqlite3
./ttarpit ttarpit
./tester tester

@ -1,26 +1,11 @@
{ {
"Includes": [
"^.*.go$"
],
"Processes": { "Processes": {
"tester1": { "tester1": {
"Command": "tester", "Command": "make",
"Args": ["-count", "100", "-id", "1"] "Args": ["build"]
}
},
"Processes": {
"tester2": {
"Command": "tester",
"Args": ["-count", "100", "-id", "2"]
}
},
"Processes": {
"tester3": {
"Command": "tester",
"Args": ["-count", "100", "-id", "3"]
}
},
"Processes": {
"tester4": {
"Command": "tester",
"Args": ["-count", "100", "-id", "4"]
} }
} }
} }

@ -11,13 +11,14 @@ import (
type Process struct { type Process struct {
Command string Command string
Args []string Args []string
Ready chan string
ExecCmd *exec.Cmd ExecCmd *exec.Cmd
} }
type config struct { type config struct {
Processes map[string]Process Processes map[string]Process
Includes []string
ConfigPath string ConfigPath string
BuildRunning bool
} }
var Settings config var Settings config

@ -6,6 +6,9 @@ import (
"log" "log"
"io" "io"
"os" "os"
"time"
"slices"
"regexp"
"io/fs" "io/fs"
"path/filepath" "path/filepath"
"errors" "errors"
@ -13,7 +16,6 @@ import (
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
func LaunchLogger(in io.Reader, out io.Writer, err error) { func LaunchLogger(in io.Reader, out io.Writer, err error) {
if err != nil { log.Fatal(err) } if err != nil { log.Fatal(err) }
@ -25,7 +27,6 @@ func LaunchLogger(in io.Reader, out io.Writer, err error) {
} }
func LaunchProcess(proc *config.Process) { func LaunchProcess(proc *config.Process) {
for {
proc.ExecCmd = exec.Command(proc.Command, proc.Args...) proc.ExecCmd = exec.Command(proc.Command, proc.Args...)
if errors.Is(proc.ExecCmd.Err, exec.ErrDot) { if errors.Is(proc.ExecCmd.Err, exec.ErrDot) {
proc.ExecCmd.Err = nil proc.ExecCmd.Err = nil
@ -47,21 +48,46 @@ func LaunchProcess(proc *config.Process) {
fmt.Println("WAITING for", proc.Command) fmt.Println("WAITING for", proc.Command)
fmt.Println("SENDING READY on channel") fmt.Println("SENDING READY on channel")
proc.Ready<- "ready"
fmt.Println("SENT READY")
proc.ExecCmd.Wait() proc.ExecCmd.Wait()
fmt.Println("PROCESS", proc.Command, "EXITED") fmt.Println("PROCESS", proc.Command, "EXITED")
}
func MatchesPath(fp string) bool {
fp = filepath.ToSlash(fp)
is_included := slices.ContainsFunc(config.Settings.Includes, func (reg string) bool {
matches, err := regexp.MatchString(reg, fp)
if err != nil {
log.Panic("invalid excludes regex", reg, "error: ", err)
} }
return matches
})
return is_included
} }
func RunBuild() { func RunBuild() {
if !config.Settings.BuildRunning {
config.Settings.BuildRunning = true
defer func(){config.Settings.BuildRunning = false}()
fmt.Println("CONFIG:", config.Settings.ConfigPath) fmt.Println("CONFIG:", config.Settings.ConfigPath)
fmt.Println("COMMANDs:", config.Settings.Processes) fmt.Println("COMMANDs:", config.Settings.Processes)
for name, proc := range config.Settings.Processes { for name, proc := range config.Settings.Processes {
fmt.Println("PROCESS:", name) fmt.Println("PROCESS:", name)
proc.Ready = make(chan string)
LaunchProcess(&proc) LaunchProcess(&proc)
fmt.Println("=================== PROCESS EXIT")
}
time.Sleep(1000 * time.Millisecond)
} else {
fmt.Println("!!!! BUILD SKIP, already running")
} }
} }
@ -103,12 +129,15 @@ func WatchDir() {
if event.Has(fsnotify.Create) { if event.Has(fsnotify.Create) {
log.Println("---> CREATE", event.Name) log.Println("---> CREATE", event.Name)
// ADD DIR AddWatchDir(watcher, event.Name)
} else if event.Has(fsnotify.Write) {
// check if match then do thing
if MatchesPath(event.Name) {
go RunBuild()
}
} else { } else {
log.Println("event:", event) log.Println("event:", event)
} }
// check if match then do thing
go RunBuild()
case err, ok := <-watcher.Errors: case err, ok := <-watcher.Errors:
if !ok { if !ok {
return return

@ -13,7 +13,7 @@ func Worker(name string, count int, done chan<- int, stop <-chan int) {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
select { select {
case <-stop: case <-stop:
fmt.Println("Worker stopped:", name) fmt.Println("TESTER Worker stopped:", name)
done<- 1 done<- 1
return return
default: default:
@ -44,28 +44,26 @@ func Supervisor(id int, count int) {
select { select {
case <-workerDone: case <-workerDone:
fmt.Println("Supervisor: Worker Done") fmt.Println("TESTER Supervisor: Worker Done")
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
case <-stop: case <-stop:
fmt.Println("Supervisor: Stop") fmt.Println("TESTER Supervisor: Stop")
return return
} }
} }
}() }()
} }
/*
go func() { go func() {
// test shutdown // test shutdown
time.Sleep(10000 * time.Millisecond) time.Sleep(10000 * time.Millisecond)
fmt.Println("TESTER FORCE STOP!")
close(stop) close(stop)
}() }()
*/
wg.Wait() wg.Wait()
} }
func main() { func main() {
count := flag.Int("count", 10, "Seconds to wait") count := flag.Int("count", 10, "Seconds to wait")

Loading…
Cancel
Save