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", "Command": "make",
"Args": ["build"] "Args": ["build"]
} }
} },
"Triggers": [
"(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"
]
} }

@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"encoding/json" "encoding/json"
"regexp"
) )
type Process struct { type Process struct {
@ -15,10 +16,14 @@ type Process struct {
} }
type config struct { type config struct {
Processes map[string]Process Triggers []string
Includes []string Includes []string
Processes map[string]Process
ConfigPath string ConfigPath string
BuildRunning bool BuildRunning bool
TriggerRegex []*regexp.Regexp
IncludeRegex []*regexp.Regexp
} }
var Settings config var Settings config
@ -36,4 +41,12 @@ func Load() {
err = json.Unmarshal(data, &Settings) err = json.Unmarshal(data, &Settings)
if err != nil { log.Fatal(err) } 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" "io"
"os" "os"
"time" "time"
"slices"
"regexp"
"io/fs" "io/fs"
"path/filepath" "path/filepath"
"errors" "errors"
"lcthw.dev/go/ttarpit/config" "lcthw.dev/go/ttarpit/config"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"bufio"
) )
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) }
go func() { 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("SENDING READY on channel")
fmt.Println("SENT READY")
proc.ExecCmd.Wait() proc.ExecCmd.Wait()
fmt.Println("PROCESS", proc.Command, "EXITED") fmt.Println("PROCESS", proc.Command, "EXITED")
} }
@ -57,17 +66,15 @@ func LaunchProcess(proc *config.Process) {
func MatchesPath(fp string) bool { func MatchesPath(fp string) bool {
fp = filepath.ToSlash(fp) fp = filepath.ToSlash(fp)
is_included := slices.ContainsFunc(config.Settings.Includes, func (reg string) bool { for _, reg := range config.Settings.IncludeRegex {
matches, err := regexp.MatchString(reg, fp) matches := reg.MatchString(fp)
if err != nil { if matches {
log.Panic("invalid excludes regex", reg, "error: ", err) return true
} }
}
return matches return false
})
return is_included
} }
func RunBuild() { func RunBuild() {

Loading…
Cancel
Save