forked from letscontrolit/ESPEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
before_deploy
executable file
·113 lines (89 loc) · 2.72 KB
/
before_deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
VERSION=$(git describe)
TMP_DIST=`mktemp -d`
CURPATH=`pwd`
BUILD_LOG=`echo "${TMP_DIST}/buildlog.txt"`
# PIO 3.x :
# BINARY_PATH=".pioenvs"
# PIO 4.0 and newer:
BINARY_PATH=".pio/build"
while getopts d: option
do
case "${option}"
in
d) VERSION=${OPTARG};;
esac
done
if [ ! -d ${TMP_DIST} ]; then
# Could not create temp dir, so exit
exit 1
fi
#Naming convention:
# ESP_Easy_[github version]_[plugin set]_[chip type]_[flash memory].bin
mkdir -p ${TMP_DIST}
cp -r dist/* ${TMP_DIST}/
if [ -d "docs/build" ]; then
# Docs have been created
mkdir -p ${TMP_DIST}/docs
cp -r docs/build/* ${TMP_DIST}/docs/
fi
mkdir -p ${TMP_DIST}/memstats
# Must look into all possible env definitions.
# Exclude so called "spec_" (special) builds
for ENV in `grep "^\[env:" platformio*.ini |cut -d'[' -f2|cut -d']' -f1|cut -d':' -f2|sort -n|grep -v spec_`;
do
MAX_FILESIZE=1044464
if [[ ${ENV} == *"_1M"* ]]; then
# max 872 kiB - 16 bytes
MAX_FILESIZE=892912
fi
if [[ ${ENV} == *"_1M_OTA"* ]]; then
# max 600 kiB - 16 bytes
MAX_FILESIZE=614384
fi
if [[ ${ENV} == *"4M316k"* ]]; then
# ESP32 with 1800k of sketch space.
MAX_FILESIZE=1900544
fi
if [[ ${ENV} == *"debug_"* ]]; then
# Debug env, used for analysis, not to be run on a node.
MAX_FILESIZE=0
fi
FIRMWARE_BIN=`echo "${BINARY_PATH}/${ENV}/firmware.bin"`
if [ -f $FIRMWARE_BIN ]; then
FILESIZE=$(stat -c%s `echo "${FIRMWARE_BIN}"` )
if (( FILESIZE < MAX_FILESIZE )); then
echo
echo "SUCCESS: $FILESIZE < $MAX_FILESIZE Bytes. (${ENV})" >> ${BUILD_LOG}
BIN=${BINARY_PATH}/${ENV}/ESP_Easy_${VERSION}_${ENV}.bin
cp ${FIRMWARE_BIN} $BIN
python2 crc2.py $BIN
mv $BIN "${TMP_DIST}/bin/ESP_Easy_${VERSION}_${ENV}.bin"
else
echo "FAILED: too large $FILESIZE > $MAX_FILESIZE Bytes. (${ENV})" >> ${BUILD_LOG}
fi
else
echo "FAILED: No file created. (${ENV})" >> ${BUILD_LOG}
fi
ELFFILE=`echo "${BINARY_PATH}/${ENV}/firmware.elf"`
if [ -f $ELFFILE ]; then
SYMBOLS_STATS=`echo "${TMP_DIST}/memstats/symbols_${ENV}.txt"`
STRINGS_STATS=`echo "${TMP_DIST}/memstats/strings_${ENV}.txt"`
readelf -a ${ELFFILE} |grep 3ff |sort -n -k 3 > ${SYMBOLS_STATS}
objdump -s -j .rodata ${ELFFILE} > ${STRINGS_STATS}
fi
done
#create a source structure that is the same as the original ESPEasy project (and works with the howto on the wiki)
#rm -rf dist/Source 2>/dev/null
mkdir -p ${TMP_DIST}/source
cp -r lib ${TMP_DIST}/source/
cp -r src ${TMP_DIST}/source/
cp platformio*.ini ${TMP_DIST}/source/
cd ${TMP_DIST}
echo
echo "### Creating zip archive"
zip -qq ${CURPATH}/ESPEasy_$VERSION.zip -r .
# Display the build log.
cat ${BUILD_LOG}
rm -Rf ${TMP_DIST}/* 2>/dev/null
rmdir ${TMP_DIST}