message: Patch the downloaded flatbuffer code to make compatible with TFLM.
  See for more details.
diff: @@ -37,7 +37,37 @@ if [ ! -d ${DOWNLOADS_DIR} ]; then
  exit 1
  fi
  +# TODO(b/173239141): Patch flatbuffers to avoid pulling in extra symbols from
  +# strtod that are not used at runtime but are still problematic on the
  +# Bluepill platform.
  +#
  +# Parameter(s):
  +# $1 - full path to the downloaded flexbuffers.h that will be patched in-place.
  +function patch_to_avoid_strtod() {
  + local input_flexbuffers_path="$1"
  + local temp_flexbuffers_path="/tmp/flexbuffers_patched.h"
  + local string_to_num_line=`awk '/StringToNumber/{ print NR; }' ${input_flexbuffers_path}`
  + local case_string_line=$((${string_to_num_line} - 2))
  +
  + head -n ${case_string_line} ${input_flexbuffers_path} > ${temp_flexbuffers_path}
  +
  + echo "#if 1" >> ${temp_flexbuffers_path}
  + echo " // TODO(b/173239141): Patched via micro/tools/make/flexbuffers_download.sh" >> ${temp_flexbuffers_path}
  + echo " // Introduce a segfault for an unsupported code path for TFLM." >> ${temp_flexbuffers_path}
  + echo " return *(static_cast<double*>(nullptr));" >> ${temp_flexbuffers_path}
  + echo "#else" >> ${temp_flexbuffers_path}
  + echo " // This is the original code" >> ${temp_flexbuffers_path}
  + sed -n -e $((${string_to_num_line} - 1)),$((${string_to_num_line} + 1))p ${input_flexbuffers_path} >> ${temp_flexbuffers_path}
  + echo "#endif" >> ${temp_flexbuffers_path}
  +
  + local total_num_lines=`wc -l ${input_flexbuffers_path} | awk '{print $1}'`
  + sed -n -e $((${string_to_num_line} + 2)),${total_num_lines}p ${input_flexbuffers_path} >> ${temp_flexbuffers_path}
  + mv ${input_flexbuffers_path} ${input_flexbuffers_path}.orig
  + mv ${temp_flexbuffers_path} ${input_flexbuffers_path}
  +}
  +
  DOWNLOADED_FLATBUFFERS_PATH=${DOWNLOADS_DIR}/flatbuffers
  +
  if [ -d ${DOWNLOADED_FLATBUFFERS_PATH} ]; then
  echo >&2 "${DOWNLOADED_FLATBUFFERS_PATH} already exists, skipping the download."
  else
  @@ -56,6 +86,8 @@ else
  unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
  mv /tmp/flatbuffers-${ZIP_PREFIX} ${DOWNLOADED_FLATBUFFERS_PATH}
  +
  + patch_to_avoid_strtod ${DOWNLOADED_FLATBUFFERS_PATH}/include/flatbuffers/flexbuffers.h
  fi
  echo "SUCCESS"
  