tools: default to text output format in 'idf.py size'

This commit is contained in:
Ivan Grokhotkov 2022-09-09 16:52:47 +02:00
parent f644d71d26
commit bfc17ce35a
No known key found for this signature in database
GPG Key ID: 1E050E141B280628
2 changed files with 17 additions and 11 deletions

View File

@ -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 # OUTPUT_JSON environment variables from within ninja or make or another
# cmake-based build runner. # cmake-based build runner.
# #
@ -12,10 +12,16 @@ cmake_minimum_required(VERSION 3.16)
set(IDF_SIZE_CMD ${IDF_SIZE_TOOL}) 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}") 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() endif()
if(DEFINED IDF_SIZE_MODE) if(DEFINED IDF_SIZE_MODE)

View File

@ -44,8 +44,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Any:
for hint in generate_hints(stdout, stderr): for hint in generate_hints(stdout, stderr):
yellow_print(hint) 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) ensure_build_directory(args, ctx.info_name)
run_target('all', args, force_progression=GENERATORS[args.generator].get('force_progression', False), run_target('all', args, force_progression=GENERATORS[args.generator].get('force_progression', False),
custom_error_handler=tool_error_handler) 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], 'global_action_callbacks': [validate_root_options],
} }
# Default value is intentionally blank, so that we know if the user explicitly specified # 'default' is introduced instead of simply setting 'text' as the default so that we know
# the format and override the OUTPUT_JSON variable if it is set # 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'], size_options = [{'names': ['--format', 'output_format'],
'type': click.Choice(['text', 'csv', 'json']), 'type': click.Choice(['default', 'text', 'csv', 'json']),
'help': 'Specify output format: text, csv or json.', 'help': 'Specify output format: text (same as "default"), csv or json.',
'default': ''}] 'default': 'default'}]
build_actions = { build_actions = {
'actions': { 'actions': {