Skip to content

Commit 252acf9

Browse files
committed
Upload now uses export folder
1 parent a5bf516 commit 252acf9

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

Diff for: commands/debug/debug.go

+16-28
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out
115115

116116
// getCommandLine compose a debug command represented by a core recipe
117117
func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) ([]string, error) {
118+
if req.GetImportFile() != "" {
119+
return nil, errors.New("the ImportFile parameter has been deprecated, use ImportDir instead")
120+
}
121+
118122
// TODO: make a generic function to extract sketch from request
119123
// and remove duplication in commands/compile.go
120124
if req.GetSketchPath() == "" {
@@ -185,40 +189,24 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager)
185189
}
186190
}
187191

188-
// Set path to compiled binary
189-
// Make the filename without the FQBN configs part
190-
fqbn.Configs = properties.NewMap()
191-
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1)
192-
193192
var importPath *paths.Path
194-
var importFile string
195-
if req.GetImportFile() == "" {
196-
importPath = sketch.FullPath
197-
importFile = sketch.Name + "." + fqbnSuffix
193+
if importDir := req.GetImportDir(); importDir != "" {
194+
importPath = paths.New(importDir)
198195
} else {
199-
importPath = paths.New(req.GetImportFile()).Parent()
200-
importFile = paths.New(req.GetImportFile()).Base()
196+
// TODO: Create a function to obtain importPath from sketch
197+
importPath = sketch.FullPath
198+
// Add FQBN (without configs part) to export path
199+
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
200+
importPath = importPath.Join("build").Join(fqbnSuffix)
201201
}
202-
203-
outputTmpFile, ok := toolProperties.GetOk("recipe.output.tmp_file")
204-
outputTmpFile = toolProperties.ExpandPropsInString(outputTmpFile)
205-
if !ok {
206-
return nil, fmt.Errorf("property 'recipe.output.tmp_file' not defined")
202+
if !importPath.Exist() {
203+
return nil, fmt.Errorf("compiled sketch not found in %s", importPath)
207204
}
208-
ext := filepath.Ext(outputTmpFile)
209-
if strings.HasSuffix(importFile, ext) {
210-
importFile = importFile[:len(importFile)-len(ext)]
205+
if !importPath.IsDir() {
206+
return nil, fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath)
211207
}
212-
213208
toolProperties.SetPath("build.path", importPath)
214-
toolProperties.Set("build.project_name", importFile)
215-
uploadFile := importPath.Join(importFile + ext)
216-
if _, err := uploadFile.Stat(); err != nil {
217-
if os.IsNotExist(err) {
218-
return nil, fmt.Errorf("compiled sketch %s not found", uploadFile.String())
219-
}
220-
return nil, errors.Wrap(err, "cannot open sketch")
221-
}
209+
toolProperties.Set("build.project_name", sketch.Name+".ino")
222210

223211
// Set debug port property
224212
port := req.GetPort()

0 commit comments

Comments
 (0)