ソースを参照

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

Ivan Grokhotkov 3 年 前
コミット
bfc17ce35a
2 ファイル変更17 行追加11 行削除
  1. 10 4
      tools/cmake/run_size_tool.cmake
  2. 7 7
      tools/idf_py_actions/core_ext.py

+ 10 - 4
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)

+ 7 - 7
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': {