xtensa-build-zephyr.py: avoid showing wrong layout of installed files

If each platform has its own output subdirectory, each platform output
subdirectory will include a key subdirectory with same name. Function
show_installed_files() can fail to find the correct parent for a node
as it only compares the subdir name that can no longer be unique.

This patch uses Anynode to replace Node class to define a new
attribute 'long_name' for a node to store its unique relative path
from the output staging directory (e.g. 'sof/apl/community') and
search for its parent.

The attribute 'name' is still used to store the subdir or file name
for a node (e.g. 'community'), and to display the layout of the
installed firmware files.

Signed-off-by: mengdonglin <mengdong.lin@intel.com>
This commit is contained in:
mengdonglin 2022-06-04 06:16:20 -04:00 committed by Liam Girdwood
parent be007d14ab
commit 0d5bac87d3
1 changed files with 5 additions and 5 deletions

View File

@ -16,7 +16,7 @@ import multiprocessing
import os import os
import warnings import warnings
# anytree module is defined in Zephyr build requirements # anytree module is defined in Zephyr build requirements
from anytree import Node, RenderTree from anytree import AnyNode, RenderTree
# Constant value resolves SOF_TOP directory as: "this script directory/.." # Constant value resolves SOF_TOP directory as: "this script directory/.."
SOF_TOP = pathlib.Path(__file__).parents[1].resolve() SOF_TOP = pathlib.Path(__file__).parents[1].resolve()
@ -243,18 +243,18 @@ def execute_command(*run_args, **run_kwargs):
def show_installed_files(): def show_installed_files():
"""[summary] Scans output directory building binary tree from files and folders """[summary] Scans output directory building binary tree from files and folders
then presents them in similar way to linux tree command.""" then presents them in similar way to linux tree command."""
graph_root = Node(STAGING_DIR.name, parent=None) graph_root = AnyNode(name=STAGING_DIR.name, long_name=STAGING_DIR.name, parent=None)
relative_entries = [entry.relative_to(STAGING_DIR) for entry in STAGING_DIR.glob("**/*")] relative_entries = [entry.relative_to(STAGING_DIR) for entry in STAGING_DIR.glob("**/*")]
nodes = [ graph_root ] nodes = [ graph_root ]
for entry in relative_entries: for entry in relative_entries:
if str(entry.parent) == ".": if str(entry.parent) == ".":
nodes.append(Node(entry.name, parent=graph_root)) nodes.append(AnyNode(name=entry.name, long_name=str(entry), parent=graph_root))
else: else:
node_parent = [node for node in nodes if node.name == str(entry.parent.name)][0] node_parent = [node for node in nodes if node.long_name == str(entry.parent)][0]
if not node_parent: if not node_parent:
warnings.warn("Failed to construct installed files tree") warnings.warn("Failed to construct installed files tree")
return return
nodes.append(Node(entry.name, parent=node_parent)) nodes.append(AnyNode(name=entry.name, long_name=str(entry), parent=node_parent))
for pre, fill, node in RenderTree(graph_root): for pre, fill, node in RenderTree(graph_root):
print(f"{pre}{node.name}") print(f"{pre}{node.name}")