Skip to content

Commit 74cc976

Browse files
authored
Update nanopb generator script to check for python and help (#10450)
1 parent 3d6305a commit 74cc976

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

scripts/nanopb/generate_protos.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ echoColor() {
3636
printf "${COLOR}$1${NC}\n"
3737
}
3838

39+
echoRed() {
40+
RED='\033[0;31m'
41+
NC='\033[0m'
42+
printf "${RED}$1${NC}\n"
43+
}
44+
45+
cleanup_and_exit() {
46+
rm -rf "${NANOPB_TEMPDIR}"
47+
exit
48+
}
49+
3950
rm -rf "${NANOPB_TEMPDIR}"
4051

4152
echoColor "Downloading nanopb..."
@@ -52,6 +63,18 @@ echoColor "Removing existing protos..."
5263
rm -rf "${PROTOGEN_DIR}/*"
5364

5465
echoColor "Generating protos..."
66+
67+
if ! command -v python &> /dev/null
68+
then
69+
echoRed ""
70+
echoRed "'python' command not found."
71+
echoRed "You may be able to resolve this by installing python with homebrew and linking 'python' to 'python3'. Eg. run:"
72+
echoRed ""
73+
echoRed '$ brew install python && cd $(dirname $(which python3)) && ln -s python3 python'
74+
echoRed ""
75+
cleanup_and_exit
76+
fi
77+
5578
python "${DIR}/scripts/nanopb/proto_generator.py" \
5679
--nanopb \
5780
--protos_dir="${PROTO_DIR}" \
@@ -60,12 +83,12 @@ python "${DIR}/scripts/nanopb/proto_generator.py" \
6083
--include="${PROTO_DIR}" \
6184
--include_prefix="${INCLUDE_PREFIX}"
6285

63-
rm -rf "${NANOPB_TEMPDIR}"
64-
6586
RED='\033[0;31m'
6687
NC='\033[0m'
67-
echo ""
68-
echo ""
69-
echo -e "${RED}Important: Any new proto fields of type string, repeated, or bytes must be specified in the proto's .options file with type:FT_POINTER${NC}"
70-
echo ""
71-
echo ""
88+
echoRed ""
89+
echoRed ""
90+
echoRed -e "Important: Any new proto fields of type string, repeated, or bytes must be specified in the proto's .options file with type:FT_POINTER"
91+
echoRed ""
92+
echoRed ""
93+
94+
cleanup_and_exit

0 commit comments

Comments
 (0)