From f64a3c2a66f08c0f907de51c5676ff977957c407 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Mon, 2 Mar 2020 07:15:34 +0500 Subject: [PATCH 1/3] cmake: utility to create a failing target --- tools/cmake/scripts/fail.cmake | 2 +- tools/cmake/utilities.cmake | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/cmake/scripts/fail.cmake b/tools/cmake/scripts/fail.cmake index 5ceddb3ca..b33aec4c3 100644 --- a/tools/cmake/scripts/fail.cmake +++ b/tools/cmake/scripts/fail.cmake @@ -1,4 +1,4 @@ # 'cmake -E' doesn't have a way to fail outright, so run this script # with 'cmake -P' to fail a build. -message(FATAL_ERROR "Failing the build (see errors on lines above)") +message(FATAL_ERROR "$ENV{FAIL_MESSAGE}") diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index fa0abc030..f873137cd 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -214,13 +214,37 @@ function(fail_at_build_time target_name message_line0) set(filename "${CMAKE_CURRENT_BINARY_DIR}/${filename}.cmake") file(WRITE "${filename}" "") include("${filename}") + set(fail_message "Failing the build (see errors on lines above)") add_custom_target(${target_name} ALL ${message_lines} COMMAND ${CMAKE_COMMAND} -E remove "${filename}" - COMMAND ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake + COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message} + ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake VERBATIM) endfunction() +# fail_target +# +# Creates a phony target which fails when invoked. This is used when the necessary conditions +# for a target are not met, such as configuration. Rather than ommitting the target altogether, +# we fail execution with a helpful message. +function(fail_target target_name message_line0) + idf_build_get_property(idf_path IDF_PATH) + set(message_lines COMMAND ${CMAKE_COMMAND} -E echo "${message_line0}") + foreach(message_line ${ARGN}) + set(message_lines ${message_lines} COMMAND ${CMAKE_COMMAND} -E echo "${message_line}") + endforeach() + # Generate a timestamp file that gets included. When deleted on build, this forces CMake + # to rerun. + set(fail_message "Failed executing target (see errors on lines above)") + add_custom_target(${target_name} + ${message_lines} + COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message} + ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake + VERBATIM) +endfunction() + + function(check_exclusive_args args prefix) set(_args ${args}) spaces2list(_args) From eb865008d5a2dda62dcf5a1dae523fa1399099f2 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 14 Feb 2020 11:13:47 +0500 Subject: [PATCH 2/3] cmake: show error message on encrypted flash targets without proper config --- components/esptool_py/project_include.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index 4b6994b12..e2f4abe1e 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -226,7 +226,12 @@ $,\n>") CONTENT "${flash_args_content}") file(GENERATE OUTPUT "${build_dir}/encrypted_${target_name}_args" INPUT "${CMAKE_CURRENT_BINARY_DIR}/encrypted_${target_name}_args.in") + else() + fail_target(encrypted-${target_name} "Error: The target encrypted-${target_name} requires" + "CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT to be enabled.") + endif() + endfunction() From a5d49d4db5e168e406a8fd34fde68b29d0767a8d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 14 Feb 2020 12:24:11 +0500 Subject: [PATCH 3/3] tools: fix double builds with idf.py --- tools/idf_py_actions/serial_ext.py | 19 +++++++------------ tools/test_idf_py/test_idf_py.py | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/idf_py_actions/serial_ext.py b/tools/idf_py_actions/serial_ext.py index a73e05f95..cea311206 100644 --- a/tools/idf_py_actions/serial_ext.py +++ b/tools/idf_py_actions/serial_ext.py @@ -111,6 +111,7 @@ def action_extensions(base_actions, project_path): run_tool("idf_monitor", monitor_args, args.project_dir) def flash(action, ctx, args): + ensure_build_directory(args, ctx.info_name) """ Run esptool to flash the entire project, from an argfile generated by the build system """ @@ -147,8 +148,7 @@ def action_extensions(base_actions, project_path): "callback": flash, "help": "Flash the project.", "options": global_options + [baud_rate, port], - "dependencies": ["all"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["all", "erase_flash"], }, "erase_flash": { "callback": erase_flash, @@ -197,34 +197,29 @@ def action_extensions(base_actions, project_path): "callback": flash, "help": "Flash partition table only.", "options": [baud_rate, port], - "dependencies": ["partition_table"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["partition_table", "erase_flash"], }, "bootloader-flash": { "callback": flash, "help": "Flash bootloader only.", "options": [baud_rate, port], - "dependencies": ["bootloader"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["bootloader", "erase_flash"], }, "app-flash": { "callback": flash, "help": "Flash the app only.", "options": [baud_rate, port], - "dependencies": ["app"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["app", "erase_flash"], }, "encrypted-app-flash": { "callback": flash, "help": "Flash the encrypted app only.", - "dependencies": ["app"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["app", "erase_flash"], }, "encrypted-flash": { "callback": flash, "help": "Flash the encrypted project.", - "dependencies": ["all"], - "order_dependencies": ["erase_flash"], + "order_dependencies": ["all", "erase_flash"], }, }, } diff --git a/tools/test_idf_py/test_idf_py.py b/tools/test_idf_py/test_idf_py.py index 5b9216a99..c027b54f8 100755 --- a/tools/test_idf_py/test_idf_py.py +++ b/tools/test_idf_py/test_idf_py.py @@ -84,7 +84,7 @@ class TestDependencyManagement(unittest.TestCase): args=['--dry-run', 'flash'], standalone_mode=False, ) - self.assertEqual(['all', 'flash'], list(result.keys())) + self.assertEqual(['flash'], list(result.keys())) def test_order_only_dependencies(self): result = idf.init_cli()( @@ -105,7 +105,7 @@ class TestDependencyManagement(unittest.TestCase): args=['--dry-run', 'clean', 'monitor', 'clean', 'fullclean', 'flash'], standalone_mode=False, ) - self.assertEqual(['fullclean', 'clean', 'all', 'flash', 'monitor'], list(result.keys())) + self.assertEqual(['fullclean', 'clean', 'flash', 'monitor'], list(result.keys())) def test_dupplicated_commands_warning(self): capturedOutput = StringIO()