Skip to content

Commit dd40d76

Browse files
avdvachew22
authored andcommitted
Make Info return stderr buffer
1 parent 613fe58 commit dd40d76

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

internal/bazel/bazel.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ type Bazel interface {
133133
SetStartupArgs([]string)
134134
WriteToStderr(v bool)
135135
WriteToStdout(v bool)
136-
Info() (map[string]string, error)
137136
Query(args ...string) (*blaze_query.QueryResult, error)
137+
Info() (map[string]string, *bytes.Buffer, error)
138138
CQuery(args ...string) (*analysis.CqueryResult, error)
139139
Build(args ...string) (*bytes.Buffer, error)
140140
Norun(args ...string) (*bytes.Buffer, error)
@@ -235,10 +235,10 @@ func (b *bazel) newCommand(command string, args ...string) (*bytes.Buffer, *byte
235235
// 'bazel help info-keys'.
236236
//
237237
// res, err := b.Info()
238-
func (b *bazel) Info() (map[string]string, error) {
238+
func (b *bazel) Info() (map[string]string, *bytes.Buffer, error) {
239239
b.WriteToStderr(false)
240240
b.WriteToStdout(false)
241-
stdoutBuffer, _ := b.newCommand("info")
241+
stdoutBuffer, stderrBuffer := b.newCommand("info")
242242

243243
// This gofunction only prints if 'bazel info' takes longer than 8 seconds
244244
doneCh := make(chan struct{})
@@ -254,9 +254,10 @@ func (b *bazel) Info() (map[string]string, error) {
254254

255255
err := b.cmd.Run()
256256
if err != nil {
257-
return nil, err
257+
return nil, nil, err
258258
}
259-
return b.processInfo(stdoutBuffer.String())
259+
result, err := b.processInfo(stdoutBuffer.String())
260+
return result, stderrBuffer, err
260261
}
261262

262263
func (b *bazel) processInfo(info string) (map[string]string, error) {

internal/bazel/testing/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func (b *MockBazel) WriteToStderr(v bool) {
5757
func (b *MockBazel) WriteToStdout(v bool) {
5858
b.actions = append(b.actions, []string{"WriteToStdout", fmt.Sprint(v)})
5959
}
60-
func (b *MockBazel) Info() (map[string]string, error) {
60+
func (b *MockBazel) Info() (map[string]string, *bytes.Buffer, error) {
6161
b.actions = append(b.actions, []string{"Info"})
62-
return map[string]string{}, nil
62+
return map[string]string{}, nil, nil
6363
}
6464
func (b *MockBazel) AddQueryResponse(query string, res *blaze_query.QueryResult) {
6565
if b.queryResponse == nil {

internal/ibazel/ibazel.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func New(version string) (*IBazel, error) {
114114
lifecycleHooks,
115115
}
116116

117-
info, _ := i.getInfo()
117+
info, stderrBuffer, _ := i.getInfo()
118118
for _, l := range i.lifecycleListeners {
119119
l.Initialize(&info)
120120
}
@@ -468,16 +468,16 @@ func (i *IBazel) queryRule(rule string) (*blaze_query.Rule, error) {
468468
return nil, errors.New("No information available")
469469
}
470470

471-
func (i *IBazel) getInfo() (map[string]string, error) {
471+
func (i *IBazel) getInfo() (map[string]string, *bytes.Buffer, error) {
472472
b := i.newBazel()
473473

474-
res, err := b.Info()
474+
res, stderrBuffer, err := b.Info()
475475
if err != nil {
476476
log.Errorf("Error getting Bazel info %v", err)
477-
return nil, err
477+
return nil, nil, err
478478
}
479479

480-
return res, nil
480+
return res, stderrBuffer, nil
481481
}
482482

483483
func (i *IBazel) queryForSourceFiles(query string) ([]string, error) {

internal/ibazel/ibazel_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func (i *IBazel) realLocalRepositoryPaths() (map[string]string, error) {
31-
info, err := i.getInfo()
31+
info, _, err := i.getInfo()
3232
if err != nil {
3333
log.Errorf("Error finding bazel info: %v\n", err)
3434
return nil, err

0 commit comments

Comments
 (0)