@@ -25,6 +25,7 @@ import (
25
25
"strings"
26
26
"time"
27
27
28
+ "github.com/arduino/arduino-cli/arduino/builder"
28
29
"github.com/arduino/arduino-cli/arduino/cores"
29
30
"github.com/arduino/arduino-cli/arduino/sketches"
30
31
"github.com/arduino/arduino-cli/cli/feedback"
@@ -156,6 +157,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
156
157
157
158
var importPath * paths.Path
158
159
var importFile string
160
+ // If no importFile is passed, use sketch path
159
161
if req .GetImportFile () == "" {
160
162
importPath = sketch .FullPath
161
163
importFile = sketch .Name + "." + fqbnSuffix
@@ -169,19 +171,52 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
169
171
if ! ok {
170
172
return nil , fmt .Errorf ("property 'recipe.output.tmp_file' not defined" )
171
173
}
174
+
172
175
ext := filepath .Ext (outputTmpFile )
173
176
if strings .HasSuffix (importFile , ext ) {
174
177
importFile = importFile [:len (importFile )- len (ext )]
175
178
}
176
179
180
+ // Check if the file ext we calculate is the same that is needed by the upload recipe
181
+ recipet := uploadProperties .Get ("upload.pattern" )
182
+ cmdLinet := uploadProperties .ExpandPropsInString (recipet )
183
+ cmdArgst , err := properties .SplitQuotedString (cmdLinet , `"'` , false )
184
+ var tPath * paths.Path
185
+ if err != nil {
186
+ return nil , fmt .Errorf ("invalid recipe '%s': %s" , recipet , err )
187
+ }
188
+ for _ , t := range cmdArgst {
189
+ if strings .Contains (t , "build.project_name" ) {
190
+ tPath = paths .New (t )
191
+ }
192
+ }
193
+
194
+ if ext != tPath .Ext () {
195
+ ext = tPath .Ext ()
196
+ }
197
+ //uploadRecipeInputFileExt :=
177
198
uploadProperties .SetPath ("build.path" , importPath )
178
199
uploadProperties .Set ("build.project_name" , importFile )
179
200
uploadFile := importPath .Join (importFile + ext )
180
201
if _ , err := uploadFile .Stat (); err != nil {
181
- if os .IsNotExist (err ) {
182
- return nil , fmt .Errorf ("compiled sketch %s not found " , uploadFile . String () )
202
+ if ! os .IsNotExist (err ) {
203
+ return nil , fmt .Errorf ("cannot open sketch: %s" , err )
183
204
}
184
- return nil , fmt .Errorf ("cannot open sketch: %s" , err )
205
+ // Built sketch not found in the provided path, let's fallback to the temp compile path
206
+ fallbackBuildPath := builder .GenBuildPath (sketchPath )
207
+ logrus .Warnf ("Built sketch not found in %s, let's fallback to %s" , uploadFile , fallbackBuildPath )
208
+ uploadProperties .SetPath ("build.path" , fallbackBuildPath )
209
+ // If we search inside the build.path, compile artifact do not have the fqbnSuffix in the filename
210
+ uploadFile = fallbackBuildPath .Join (sketch .Name + ".ino" + ext )
211
+ if _ , err := uploadFile .Stat (); err != nil {
212
+ if os .IsNotExist (err ) {
213
+ return nil , fmt .Errorf ("compiled sketch %s not found" , uploadFile .String ())
214
+ }
215
+ return nil , fmt .Errorf ("cannot open sketch: %s" , err )
216
+ }
217
+ // Clean from extension
218
+ uploadProperties .Set ("build.project_name" , sketch .Name + ".ino" )
219
+
185
220
}
186
221
187
222
// Perform reset via 1200bps touch if requested
0 commit comments