diff --git a/components/app_update/CMakeLists.txt b/components/app_update/CMakeLists.txt index a8492e351a..74c0d88fed 100644 --- a/components/app_update/CMakeLists.txt +++ b/components/app_update/CMakeLists.txt @@ -49,7 +49,8 @@ if(NOT BOOTLOADER_BUILD) set(otatool_py ${python} ${COMPONENT_DIR}/otatool.py) set(esptool_args "--esptool-args;before=${CONFIG_ESPTOOLPY_BEFORE};after=${CONFIG_ESPTOOLPY_AFTER}") - set(otatool_args "--partition-table-file;${PARTITION_CSV_PATH};--partition-table-offset;${PARTITION_TABLE_OFFSET}") + set(otatool_args "--partition-table-file;${PARTITION_CSV_PATH}" + "--partition-table-offset;${PARTITION_TABLE_OFFSET}") idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR) add_custom_target(read_otadata DEPENDS "${PARTITION_CSV_PATH}" diff --git a/components/esptool_py/get_port_args.cmake b/components/esptool_py/get_port_args.cmake index e70f131046..90f5258611 100644 --- a/components/esptool_py/get_port_args.cmake +++ b/components/esptool_py/get_port_args.cmake @@ -3,7 +3,8 @@ # without needing a CMake re-run) set(ESPPORT $ENV{ESPPORT}) if(NOT ESPPORT) - message("Note: ${SERIAL_TOOL} will search for a serial port. To specify a port, set the ESPPORT environment variable.") + message("Note: ${SERIAL_TOOL} will search for a serial port. " + "To specify a port, set the ESPPORT environment variable.") else() set(port_arg "-p ${ESPPORT}") endif() diff --git a/components/esptool_py/run_cmd.cmake b/components/esptool_py/run_cmd.cmake deleted file mode 100644 index a5620a3420..0000000000 --- a/components/esptool_py/run_cmd.cmake +++ /dev/null @@ -1,15 +0,0 @@ -if(NOT IDF_PATH) - message(FATAL_ERROR "IDF_PATH not set.") -endif() -include("${IDF_PATH}/tools/cmake/utilities.cmake") -spaces2list(CMD) - -execute_process(COMMAND ${CMD} - WORKING_DIRECTORY "${WORKING_DIRECTORY}" - RESULT_VARIABLE result - ) - -if(${result}) - # No way to have CMake silently fail, unfortunately - message(FATAL_ERROR "${SERIAL_TOOL} failed") -endif() diff --git a/components/esptool_py/run_serial_tool.cmake b/components/esptool_py/run_serial_tool.cmake index 04d3f5afdf..ce8bf93d98 100644 --- a/components/esptool_py/run_serial_tool.cmake +++ b/components/esptool_py/run_serial_tool.cmake @@ -1,19 +1,51 @@ -# A CMake script to run esptool commands from within ninja or make -# or another cmake-based build runner -# -# (Needed to expand environment variables, for backwards compatibility.) +# A CMake script to run serial tool commands supporting ESPPORT and +# ESPBAUD environment variables from within ninja or make or another +# cmake-based build runner. # # It is recommended to NOT USE this CMake script if you have the option of -# running esptool.py directly. This script exists only for use inside CMake builds. -# +# running the tool directly. This script exists only for use inside CMake builds. cmake_minimum_required(VERSION 3.5) +if(NOT IDF_PATH) + message(FATAL_ERROR "IDF_PATH not set.") +endif() + if(NOT SERIAL_TOOL OR NOT SERIAL_TOOL_ARGS) message(FATAL_ERROR "SERIAL_TOOL and SERIAL_TOOL_ARGS must " "be specified on the CMake command line. For direct execution, it is " "strongly recommended to run ${SERIAL_TOOL} directly.") endif() -include("${CMAKE_CURRENT_LIST_DIR}/get_port_args.cmake") -set(CMD "${SERIAL_TOOL} ${port_arg} ${baud_arg} ${SERIAL_TOOL_ARGS}") -include("${CMAKE_CURRENT_LIST_DIR}/run_cmd.cmake") +# Main purpose of this script: we can't expand these environment variables in the main IDF CMake build, +# because we want to expand them at flashing time not at CMake runtime (so they can change +# without needing a CMake re-run) +set(ESPPORT $ENV{ESPPORT}) +if(NOT ESPPORT) + message("Note: ${SERIAL_TOOL} will search for a serial port. " + "To specify a port, set the ESPPORT environment variable.") +else() + set(port_arg "-p ${ESPPORT}") +endif() + +set(ESPBAUD $ENV{ESPBAUD}) +if(NOT ESPBAUD) + message("Note: ${SERIAL_TOOL} will attempt to set baud rate automatically. " + "To specify a baud rate, set the ESPBAUD environment variable.") +else() + set(baud_arg "-b ${ESPBAUD}") +endif() + +set(serial_tool_cmd "${SERIAL_TOOL} ${port_arg} ${baud_arg} ${SERIAL_TOOL_ARGS}") + +include("${IDF_PATH}/tools/cmake/utilities.cmake") +spaces2list(serial_tool_cmd) + +execute_process(COMMAND ${serial_tool_cmd} + WORKING_DIRECTORY "${WORKING_DIRECTORY}" + RESULT_VARIABLE result + ) + +if(${result}) + # No way to have CMake silently fail, unfortunately + message(FATAL_ERROR "${SERIAL_TOOL} failed") +endif()