Skip to content

Commit cdc586f

Browse files
authored
Use loginterceptor in xcodecommand/xcbeautify and xcodecommand/xcpretty as well (#284)
1 parent 59044af commit cdc586f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

xcodecommand/xcbeautify.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import (
77
"io"
88
"os"
99
"os/exec"
10+
"regexp"
1011

1112
"github.com/bitrise-io/go-utils/v2/command"
1213
"github.com/bitrise-io/go-utils/v2/log"
1314
"github.com/bitrise-io/go-xcode/v2/errorfinder"
15+
"github.com/bitrise-io/go-xcode/v2/loginterceptor"
1416
version "github.com/hashicorp/go-version"
1517
)
1618

17-
const xcbeautify = "xcbeautify"
19+
const (
20+
xcbeautify = "xcbeautify"
21+
)
1822

1923
// XcbeautifyRunner is a xcodebuild runner that uses xcbeautify as log formatter
2024
type XcbeautifyRunner struct {
@@ -36,13 +40,21 @@ func (c *XcbeautifyRunner) Run(workDir string, xcodebuildArgs []string, xcbeauti
3640
buildOutBuffer bytes.Buffer
3741
pipeReader, pipeWriter = io.Pipe()
3842
buildOutWriter = io.MultiWriter(&buildOutBuffer, pipeWriter)
43+
prefixRegexp = regexp.MustCompile(prefix)
44+
interceptor = loginterceptor.NewPrefixInterceptor(prefixRegexp, os.Stdout, buildOutWriter, c.logger)
3945
)
4046

47+
defer func() {
48+
if err := interceptor.Close(); err != nil {
49+
c.logger.Warnf("Failed to close log interceptor, error: %s", err)
50+
}
51+
}()
52+
4153
// For parallel and concurrent destination testing, it helps to use unbuffered I/O for stdout and to redirect stderr to stdout.
4254
// NSUnbufferedIO=YES xcodebuild [args] 2>&1 | xcbeautify
4355
buildCmd := c.commandFactory.Create("xcodebuild", xcodebuildArgs, &command.Opts{
44-
Stdout: buildOutWriter,
45-
Stderr: buildOutWriter,
56+
Stdout: interceptor,
57+
Stderr: interceptor,
4658
Env: unbufferedIOEnv,
4759
Dir: workDir,
4860
ErrorFinder: errorfinder.FindXcodebuildErrors,

xcodecommand/xcpretty.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import (
66
"io"
77
"os"
88
"os/exec"
9+
"regexp"
910

1011
"github.com/bitrise-io/go-steputils/v2/ruby"
1112
"github.com/bitrise-io/go-utils/v2/command"
1213
"github.com/bitrise-io/go-utils/v2/fileutil"
1314
"github.com/bitrise-io/go-utils/v2/log"
1415
"github.com/bitrise-io/go-utils/v2/pathutil"
1516
"github.com/bitrise-io/go-xcode/v2/errorfinder"
17+
"github.com/bitrise-io/go-xcode/v2/loginterceptor"
18+
)
19+
20+
const (
21+
prefix = `^\[Bitrise.*\].*`
1622
)
1723

1824
// XcprettyCommandRunner is an xcodebuild command runner that uses xcpretty as log formatter
@@ -46,13 +52,21 @@ func (c *XcprettyCommandRunner) Run(workDir string, xcodebuildArgs []string, xcp
4652
pipeReader, pipeWriter = io.Pipe()
4753
buildOutWriter = io.MultiWriter(&buildOutBuffer, pipeWriter)
4854
prettyOutWriter = os.Stdout
55+
prefixRegexp = regexp.MustCompile(prefix)
56+
interceptor = loginterceptor.NewPrefixInterceptor(prefixRegexp, os.Stdout, buildOutWriter, c.logger)
4957
)
5058

59+
defer func() {
60+
if err := interceptor.Close(); err != nil {
61+
c.logger.Warnf("Failed to close log interceptor, error: %s", err)
62+
}
63+
}()
64+
5165
c.cleanOutputFile(xcprettyArgs)
5266

5367
buildCmd := c.commandFactory.Create("xcodebuild", xcodebuildArgs, &command.Opts{
54-
Stdout: buildOutWriter,
55-
Stderr: buildOutWriter,
68+
Stdout: interceptor,
69+
Stderr: interceptor,
5670
Env: unbufferedIOEnv,
5771
Dir: workDir,
5872
ErrorFinder: errorfinder.FindXcodebuildErrors,

0 commit comments

Comments
 (0)