Skip to content

Commit c12f371

Browse files
platisdladyada
authored andcommitted
Preserve temporary files after compilation (espressif#49)
Preserve the temporary files (e.g. '.hex') so they can be found at a deterministic location and be deployed if there's a need to.
1 parent 62f87be commit c12f371

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,26 @@ External libraries (which are not hosted by the Arduino library manager) can be
125125
```
126126
- if [ ! -d "$HOME/arduino_ide/libraries/<Name>" ]; then git clone <URL> $HOME/arduino_ide/libraries/<Name>; fi
127127
```
128+
129+
## Deploying compiled artifacts
130+
If you need to get hold of the compiled sketches of your project, in order to release them or forward them to an
131+
deployment pipeline, you can find them in the `$ARDUINO_HEX_DIR` directory. Specifically, if `Foo` is the name
132+
of your project, you are compiling for an `Arduino Mega` and the primary sketch is called `Foo.ino`, the flashable
133+
`.hex` files will be found inside `$ARDUINO_HEX_DIR/mega2560/Foo` as `Foo.ino.hex` and `Foo.ino.with_bootloader.hex`.
134+
Similarly for the rest of the platforms.
135+
136+
For example, assuming you have a `Foo` project as outlined above, to create a release which includes the `.hex`
137+
files on GitHub, you could add this to your `.travis.yml` configuration:
138+
139+
```yaml
140+
deploy:
141+
provider: releases
142+
api_key:
143+
secure: YOUR_API_KEY_ENCRYPTED
144+
file:
145+
- $ARDUINO_HEX_DIR/mega2560/Foo/Foo.ino.hex
146+
- $ARDUINO_HEX_DIR/mega2560/Foo/Foo.ino.with_bootloader.hex
147+
skip_cleanup: true
148+
on:
149+
tags: true
150+
```

install.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ echo -n "CACHED: "
7171
echo -e """$GREEN""\xe2\x9c\x93"
7272
fi
7373

74+
# define output directory for .hex files
75+
export ARDUINO_HEX_DIR=$HOME/compiled_arduino_sketches/arduino_build_$TRAVIS_BUILD_NUMBER
76+
7477
# link test library folder to the arduino libraries folder
7578
ln -s $TRAVIS_BUILD_DIR $HOME/arduino_ide/libraries/Adafruit_Test_Library
7679

@@ -345,11 +348,15 @@ function build_platform()
345348

346349
fi
347350

351+
# get the sketch name so we can place the generated files in the respective folder
352+
local sketch_filename_with_ending=$(basename -- "$example")
353+
local sketch_filename="${sketch_filename_with_ending%.*}"
354+
local build_path=$ARDUINO_HEX_DIR/$platform_key/$sketch_filename
348355
# verify the example, and save stdout & stderr to a variable
349356
# we have to avoid reading the exit code of local:
350357
# "when declaring a local variable in a function, the local acts as a command in its own right"
351358
local build_stdout
352-
build_stdout=$(arduino --verify $example 2>&1)
359+
build_stdout=$(arduino --verify --pref build.path=$build_path --preserve-temp-files $example 2>&1)
353360

354361
# echo output if the build failed
355362
if [ $? -ne 0 ]; then

0 commit comments

Comments
 (0)