Browse Source

Make update_lists.py more flexible (#2290)

Add options to specify additional domain exclusion prefixes on
the command line, and downgrade unused patterns/prefixes from
errors to info messages. These are useful when working with
alternative Chromium source trees, such as Debian's.
Daniel Richard G 1 year ago
parent
commit
a8f4e3bafb
1 changed files with 16 additions and 3 deletions
  1. 16 3
      devutils/update_lists.py

+ 16 - 3
devutils/update_lists.py

@@ -133,17 +133,18 @@ class UnusedPatterns: #pylint: disable=too-few-public-methods
         for name in self._all_names:
             setattr(self, name, set(globals()[name.upper()]))
 
-    def log_unused(self):
+    def log_unused(self, error=True):
         """
         Logs unused patterns and prefixes
 
         Returns True if there are unused patterns or prefixes; False otherwise
         """
         have_unused = False
+        log = get_logger().error if error else get_logger().info
         for name in self._all_names:
             current_set = getattr(self, name, None)
             if current_set:
-                get_logger().error('Unused from %s: %s', name.upper(), current_set)
+                log('Unused from %s: %s', name.upper(), current_set)
                 have_unused = True
         return have_unused
 
@@ -354,7 +355,19 @@ def main(args_list=None):
         default=None,
         help=
         'The maximum number of worker processes to create. Defaults to the number of system CPUs.')
+    parser.add_argument(
+        '--domain-exclude-prefix',
+        metavar='PREFIX',
+        type=str,
+        action='append',
+        help='Additional exclusion for domain_substitution.list.')
+    parser.add_argument(
+        '--no-error-unused',
+        action='store_false',
+        dest='error_unused',
+        help='Do not treat unused patterns/prefixes as an error.')
     args = parser.parse_args(args_list)
+    DOMAIN_EXCLUDE_PREFIXES.extend(args.domain_exclude_prefix)
     if args.tree.exists() and not _dir_empty(args.tree):
         get_logger().info('Using existing source tree at %s', args.tree)
     else:
@@ -368,7 +381,7 @@ def main(args_list=None):
         file_obj.writelines('%s\n' % line for line in pruning_set)
     with args.domain_substitution.open('w', encoding=_ENCODING) as file_obj:
         file_obj.writelines('%s\n' % line for line in domain_substitution_set)
-    if unused_patterns.log_unused():
+    if unused_patterns.log_unused(args.error_unused) and args.error_unused:
         get_logger().error('Please update or remove unused patterns and/or prefixes. '
                            'The lists have still been updated with the remaining valid entries.')
         exit(1)