Skip to content

Fixed upload issue on esp32 (partitions artifacts copy) #457

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

Merged
merged 3 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,39 @@ board_manager:
require.NotZero(t, exitCode)
}

func Test3rdPartyCoreIntegration(t *testing.T) {
// override SetUp dirs
tmp := tmpDirOrDie()
defer os.RemoveAll(tmp)
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
currSketchbookDir = tmp

configFile := filepath.Join(currDataDir, "arduino-cli.yaml")
err := ioutil.WriteFile(configFile, []byte(`
board_manager:
additional_urls:
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
`), os.FileMode(0644))
require.NoError(t, err, "writing dummy config "+configFile)

// Update index and install esp32:esp32
exitCode, _ := executeWithArgs("--config-file", configFile, "core", "update-index")
require.Zero(t, exitCode)
exitCode, d := executeWithArgs("--config-file", configFile, "core", "install", "esp32:esp32")
require.Zero(t, exitCode)
require.Contains(t, string(d), "installed")

// Build a simple sketch and check if all artifacts are copied
tmpSketch := paths.New(currSketchbookDir).Join("Blink")
err = paths.New("testdata/Blink").CopyDirTo(tmpSketch)
require.NoError(t, err, "copying test sketch into temp dir")
exitCode, d = executeWithArgs("--config-file", configFile, "compile", "-b", "esp32:esp32:esp32", tmpSketch.String())
require.Zero(t, exitCode)
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.bin").Exist())
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.elf").Exist())
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.partitions.bin").Exist()) // https://github.com/arduino/arduino-cli/issues/163
}

func TestCoreCommandsIntegration(t *testing.T) {
// override SetUp dirs
tmp := tmpDirOrDie()
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/Blink/Blink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void setup() {}
void loop() {}
32 changes: 22 additions & 10 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
}

// FIXME: Make a function to obtain these info...
outputPath := builderCtx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")
ext := filepath.Ext(outputPath)
outputPath := paths.New(
builderCtx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")) // "/build/path/sketch.ino.bin"
ext := outputPath.Ext() // ".hex" | ".bin"
base := outputPath.Base() // "sketch.ino.hex"
base = base[:len(base)-len(ext)] // "sketch.ino"

// FIXME: Make a function to produce a better name...
// Make the filename without the FQBN configs part
Expand All @@ -190,7 +193,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
} else {
exportPath = sketch.FullPath.Parent()
}
exportFile = sketch.Name + "." + fqbnSuffix
exportFile = sketch.Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
} else {
exportPath = paths.New(req.GetExportFile()).Parent()
exportFile = paths.New(req.GetExportFile()).Base()
Expand All @@ -199,16 +202,25 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
}
}

// Copy .hex file to sketch directory
srcHex := paths.New(outputPath)
dstHex := exportPath.Join(exportFile + ext)
logrus.WithField("from", srcHex).WithField("to", dstHex).Debug("copying sketch build output")
if err = srcHex.CopyTo(dstHex); err != nil {
return nil, fmt.Errorf("copying output file: %s", err)
// Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
srcDir, err := outputPath.Parent().ReadDir() // read "/build/path/*"
if err != nil {
return nil, fmt.Errorf("reading build directory: %s", err)
}
srcDir.FilterPrefix(base + ".")
srcDir.FilterSuffix(ext)
for _, srcOutput := range srcDir {
srcFilename := srcOutput.Base() // "sketch.ino.*.bin"
srcFilename = srcFilename[len(base):] // ".*.bin"
dstOutput := exportPath.Join(exportFile + srcFilename)
logrus.WithField("from", srcOutput).WithField("to", dstOutput).Debug("copying sketch build output")
if err = srcOutput.CopyTo(dstOutput); err != nil {
return nil, fmt.Errorf("copying output file: %s", err)
}
}

// Copy .elf file to sketch directory
srcElf := paths.New(outputPath[:len(outputPath)-3] + "elf")
srcElf := outputPath.Parent().Join(base + ".elf")
if srcElf.Exist() {
dstElf := exportPath.Join(exportFile + ".elf")
logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output")
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
golang.org/x/net v0.0.0-20190311183353-d8887717615a
golang.org/x/text v0.3.0
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
google.golang.org/grpc v1.21.1
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1 h1:S0NpDSqjlkNA510vmRCP5Cq9mPgu3rWDSdeN4SI1Mwc=
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1/go.mod h1:OGL+FS3aTrS01YsBAJJhkGuxtEGsFRSgZYo8b3vefdc=
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA=
Expand Down
1 change: 1 addition & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pluggy==0.12.0
py==1.8.0
pylint==2.3.1
pyparsing==2.4.0
pyserial==3.4
pytest==5.1.3
semver==2.8.1
simplejson==3.16.0
Expand Down