From bfc17ce35a162e11cefd9ad02bdccaf81883007f Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 9 Sep 2022 16:52:47 +0200 Subject: [PATCH] tools: default to text output format in 'idf.py size' --- tools/cmake/run_size_tool.cmake | 14 ++++++++++---- tools/idf_py_actions/core_ext.py | 14 +++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tools/cmake/run_size_tool.cmake b/tools/cmake/run_size_tool.cmake index f38b1e19a3..648f8bcc0b 100644 --- a/tools/cmake/run_size_tool.cmake +++ b/tools/cmake/run_size_tool.cmake @@ -1,4 +1,4 @@ -# A CMake script to run size tool commands supporting OUTPUT_FORMAT and +# A CMake script to run size tool commands supporting SIZE_OUTPUT_FORMAT and # OUTPUT_JSON environment variables from within ninja or make or another # cmake-based build runner. # @@ -12,10 +12,16 @@ cmake_minimum_required(VERSION 3.16) set(IDF_SIZE_CMD ${IDF_SIZE_TOOL}) -if(DEFINED ENV{SIZE_OUTPUT_FORMAT}) +if(NOT DEFINED ENV{SIZE_OUTPUT_FORMAT} OR "$ENV{SIZE_OUTPUT_FORMAT}" STREQUAL "default") + # Format not passed to "idf.py size" explicitly, or this target was invoked + # from make/ninja directly (without idf.py) + if(DEFINED OUTPUT_JSON AND OUTPUT_JSON) + # honor the legacy OUTPUT_JSON variable, if set + list(APPEND IDF_SIZE_CMD "--format=json") + endif() +elseif(DEFINED ENV{SIZE_OUTPUT_FORMAT}) + # specific format was requested list(APPEND IDF_SIZE_CMD "--format=$ENV{SIZE_OUTPUT_FORMAT}") -elseif(DEFINED OUTPUT_JSON AND OUTPUT_JSON) - list(APPEND IDF_SIZE_CMD "--format=json") endif() if(DEFINED IDF_SIZE_MODE) diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index 2b0e734ec9..f6abf137b7 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -44,8 +44,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Any: for hint in generate_hints(stdout, stderr): yellow_print(hint) - if output_format: - os.environ['SIZE_OUTPUT_FORMAT'] = output_format + os.environ['SIZE_OUTPUT_FORMAT'] = output_format ensure_build_directory(args, ctx.info_name) run_target('all', args, force_progression=GENERATORS[args.generator].get('force_progression', False), custom_error_handler=tool_error_handler) @@ -338,12 +337,13 @@ def action_extensions(base_actions: Dict, project_path: str) -> Any: 'global_action_callbacks': [validate_root_options], } - # Default value is intentionally blank, so that we know if the user explicitly specified - # the format and override the OUTPUT_JSON variable if it is set + # 'default' is introduced instead of simply setting 'text' as the default so that we know + # if the user explicitly specified the format or not. If the format is not specified, then + # the legacy OUTPUT_JSON CMake variable will be taken into account. size_options = [{'names': ['--format', 'output_format'], - 'type': click.Choice(['text', 'csv', 'json']), - 'help': 'Specify output format: text, csv or json.', - 'default': ''}] + 'type': click.Choice(['default', 'text', 'csv', 'json']), + 'help': 'Specify output format: text (same as "default"), csv or json.', + 'default': 'default'}] build_actions = { 'actions': {