31
31
include_guard (GLOBAL )
32
32
33
33
include (extensions )
34
+ include (python )
34
35
35
36
# Check that SHIELD has not changed.
36
37
zephyr_check_cache (SHIELD WATCH )
@@ -46,31 +47,42 @@ endif()
46
47
# After processing all shields, only invalid shields will be left in this list.
47
48
set (SHIELD-NOTFOUND ${SHIELD_AS_LIST} )
48
49
49
- foreach (root ${BOARD_ROOT} )
50
- set (shield_dir ${root} /boards/shields )
51
- # Match the Kconfig.shield files in the shield directories to make sure we are
52
- # finding shields, e.g. x_nucleo_iks01a1/Kconfig.shield
53
- file (GLOB_RECURSE shields_refs_list ${shield_dir} /*/Kconfig.shield )
54
-
55
- # The above gives a list of Kconfig.shield files, like this:
56
- #
57
- # x_nucleo_iks01a1/Kconfig.shield;x_nucleo_iks01a2/Kconfig.shield
58
- #
59
- # we construct a list of shield names by extracting the directories
60
- # from each file and looking for <shield>.overlay files in there.
61
- # Each overlay corresponds to a shield. We obtain the shield name by
62
- # removing the .overlay extension.
63
- # We also create a SHIELD_DIR_${name} variable for each shield's directory.
64
- foreach (shields_refs ${shields_refs_list} )
65
- get_filename_component (shield_path ${shields_refs} DIRECTORY )
66
- file (GLOB shield_overlays RELATIVE ${shield_path} ${shield_path} /*.overlay )
67
- foreach (overlay ${shield_overlays} )
68
- get_filename_component (shield ${overlay} NAME_WE )
69
- list (APPEND SHIELD_LIST ${shield} )
70
- set (SHIELD_DIR_${shield} ${shield_path} )
71
- endforeach ()
50
+ # Prepare list shields command.
51
+ # This command is used for locating the shield dir as well as printing all shields
52
+ # in the system in the following cases:
53
+ # - User specifies an invalid SHIELD
54
+ # - User invokes '<build-command> shields' target
55
+ list (TRANSFORM BOARD_ROOT PREPEND "--board-root=" OUTPUT_VARIABLE board_root_args )
56
+
57
+ set (list_shields_commands
58
+ COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/list_shields.py
59
+ ${board_root_args} --json
60
+ )
61
+
62
+ # Get list of shields in JSON format
63
+ execute_process (${list_shields_commands}
64
+ OUTPUT_VARIABLE shields_json
65
+ ERROR_VARIABLE err_shields
66
+ RESULT_VARIABLE ret_val
67
+ )
68
+
69
+ if (ret_val )
70
+ message (FATAL_ERROR "Error finding shields\n Error message: ${err_shields} " )
71
+ endif ()
72
+
73
+ string (JSON shields_length LENGTH ${shields_json} )
74
+
75
+ if (shields_length GREATER 0 )
76
+ math (EXPR shields_length "${shields_length} - 1" )
77
+
78
+ foreach (i RANGE ${shields_length} )
79
+ string (JSON shield GET "${shields_json} " "${i} " )
80
+ string (JSON shield_name GET ${shield} name )
81
+ string (JSON shield_dir GET ${shield} dir )
82
+ list (APPEND SHIELD_LIST ${shield_name} )
83
+ set (SHIELD_DIR_${shield_name} ${shield_dir} )
72
84
endforeach ()
73
- endforeach ()
85
+ endif ()
74
86
75
87
# Process shields in-order
76
88
if (DEFINED SHIELD )
0 commit comments