@@ -129,16 +129,15 @@ func parseOutput(cmdOutToParse []byte) ([]*paths.Path, *ReturnJson) {
129
129
}
130
130
131
131
compilerOutLines := strings .Split (compileOutput .CompilerOut , "\n " )
132
- var coreLine string
132
+ var platformPath * paths. Path
133
133
for _ , compilerOutLine := range compilerOutLines {
134
134
logrus .Debug (compilerOutLine )
135
- if matched := strings .Contains (compilerOutLine , "Using core" ); matched {
136
- coreLine = compilerOutLine
137
- break // we should already have coreLine
135
+ if platformPath = parsePlatformLine (compilerOutLine ); platformPath != nil {
136
+ break
138
137
}
139
138
}
140
- if coreLine == "" {
141
- logrus .Fatal ("cannot find core used" )
139
+ if platformPath == nil {
140
+ logrus .Fatal ("cannot find platform used" )
142
141
}
143
142
144
143
// this dir contains all the obj files we need (the sketch related ones and not the core or libs)
@@ -157,27 +156,40 @@ func parseOutput(cmdOutToParse []byte) ([]*paths.Path, *ReturnJson) {
157
156
}
158
157
159
158
returnJson := ReturnJson {
160
- CoreInfo : parseCoreLine ( coreLine ),
159
+ CoreInfo : getCoreInfo ( platformPath ),
161
160
LibsInfo : compileOutput .BuilderResult .UsedLibraries ,
162
161
}
163
162
164
163
return returnObjectFilesList , & returnJson
165
164
}
166
165
167
- // parseCoreLine takes the line containing info regarding the core and
168
- // returns a Info object
169
- func parseCoreLine (coreLine string ) * Info {
170
- words := strings .Split (coreLine , " " )
171
- strCorePath := words [len (words )- 1 ] // last string has the path of the core
172
- corePath := paths .New (strCorePath )
173
- if ! corePath .Exist () {
174
- logrus .Fatalf ("the path of the core does not exists: %s" , corePath )
166
+ // getCoreInfo takes the path of the platform used and
167
+ // returns an Info object
168
+ func getCoreInfo (platformPath * paths.Path ) * Info {
169
+ if ! platformPath .Exist () {
170
+ logrus .Fatalf ("the path of the core does not exists: %s" , platformPath )
175
171
}
176
- corePathParents := corePath .Parents ()
172
+ corePathParents := platformPath .Parents ()
177
173
coreInfo := & Info {
178
174
Packager : corePathParents [3 ].Base (),
179
175
Name : corePathParents [1 ].Base (),
180
176
Version : corePathParents [0 ].Base (),
181
177
}
182
178
return coreInfo
183
179
}
180
+
181
+ // parsePlatformLine takes compilerOutLine as input and tries to extract the path of the platform used
182
+ // compilerOutLine should be something like:
183
+ // - Using core 'arduino' from platform in folder: C:\\Users\\Umberto Baldi\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\n
184
+ // - Using core 'arduino' from platform in folder: /home/umberto/.arduino15/packages/arduino/hardware/avr/1.8.4
185
+
186
+ func parsePlatformLine (compilerOutLine string ) * paths.Path {
187
+ if matched := strings .Contains (compilerOutLine , "Using core" ); matched {
188
+ // we use this approach to avoid path with spaces problem
189
+ if startIndex := strings .Index (compilerOutLine , "from platform in folder: " ); startIndex != - 1 {
190
+ startIndex = startIndex + len ("from platform in folder: " )
191
+ return paths .New (compilerOutLine [startIndex :])
192
+ }
193
+ }
194
+ return nil
195
+ }
0 commit comments