diff --git a/dtschema/dtb_validate.py b/dtschema/dtb_validate.py index 6a02946..e22d5dd 100755 --- a/dtschema/dtb_validate.py +++ b/dtschema/dtb_validate.py @@ -103,7 +103,8 @@ def main(): help="Filename or directory of devicetree DTB input file(s)") ap.add_argument('-s', '--schema', help="preparsed schema file or path to schema files") ap.add_argument('-p', '--preparse', help="preparsed schema file (deprecated, use '-s')") - ap.add_argument('-l', '--limit', help="limit validation to schemas with $id matching LIMIT substring") + ap.add_argument('-l', '--limit', help="limit validation to schemas with $id matching LIMIT substring. " \ + "Multiple substrings separated by ':' can be listed (e.g. foo:bar:baz).") ap.add_argument('-c', '--compatible-match', action="store_true", help="limit validation to schema matching nodes' most specific compatible string") ap.add_argument('-m', '--show-unmatched', @@ -118,14 +119,17 @@ def main(): verbose = args.verbose show_unmatched = args.show_unmatched - match_schema_file = args.limit + if args.limit: + match_schema_file = args.limit.split(':') compatible_match = args.compatible_match # Maintain prior behaviour which accepted file paths by stripping the file path if args.url_path and args.limit: - for d in args.url_path.split(os.path.sep): - if d and match_schema_file.startswith(d): - match_schema_file = match_schema_file[(len(d) + 1):] + for i,match in enumerate(match_schema_file): + for d in args.url_path.split(os.path.sep): + if d and match.startswith(d): + match = match[(len(d) + 1):] + match_schema_file[i] = match if args.preparse: sg = schema_group(args.preparse) diff --git a/dtschema/validator.py b/dtschema/validator.py index 8223407..4d94d9e 100644 --- a/dtschema/validator.py +++ b/dtschema/validator.py @@ -416,12 +416,20 @@ def annotate_error(self, id, error): error.linecol = -1, -1 error.note = None + def _filter_match(self, schema_id, filter): + if not filter: + return True + for f in filter: + if f in schema_id: + return True + return False + def iter_errors(self, instance, filter=None, compatible_match=False): if 'compatible' in instance: for inst_compat in instance['compatible']: if inst_compat in self.compat_map: schema_id = self.compat_map[inst_compat] - if not filter or filter in schema_id: + if self._filter_match(schema_id, filter): schema = self.schemas[schema_id] for error in self.DtValidator(schema, resolver=self.resolver, @@ -434,7 +442,7 @@ def iter_errors(self, instance, filter=None, compatible_match=False): return for schema_id in self.always_schemas: - if filter and filter not in schema_id: + if not self._filter_match(schema_id, filter): continue schema = {'if': self.schemas[schema_id]['select'], 'then': self.schemas[schema_id]}