8000 Add smart artifact find during upload by rsora · Pull Request #655 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Add smart artifact find during upload #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add build-path fallback POC in upload
  • Loading branch information
rsora committed Apr 14, 2020
commit d954694760aff59a2aacd0c359a1c4340c4bca5b
41 changes: 38 additions & 3 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"time"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/sketches"
"github.com/arduino/arduino-cli/cli/feedback"
Expand Down Expand Up @@ -156,6 +157,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr

var importPath *paths.Path
var importFile string
// If no importFile is passed, use sketch path
if req.GetImportFile() == "" {
importPath = sketch.FullPath
importFile = sketch.Name + "." + fqbnSuffix
Expand All @@ -169,19 +171,52 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
if !ok {
return nil, fmt.Errorf("property 'recipe.output.tmp_file' not defined")
}

ext := filepath.Ext(outputTmpFile)
if strings.HasSuffix(importFile, ext) {
importFile = importFile[:len(importFile)-len(ext)]
}

// Check if the file ext we calculate is the same that is needed by the upload recipe
recipet := uploadProperties.Get("upload.pattern")
cmdLinet := uploadProperties.ExpandPropsInString(recipet)
cmdArgst, err := properties.SplitQuotedString(cmdLinet, `"'`, false)
var tPath *paths.Path
if err != nil {
return nil, fmt.Errorf("invalid recipe '%s': %s", recipet, err)
}
for _, t := range cmdArgst {
if strings.Contains(t, "build.project_name") {
tPath = paths.New(t)
}
}

if ext != tPath.Ext() {
ext = tPath.Ext()
}
//uploadRecipeInputFileExt :=
uploadProperties.SetPath("build.path", importPath)
uploadProperties.Set("build.project_name", importFile)
uploadFile := importPath.Join(importFile + ext)
if _, err := uploadFile.Stat(); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("compiled sketch %s not found", uploadFile.String())
if !os.IsNotExist(err) {
return nil, fmt.Errorf("cannot open sketch: %s", err)
}
return nil, fmt.Errorf("cannot open sketch: %s", err)
// Built sketch not found in the provided path, let's fallback to the temp compile path
fallbackBuildPath := builder.GenBuildPath(sketchPath)
logrus.Warnf("Built sketch not found in %s, let's fallback to %s", uploadFile, fallbackBuildPath)
uploadProperties.SetPath("build.path", fallbackBuildPath)
// If we search inside the build.path, compile artifact do not have the fqbnSuffix in the filename
uploadFile = fallbackBuildPath.Join(sketch.Name + ".ino" + ext)
if _, err := uploadFile.Stat(); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("compiled sketch %s not found", uploadFile.String())
}
return nil, fmt.Errorf("cannot open sketch: %s", err)
}
// Clean from extension
uploadProperties.Set("build.project_name", sketch.Name+".ino")

}

// Perform reset via 1200bps touch if requested
Expand Down
0