From b8909439bf6e11a7bebf779d046c5158b9c5040a Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Fri, 2 Aug 2019 11:42:06 -0700 Subject: [PATCH] scripts: dts: support multiple binding dirs in new scripts gen_defines.py and edtlib.py were recently added in commit 62d57414762d ("dts: Add new DTS/binding parser"). The old extract_dts_includes.py script allowed for multiple dts bindings dirs. Let's add that functionality to the new scripts as well. Signed-off-by: Michael Scott --- scripts/dts/edtlib.py | 41 +++++++++++++++++++++----------------- scripts/dts/gen_defines.py | 9 +++++---- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/scripts/dts/edtlib.py b/scripts/dts/edtlib.py index 485a8865fb9..20262e375ab 100644 --- a/scripts/dts/edtlib.py +++ b/scripts/dts/edtlib.py @@ -90,26 +90,26 @@ class EDT: dts_path: The .dts path passed to __init__() - bindings_dir: - The bindings directory path passed to __init__() + bindings_dirs: + The bindings directory paths passed to __init__() """ - def __init__(self, dts, bindings_dir): + def __init__(self, dts, bindings_dirs): """ EDT constructor. This is the top-level entry point to the library. dts: Path to device tree .dts file - bindings_dir: - Path to directory containing bindings, in YAML format. This directory - is recursively searched for .yaml files. + bindings_dirs: + List of paths to directories containing bindings, in YAML format. + These directories are recursively searched for .yaml files. """ self.dts_path = dts - self.bindings_dir = bindings_dir + self.bindings_dirs = bindings_dirs self._dt = DT(dts) - self._init_compat2binding(bindings_dir) + self._init_compat2binding(bindings_dirs) self._init_devices() def get_dev(self, path): @@ -143,7 +143,7 @@ class EDT: _err("{} in /chosen points to {}, which does not exist" .format(name, path)) - def _init_compat2binding(self, bindings_dir): + def _init_compat2binding(self, bindings_dirs): # Creates self._compat2binding. This is a dictionary that maps # (, ) tuples (both strings) to (, ) # tuples. is the binding in parsed PyYAML format, and @@ -160,7 +160,7 @@ class EDT: # are loaded. dt_compats = _dt_compats(self._dt) - self._binding_paths = _binding_paths(bindings_dir) + self._binding_paths = _binding_paths(bindings_dirs) # Add '!include foo.yaml' handling. # @@ -238,8 +238,8 @@ class EDT: dev._init_clocks() def __repr__(self): - return "".format( - self.dts_path, self.bindings_dir) + return "".format( + self.dts_path, self.bindings_dirs) class Device: @@ -1009,14 +1009,19 @@ def _dt_compats(dt): for compat in node.props["compatible"].to_strings()} -def _binding_paths(bindings_dir): +def _binding_paths(bindings_dirs): # Returns a list with the paths to all bindings (.yaml files) in - # 'bindings_dir' + # 'bindings_dirs' - return [os.path.join(root, filename) - for root, _, filenames in os.walk(bindings_dir) - for filename in filenames - if filename.endswith(".yaml")] + binding_paths = [] + + for bindings_dir in bindings_dirs: + for root, _, filenames in os.walk(bindings_dir): + for filename in filenames: + if filename.endswith(".yaml"): + binding_paths.append(os.path.join(root, filename)) + + return binding_paths def _binding_compat(binding_path): diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index c82b7f64bf8..1284b8338b7 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -31,7 +31,7 @@ def main(): args = parse_args() try: - edt = edtlib.EDT(args.dts, args.bindings_dir) + edt = edtlib.EDT(args.dts, args.bindings_dirs) except edtlib.EDTError as e: sys.exit("device tree error: " + str(e)) @@ -40,7 +40,7 @@ def main(): out_comment("Generated by gen_defines.py", blank_before=False) out_comment("DTS input file: " + args.dts, blank_before=False) - out_comment("Directory with bindings: " + args.bindings_dir, + out_comment("Directories with bindings: " + ", ".join(args.bindings_dirs), blank_before=False) active_compats = set() @@ -114,8 +114,9 @@ def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--dts", required=True, help="DTS file") - parser.add_argument("--bindings-dir", required=True, - help="directory with bindings in YAML format") + parser.add_argument("--bindings-dirs", nargs='+', required=True, + help="directory with bindings in YAML format, " + "we allow multiple") parser.add_argument("--header-out", required=True, help="path to write header to") parser.add_argument("--conf-out", required=True,