Skip to content

Commit 4df8166

Browse files
committed
Upload now uses export folder
1 parent d915ee8 commit 4df8166

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

commands/upload/upload.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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,29 @@ 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+
if sketch.FullPath.IsDir() {
154+
importPath = sketch.FullPath
155+
} else {
156+
importPath = sketch.FullPath.Parent()
157+
}
158+
// Add FQBN (without configs part) to export path
159+
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
160+
importPath = importPath.Join("build").Join(fqbnSuffix)
163161
}
164162

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")
163+
if !importPath.Exist() {
164+
return nil, fmt.Errorf("compiled sketch not found in %s", importPath)
169165
}
170-
ext := filepath.Ext(outputTmpFile)
171-
if strings.HasSuffix(importFile, ext) {
172-
importFile = importFile[:len(importFile)-len(ext)]
166+
if !importPath.IsDir() {
167+
return nil, fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath)
173168
}
174-
175169
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-
}
170+
uploadProperties.Set("build.project_name", sketch.Name+".ino")
184171

185172
// Perform reset via 1200bps touch if requested
186173
if uploadProperties.GetBoolean("upload.use_1200bps_touch") {

0 commit comments

Comments
 (0)