Skip to content

Commit

Permalink
fix: decode make output
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying committed Sep 22, 2024
1 parent 9536440 commit f972d38
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .tasks
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[build]
# command=go run ./cmd/compiledb/main.go -v
command=go run ./cmd/compiledb/main.go -v -c --full-path < ./tests/build.log
cwd=$(VIM_ROOT)
output=terminal

[release]
command=go install ./cmd/compiledb
cwd=$(VIM_ROOT)
output=terminal
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.3
require (
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli/v2 v2.27.3
golang.org/x/text v0.18.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGC
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
23 changes: 20 additions & 3 deletions internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,32 @@ func MakeWrap(args []string) {

if ParseConfig.NoBuild == false {
cmd := exec.Command("make", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Error("Error:", err)
return
}
stderr, err := cmd.StderrPipe()
if err != nil {
log.Error("Error:", err)
return
}

if err := cmd.Start(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
StatusCode = exitError.ExitCode()
log.Errorf("make failed! errorCode: %d", StatusCode)
}
}

go TransferPrintScanner(stdout)
go TransferPrintScanner(stderr)

if err := cmd.Wait(); err != nil {
log.Error("Error:", err)
}
}

wg.Wait()
Expand Down
24 changes: 24 additions & 0 deletions internal/util.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package internal

import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"strings"

log "github.com/sirupsen/logrus"
"golang.org/x/text/encoding/simplifiedchinese"
)

func FileExist(filename string) bool {
Expand Down Expand Up @@ -42,3 +48,21 @@ func IsAbsPath(path string) bool {
}
return false
}

func TransferPrintScanner(in io.ReadCloser) {
decoder := simplifiedchinese.GB18030.NewDecoder()
scanner := bufio.NewScanner(in)

for scanner.Scan() {
result, err := decoder.String(scanner.Text())
if err != nil {
log.Error("decode failed!", scanner.Text())
result = ""
}
fmt.Println(result)
}

if err := scanner.Err(); err != nil {
log.Error("Error reading scanner:", err)
}
}

0 comments on commit f972d38

Please sign in to comment.