From 1302a6d3e0efd2201cce75486cb8fb174685a9d1 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 26 Dec 2025 13:07:36 -0500 Subject: [PATCH] Can now run a build on itself and detect errors in the output. --- .ttarpit.json | 5 ++++- config/settings.go | 15 ++++++++++++++- main.go | 33 ++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/.ttarpit.json b/.ttarpit.json index b70b87c..c37b276 100644 --- a/.ttarpit.json +++ b/.ttarpit.json @@ -7,5 +7,8 @@ "Command": "make", "Args": ["build"] } - } + }, + "Triggers": [ + "(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*" + ] } diff --git a/config/settings.go b/config/settings.go index 4c4bd61..8283714 100644 --- a/config/settings.go +++ b/config/settings.go @@ -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)) + } } diff --git a/main.go b/main.go index 1bc7289..b641b8a 100644 --- a/main.go +++ b/main.go @@ -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() {