Skip to content

Commit 832c904

Browse files
authored
Merge pull request ejfitzgerald#9 from mathstuf/cache-stdout-without-exports
runClangTidyCommand: cache the stdout if no export-file is given
2 parents 2ceb392 + 3bbae5e commit 832c904

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

main.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func loadConfiguration() (*Configuration, error) {
7979
return &cfg, nil
8080
}
8181

82-
func streamOutput(file *os.File, closer io.ReadCloser) {
82+
func streamOutput(file *os.File, closer io.ReadCloser, result *[]byte) {
8383
defer closer.Close()
8484

8585
buffer := make([]byte, 1024)
@@ -93,36 +93,40 @@ func streamOutput(file *os.File, closer io.ReadCloser) {
9393
if err != nil {
9494
break
9595
}
96+
*result = append(*result, buffer[:n]...)
9697
}
9798
}
9899

99-
func runClangTidyCommand(cfg *Configuration, args []string) error {
100+
func runClangTidyCommand(cfg *Configuration, args []string) ([]byte, []byte, error) {
100101
cmd := exec.Command(cfg.ClangTidyPath, args...)
101102
stdout, err := cmd.StdoutPipe()
102103
if err != nil {
103-
return err
104+
return nil, nil, err
104105
}
105106

106107
stderr, err := cmd.StderrPipe()
107108
if err != nil {
108-
return err
109+
return nil, nil, err
109110
}
110111

112+
stdout_buffer := []byte{}
113+
stderr_buffer := []byte{}
114+
111115
// stream out the output of the command
112-
go streamOutput(os.Stdout, stdout)
113-
go streamOutput(os.Stderr, stderr)
116+
go streamOutput(os.Stdout, stdout, &stdout_buffer)
117+
go streamOutput(os.Stderr, stderr, &stderr_buffer)
114118

115119
err = cmd.Start()
116120
if err != nil {
117-
return err
121+
return nil, nil, err
118122
}
119123

120124
err = cmd.Wait()
121125
if err != nil {
122-
return err
126+
return nil, nil, err
123127
}
124128

125-
return nil
129+
return stdout_buffer, stderr_buffer, nil
126130
}
127131

128132
func shouldBypassCache(args []string) bool {
@@ -180,7 +184,7 @@ func evaluateTidyCommand(cfg *Configuration, wd string, args []string, cache cac
180184
}
181185

182186
// we need to run the command
183-
err := runClangTidyCommand(cfg, args)
187+
stdout, _, err := runClangTidyCommand(cfg, args)
184188
if err != nil {
185189
return err
186190
}
@@ -193,6 +197,8 @@ func evaluateTidyCommand(cfg *Configuration, wd string, args []string, cache cac
193197
if err != nil {
194198
return err
195199
}
200+
} else {
201+
content = stdout
196202
}
197203
err = cache.SaveEntry(fingerPrint, content)
198204
if err != nil {

0 commit comments

Comments
 (0)