Skip to content

Commit e51df0d

Browse files
authored
Fixed upload issue on esp32 (partitions artifacts copy) (#457)
* Copy multiple build artifacts matching a name pattern. Previously the compile command copied only the following artifacts: sketch.ino.hex (or .bin) sketch.ino.elf now also the files matching the glob sketch.ino.*.hex will be copied. This allows for some 3rd party core (like esp32) to copy also the extra file sketch.ino.partitions.bin. Should fix #163 * Added test for improved support for esp32:esp32 #163 * Run of "go mod tidy"
1 parent ca3a6d9 commit e51df0d

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

Diff for: cli/cli_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,39 @@ board_manager:
396396
require.NotZero(t, exitCode)
397397
}
398398

399+
func Test3rdPartyCoreIntegration(t *testing.T) {
400+
// override SetUp dirs
401+
tmp := tmpDirOrDie()
402+
defer os.RemoveAll(tmp)
403+
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
404+
currSketchbookDir = tmp
405+
406+
configFile := filepath.Join(currDataDir, "arduino-cli.yaml")
407+
err := ioutil.WriteFile(configFile, []byte(`
408+
board_manager:
409+
additional_urls:
410+
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
411+
`), os.FileMode(0644))
412+
require.NoError(t, err, "writing dummy config "+configFile)
413+
414+
// Update index and install esp32:esp32
415+
exitCode, _ := executeWithArgs("--config-file", configFile, "core", "update-index")
416+
require.Zero(t, exitCode)
417+
exitCode, d := executeWithArgs("--config-file", configFile, "core", "install", "esp32:esp32")
418+
require.Zero(t, exitCode)
419+
require.Contains(t, string(d), "installed")
420+
421+
// Build a simple sketch and check if all artifacts are copied
422+
tmpSketch := paths.New(currSketchbookDir).Join("Blink")
423+
err = paths.New("testdata/Blink").CopyDirTo(tmpSketch)
424+
require.NoError(t, err, "copying test sketch into temp dir")
425+
exitCode, d = executeWithArgs("--config-file", configFile, "compile", "-b", "esp32:esp32:esp32", tmpSketch.String())
426+
require.Zero(t, exitCode)
427+
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.bin").Exist())
428+
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.elf").Exist())
429+
require.True(t, tmpSketch.Join("Blink.esp32.esp32.esp32.partitions.bin").Exist()) // https://github.com/arduino/arduino-cli/issues/163
430+
}
431+
399432
func TestCoreCommandsIntegration(t *testing.T) {
400433
// override SetUp dirs
401434
tmp := tmpDirOrDie()

Diff for: cli/testdata/Blink/Blink.ino

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
void setup() {}
3+
void loop() {}

Diff for: commands/compile/compile.go

+22-10
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
174174
}
175175

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

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

202-
// Copy .hex file to sketch directory
203-
srcHex := paths.New(outputPath)
204-
dstHex := exportPath.Join(exportFile + ext)
205-
logrus.WithField("from", srcHex).WithField("to", dstHex).Debug("copying sketch build output")
206-
if err = srcHex.CopyTo(dstHex); err != nil {
207-
return nil, fmt.Errorf("copying output file: %s", err)
205+
// Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
206+
srcDir, err := outputPath.Parent().ReadDir() // read "/build/path/*"
207+
if err != nil {
208+
return nil, fmt.Errorf("reading build directory: %s", err)
209+
}
210+
srcDir.FilterPrefix(base + ".")
211+
srcDir.FilterSuffix(ext)
212+
for _, srcOutput := range srcDir {
213+
srcFilename := srcOutput.Base() // "sketch.ino.*.bin"
214+
srcFilename = srcFilename[len(base):] // ".*.bin"
215+
dstOutput := exportPath.Join(exportFile + srcFilename)
216+
logrus.WithField("from", srcOutput).WithField("to", dstOutput).Debug("copying sketch build output")
217+
if err = srcOutput.CopyTo(dstOutput); err != nil {
218+
return nil, fmt.Errorf("copying output file: %s", err)
219+
}
208220
}
209221

210222
// Copy .elf file to sketch directory
211-
srcElf := paths.New(outputPath[:len(outputPath)-3] + "elf")
223+
srcElf := outputPath.Parent().Join(base + ".elf")
212224
if srcElf.Exist() {
213225
dstElf := exportPath.Join(exportFile + ".elf")
214226
logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output")

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ require (
4343
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45
4444
golang.org/x/net v0.0.0-20190311183353-d8887717615a
4545
golang.org/x/text v0.3.0
46-
google.golang.org/appengine v1.4.0 // indirect
4746
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
4847
google.golang.org/grpc v1.21.1
4948
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect

Diff for: go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
44
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
55
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s=
66
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
7-
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1 h1:S0NpDSqjlkNA510vmRCP5Cq9mPgu3rWDSdeN4SI1Mwc=
8-
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1/go.mod h1:OGL+FS3aTrS01YsBAJJhkGuxtEGsFRSgZYo8b3vefdc=
97
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
108
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
119
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA=

Diff for: test/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pluggy==0.12.0
1414
py==1.8.0
1515
pylint==2.3.1
1616
pyparsing==2.4.0
17+
pyserial==3.4
1718
pytest==5.1.3
1819
semver==2.8.1
1920
simplejson==3.16.0

0 commit comments

Comments
 (0)