@@ -20,6 +20,7 @@ var RegexCompile string = `^.*-?(gcc|clang|cc|g\+\+|c\+\+|clang\+\+)-?.*(\.exe)?
20
20
var RegexFile string = `^.*\s-c.*\s(.*\.(c|cpp|cc|cxx|c\+\+|s|m|mm|cu))(\s.*$|$)`
21
21
22
22
// Internal variables used to parse build log entries
23
+ var cd_regex = regexp .MustCompile (`^.*cd\s(.*?)\s(;|&|\|)` )
23
24
var sh_regex = regexp .MustCompile (`^.*(;|&&|&|\|)` )
24
25
var compile_regex * regexp.Regexp
25
26
var file_regex * regexp.Regexp
@@ -71,11 +72,13 @@ func commandProcess(line string, workingDir string) ([]string, string) {
71
72
72
73
func Parse (buildLog []string ) {
73
74
var (
74
- err error
75
- workingDir string
76
- exclude_regex * regexp.Regexp
77
- cmdCnt = 0
78
- result []Command
75
+ err error
76
+ workingDir = ""
77
+ backupWorkingDir = ""
78
+ exclude_regex * regexp.Regexp
79
+ cmdCnt = 0
80
+ result []Command
81
+ matchGroup []string
79
82
)
80
83
81
84
// check workingDir
@@ -94,7 +97,7 @@ func Parse(buildLog []string) {
94
97
95
98
dirStack := []string {workingDir }
96
99
97
- //init regex
100
+ // init regex
98
101
if ParseConfig .Exclude != "" {
99
102
exclude_regex , err = regexp .Compile (ParseConfig .Exclude )
100
103
if err != nil {
@@ -117,6 +120,13 @@ func Parse(buildLog []string) {
117
120
line = strings .TrimSpace (line )
118
121
log .Debug ("New command:" , line )
119
122
123
+ // Restore workingDir
124
+ if backupWorkingDir != "" {
125
+ workingDir = backupWorkingDir
126
+ backupWorkingDir = ""
127
+ log .Infof ("Restore workingDir: %s" , workingDir )
128
+ }
129
+
120
130
// Parse directory that make entering/leaving
121
131
if make_enter_dir .MatchString (line ) {
122
132
group := make_enter_dir .FindStringSubmatch (line )
@@ -138,6 +148,19 @@ func Parse(buildLog []string) {
138
148
continue
139
149
}
140
150
151
+ // Parse cd xx
152
+ matchGroup = cd_regex .FindStringSubmatch (line )
153
+ if matchGroup != nil {
154
+ backupWorkingDir = workingDir
155
+ cdPath := matchGroup [1 ]
156
+ if IsAbsPath (cdPath ) == false {
157
+ workingDir = workingDir + "/" + cdPath
158
+ } else {
159
+ workingDir = cdPath
160
+ }
161
+ log .Infof ("Temporarily change workingDir: %s" , workingDir )
162
+ }
163
+
141
164
if checking_make .MatchString (line ) {
142
165
continue
143
166
}
0 commit comments