Can now run a build on itself and detect errors in the output.

master
Zed A. Shaw 3 weeks ago
parent 81a3c7086d
commit 1302a6d3e0
  1. 5
      .ttarpit.json
  2. 15
      config/settings.go
  3. 33
      main.go

@ -7,5 +7,8 @@
"Command": "make",
"Args": ["build"]
}
}
},
"Triggers": [
"(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"
]
}

@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"encoding/json"
"regexp"
)
type Process struct {
@ -15,10 +16,14 @@ type Process struct {
}
type config struct {
Processes map[string]Process
Triggers []string
Includes []string
Processes map[string]Process
ConfigPath string
BuildRunning bool
TriggerRegex []*regexp.Regexp
IncludeRegex []*regexp.Regexp
}
var Settings config
@ -36,4 +41,12 @@ func Load() {
err = json.Unmarshal(data, &Settings)
if err != nil { log.Fatal(err) }
for _, reg := range Settings.Triggers {
Settings.TriggerRegex = append(Settings.TriggerRegex, regexp.MustCompile(reg))
}
for _, reg := range Settings.Includes {
Settings.IncludeRegex = append(Settings.IncludeRegex, regexp.MustCompile(reg))
}
}

@ -7,22 +7,32 @@ import (
"io"
"os"
"time"
"slices"
"regexp"
"io/fs"
"path/filepath"
"errors"
"lcthw.dev/go/ttarpit/config"
"github.com/fsnotify/fsnotify"
"bufio"
)
func LaunchLogger(in io.Reader, out io.Writer, err error) {
if err != nil { log.Fatal(err) }
go func() {
if _, err := io.Copy(out, in)
scan := bufio.NewScanner(in)
err != nil { log.Printf("LOGGER: %v", err) }
for scan.Scan() {
for _, reg := range config.Settings.TriggerRegex {
line := scan.Text()
matches := reg.FindStringSubmatch(line)
if len(matches) > 0 {
file, line, col, err_type, text := matches[1], matches[2], matches[3], matches[4], matches[5]
fmt.Printf("!!!!!!!!!!!!!! file=%s, line=%s, col=%s, type=%s, text=%s\n",
file, line, col, err_type, text)
}
}
}
}()
}
@ -49,7 +59,6 @@ func LaunchProcess(proc *config.Process) {
fmt.Println("SENDING READY on channel")
fmt.Println("SENT READY")
proc.ExecCmd.Wait()
fmt.Println("PROCESS", proc.Command, "EXITED")
}
@ -57,17 +66,15 @@ func LaunchProcess(proc *config.Process) {
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)
for _, reg := range config.Settings.IncludeRegex {
matches := reg.MatchString(fp)
if err != nil {
log.Panic("invalid excludes regex", reg, "error: ", err)
if matches {
return true
}
}
return matches
})
return is_included
return false
}
func RunBuild() {

Loading…
Cancel
Save