diff options
Diffstat (limited to 'tools/buildgen/plugins/expand_filegroups.py')
-rwxr-xr-x | tools/buildgen/plugins/expand_filegroups.py | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/tools/buildgen/plugins/expand_filegroups.py b/tools/buildgen/plugins/expand_filegroups.py index 156bdc4417..14cb616027 100755 --- a/tools/buildgen/plugins/expand_filegroups.py +++ b/tools/buildgen/plugins/expand_filegroups.py @@ -42,6 +42,9 @@ def excluded(filename, exclude_res): return False +FILEGROUP_LISTS = ['src', 'headers', 'public_headers'] + + def mako_plugin(dictionary): """The exported plugin code for expand_filegroups. @@ -54,21 +57,60 @@ def mako_plugin(dictionary): filegroups_list = dictionary.get('filegroups') filegroups = {} - for fg in filegroups_list: - filegroups[fg['name']] = fg + todo = filegroups_list[:] + skips = 0 + + while todo: + assert skips != len(todo), "infinite loop in filegroup uses clauses" + # take the first element of the todo list + cur = todo[0] + todo = todo[1:] + # check all uses filegroups are present (if no, skip and come back later) + skip = False + for uses in cur.get('uses', []): + if uses not in filegroups: + skip = True + if skip: + skips += 1 + todo.append(cur) + else: + skips = 0 + assert 'plugins' not in cur + plugins = [] + for uses in cur.get('uses', []): + for plugin in filegroups[uses]['plugins']: + if plugin not in plugins: + plugins.append(plugin) + for lst in FILEGROUP_LISTS: + vals = cur.get(lst, []) + vals.extend(filegroups[uses].get(lst, [])) + cur[lst] = vals + cur_plugin_name = cur.get('plugin') + if cur_plugin_name: + plugins.append(cur_plugin_name) + cur['plugins'] = plugins + filegroups[cur['name']] = cur + + # the above expansion can introduce duplicate filenames: contract them here + for fg in filegroups.itervalues(): + for lst in FILEGROUP_LISTS: + fg[lst] = sorted(list(set(fg.get(lst, [])))) for lib in libs: + assert 'plugins' not in lib + plugins = [] for fg_name in lib.get('filegroups', []): fg = filegroups[fg_name] - - src = lib.get('src', []) - src.extend(fg.get('src', [])) - lib['src'] = src - - headers = lib.get('headers', []) - headers.extend(fg.get('headers', [])) - lib['headers'] = headers - - public_headers = lib.get('public_headers', []) - public_headers.extend(fg.get('public_headers', [])) - lib['public_headers'] = public_headers + for plugin in fg['plugins']: + if plugin not in plugins: + plugins.append(plugin) + for lst in FILEGROUP_LISTS: + vals = lib.get(lst, []) + vals.extend(fg.get(lst, [])) + lib[lst] = vals + lib['plugins'] = plugins + if lib.get('generate_plugin_registry', False): + lib['src'].append('src/core/plugin_registry/%s_plugin_registry.c' % + lib['name']) + for lst in FILEGROUP_LISTS: + lib[lst] = sorted(list(set(lib.get(lst, [])))) |