Commit 58967c7d authored by Bobby Noelte's avatar Bobby Noelte Committed by Kumar Gala
Browse files

scripts: extract_dts_includes.py: fix multiple include in bindings



Correctly process multiple include files given to the
!include command of the YAML loader.

The fix only targets the sequential definition of include files.

Fixes #7067

Signed-off-by: default avatarBobby Noelte <b0661n0e17e@gmail.com>
parent b028a515
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6,6 +6,11 @@ description: >
    Describe in free form text w/ spanning lines what you
    are describing

inherits:
  - !include other.yaml # or [other1.yaml, other2.yaml]
# other.yaml contains bindings that also apply to this node.
# In case there are duplicate definitions in the different
# bindings the one that is defined first prevails.

< parent | child >:
# parent/child is used to document implicit relation between nodes.
+31 −9
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class Loader(yaml.Loader):
        elif isinstance(node, yaml.SequenceNode):
            result = []
            for filename in self.construct_sequence(node):
                result += self.extractFile(filename)
                result.append(self.extractFile(filename))
            return result

        elif isinstance(node, yaml.MappingNode):
@@ -572,6 +572,9 @@ def dict_merge(dct, merge_dct):
                and isinstance(merge_dct[k], collections.Mapping)):
            dict_merge(dct[k], merge_dct[k])
        else:
            if k in dct and dct[k] != merge_dct[k]:
                print("extract_dts_includes.py: Merge of '{}': '{}'  overwrites '{}'.".format(
                        k, merge_dct[k], dct[k]))
            dct[k] = merge_dct[k]


@@ -584,15 +587,34 @@ def yaml_traverse_inherited(node):
    :return: node
    """

    if 'inherits' in node.keys():
        if 'id' in node['inherits'].keys():
            node['inherits']['node_type'] = node['inherits']['id']
            node['inherits'].pop('id')
        if 'inherits' in node['inherits'].keys():
            node['inherits'] = yaml_traverse_inherited(node['inherits'])
        dict_merge(node['inherits'], node)
        node = node['inherits']
    if 'node_type' not in node:
        node['node_type'] = []
    if 'inherits' in node:
        if isinstance(node['inherits'], list):
            inherits_list  = node['inherits']
        else:
            inherits_list  = [node['inherits'],]
        node.pop('inherits')
        for inherits in inherits_list:
            if 'id' in inherits:
                node['node_type'].append(inherits['id'])
                inherits.pop('id')
            # title, description, version of inherited node are overwritten
            # by intention. Remove to prevent dct_merge to complain about
            # duplicates.
            if 'title' in inherits and 'title' in node:
                inherits.pop('title')
            if 'version' in inherits and 'version' in node:
                inherits.pop('version')
            if 'description' in inherits and 'description' in node:
                inherits.pop('description')

            if 'inherits' in inherits:
                inherits = yaml_traverse_inherited(inherits)
                if 'node_type' in inherits:
                    node['node_type'].extend(inherits['node_type'])
            dict_merge(inherits, node)
            node = inherits
    return node