@@ -157,29 +157,26 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
157
157
// Start smart fetch process for the built sketch
158
158
var uploadPaths []* paths.Path
159
159
160
- // Search for built sketch to upload in CLI param importFile (if passed)...
161
- // ...or in the Export path (the Sketch Path)
162
-
163
160
// Set path to compiled binary
164
161
// Make the filename without the FQBN configs part
165
162
fqbn .Configs = properties .NewMap ()
166
163
fqbnSuffix := strings .Replace (fqbn .String (), ":" , "." , - 1 )
167
164
168
165
var importPath * paths.Path
169
166
var importFile string
170
- // If no importFile is passed, use sketch path
171
167
if req .GetImportFile () == "" {
168
+ // Search for built sketch to upload in CLI param importFile (if passed)...
172
169
importPath = sketch .FullPath
173
170
importFile = sketch .Name + "." + fqbnSuffix
174
171
} else {
172
+ // ...or in the Export path (the Sketch Path)
175
173
importPath = paths .New (req .GetImportFile ()).Parent ()
176
174
importFile = paths .New (req .GetImportFile ()).Base ()
177
175
}
178
176
179
177
// Remove file extension if any from input
180
- importFileExt := paths .New (importFile ).Ext ()
181
- if strings .HasSuffix (importFile , importFileExt ) {
182
- importFile = importFile [:len (importFile )- len (importFileExt )]
178
+ if strings .HasSuffix (importFile , ext ) {
179
+ importFile = importFile [:len (importFile )- len (ext )]
183
180
}
184
181
185
182
uploadPaths = append (uploadPaths , importPath .Join (importFile + ext ))
@@ -195,13 +192,14 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
195
192
fallbackBuildPath := builder .GenBuildPath (sketchPath )
196
193
// If we search inside the build.path, compile artifact do not have the fqbnSuffix in the filename
197
194
uploadPaths = append (uploadPaths , fallbackBuildPath .Join (sketch .Name + ".ino" + ext ))
195
+
198
196
for _ , p := range uploadPaths {
199
197
if _ , err := p .Stat (); err == nil {
200
198
uploadProperties .SetPath ("build.path" , p .Parent ())
201
199
name := p .Base ()
202
200
name = name [:len (name )- len (ext )]
203
201
uploadProperties .Set ("build.project_name" , name )
204
-
202
+ break
205
203
} else {
206
204
logrus .Warnf ("Built sketch opening error in %s: %s" , p , err )
207
205
}
@@ -305,14 +303,16 @@ func getExtensionFromRecipe(uploadProperties *properties.Map, err error) (string
305
303
for _ , t := range cmdArgs {
306
304
if strings .Contains (t , "build.project_name" ) {
307
305
uploadInputPath = paths .New (t )
306
+ break
308
307
}
309
308
}
310
309
311
310
if uploadInputPath == nil {
312
311
return "" , fmt .Errorf ("cannot find upload file extension in upload recipe" )
313
312
}
314
-
315
- return uploadInputPath .Ext (), nil
313
+ // trim extension from "}" and following recipe tokens as they could be erroneously included by the Ext() func
314
+ trimmedExt := strings .Split (uploadInputPath .Ext (), "}" )[0 ]
315
+ return trimmedExt , nil
316
316
}
317
317
318
318
func touchSerialPortAt1200bps (port string ) error {
0 commit comments