@@ -20,8 +20,6 @@ import (
2020 "fmt"
2121 "io"
2222 "net/url"
23- "os"
24- "path/filepath"
2523 "strings"
2624 "time"
2725
@@ -147,40 +145,25 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
147145 uploadProperties .Set ("upload.verify" , uploadProperties .Get ("upload.params.noverify" ))
148146 }
149147
150- // Set path to compiled binary
151- // Make the filename without the FQBN configs part
152- fqbn .Configs = properties .NewMap ()
153- fqbnSuffix := strings .Replace (fqbn .String (), ":" , "." , - 1 )
154-
155148 var importPath * paths.Path
156- var importFile string
157- if req .GetImportFile () == "" {
158- importPath = sketch .FullPath
159- importFile = sketch .Name + "." + fqbnSuffix
149+ if importDir := req .GetImportDir (); importDir != "" {
150+ importPath = paths .New (importDir )
160151 } else {
161- importPath = paths .New (req .GetImportFile ()).Parent ()
162- importFile = paths .New (req .GetImportFile ()).Base ()
152+ // TODO: Create a function to obtain importPath from sketch
153+ importPath = sketch .FullPath
154+ // Add FQBN (without configs part) to export path
155+ fqbnSuffix := strings .Replace (fqbn .StringWithoutConfig (), ":" , "." , - 1 )
156+ importPath = importPath .Join ("build" ).Join (fqbnSuffix )
163157 }
164158
165- outputTmpFile , ok := uploadProperties .GetOk ("recipe.output.tmp_file" )
166- outputTmpFile = uploadProperties .ExpandPropsInString (outputTmpFile )
167- if ! ok {
168- return nil , fmt .Errorf ("property 'recipe.output.tmp_file' not defined" )
159+ if ! importPath .Exist () {
160+ return nil , fmt .Errorf ("compiled sketch not found in %s" , importPath )
169161 }
170- ext := filepath .Ext (outputTmpFile )
171- if strings .HasSuffix (importFile , ext ) {
172- importFile = importFile [:len (importFile )- len (ext )]
162+ if ! importPath .IsDir () {
163+ return nil , fmt .Errorf ("expected compiled sketch in directory %s, but is a file instead" , importPath )
173164 }
174-
175165 uploadProperties .SetPath ("build.path" , importPath )
176- uploadProperties .Set ("build.project_name" , importFile )
177- uploadFile := importPath .Join (importFile + ext )
178- if _ , err := uploadFile .Stat (); err != nil {
179- if os .IsNotExist (err ) {
180- return nil , fmt .Errorf ("compiled sketch %s not found" , uploadFile .String ())
181- }
182- return nil , fmt .Errorf ("cannot open sketch: %s" , err )
183- }
166+ uploadProperties .Set ("build.project_name" , sketch .Name + ".ino" )
184167
185168 // Perform reset via 1200bps touch if requested
186169 if uploadProperties .GetBoolean ("upload.use_1200bps_touch" ) {
0 commit comments