@@ -20,8 +20,6 @@ import (
20
20
"fmt"
21
21
"io"
22
22
"net/url"
23
- "os"
24
- "path/filepath"
25
23
"strings"
26
24
"time"
27
25
@@ -147,40 +145,25 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
147
145
uploadProperties .Set ("upload.verify" , uploadProperties .Get ("upload.params.noverify" ))
148
146
}
149
147
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
-
155
148
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 )
160
151
} 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 )
163
157
}
164
158
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 )
169
161
}
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 )
173
164
}
174
-
175
165
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" )
184
167
185
168
// Perform reset via 1200bps touch if requested
186
169
if uploadProperties .GetBoolean ("upload.use_1200bps_touch" ) {
0 commit comments