8
8
package checkpatch
9
9
10
10
import (
11
- "bytes"
12
11
"context"
13
12
"fmt"
14
13
"io"
15
14
"os"
16
15
"os/exec"
16
+ "path/filepath"
17
17
"strconv"
18
18
"strings"
19
19
@@ -76,15 +76,19 @@ func NewCheckpatch(ctx context.Context, file string, opts ...PatchOption) (*Patc
76
76
}
77
77
78
78
args := []string {
79
+ "--patch" ,
79
80
"--color=never" ,
81
+ "--root=" + filepath .Dir (filepath .Dir (filepath .Dir (patch .script ))),
80
82
}
81
83
82
84
// Add options from the conf file in the PR
83
85
content , err := os .ReadFile (patch .conf )
84
86
if err != nil {
85
87
return nil , fmt .Errorf ("could not read checkpatch configuration file: %w" , err )
86
88
}
87
- args = append (args , strings .Split (strings .TrimSpace (string (content )), "\n " )... )
89
+ for _ , line := range strings .Split (strings .TrimSpace (string (content )), "\n " ) {
90
+ args = append (args , strings .Split (line , " " )... )
91
+ }
88
92
89
93
// Extra ignores from the commits.
90
94
if len (patch .ignores ) > 0 {
@@ -97,27 +101,20 @@ func NewCheckpatch(ctx context.Context, file string, opts ...PatchOption) (*Patc
97
101
args = append (args , file )
98
102
99
103
c := exec .Command (patch .script , args ... )
104
+ c .Stderr = patch .stderr
100
105
c .Env = os .Environ ()
101
106
102
107
log .G (ctx ).Info (
103
108
strings .Join (append ([]string {patch .script }, args ... ), " " ),
104
109
)
105
110
106
- var b bytes.Buffer
107
- c .Stdout = & b
108
- c .Stderr = patch .stderr
109
-
110
- if err := c .Start (); err != nil {
111
- return nil , fmt .Errorf ("could not start checkpatch.pl: %w" , err )
111
+ var out []byte
112
+ if out , err = c .Output (); err != nil && out == nil {
113
+ return nil , fmt .Errorf ("running checkpatch.pl failed: %w" , err )
112
114
}
113
115
114
- // Checkpatch may return non-zero exit code, so we can safely ignore the
115
- // returning error here.
116
- _ = c .Wait ()
117
-
118
116
var note * Note
119
-
120
- for _ , line := range strings .Split (strings .TrimSuffix (b .String (), "\n " ), "\n " ) {
117
+ for _ , line := range strings .Split (strings .TrimSuffix (string (out ), "\n " ), "\n " ) {
121
118
if warning := strings .TrimPrefix (line , "WARNING:" ); len (warning ) < len (line ) {
122
119
split := strings .SplitN (warning , ":" , 2 )
123
120
if len (split ) != 2 {
0 commit comments