buildman: Return an error if there are maintainer warnings

Detect warnings about missing maintain info and return result code 2 in
that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/buildman/README b/tools/buildman/README
index 0666bc7..3ba08d0 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -1314,7 +1314,8 @@
 This file is no-longer needed by buildman but it is still generated in the
 working directory. This helps avoid a delay on every build, since scanning all
 the Kconfig files takes a few seconds. Use the -R flag to force regeneration
-of the file - in that case buildman exits after writing the file.
+of the file - in that case buildman exits after writing the file. with exit code
+2 if there was an error in the maintainer files.
 
 You should use 'buildman -nv <criteria>' instead of greoing the boards.cfg file,
 since it may be dropped altogether in future.
diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py
index 8832e40..b30b344 100644
--- a/tools/buildman/boards.py
+++ b/tools/buildman/boards.py
@@ -276,11 +276,13 @@
             value: tuple:
                 str: Board status (e.g. 'Active')
                 str: List of maintainers, separated by :
+        warnings (list of str): List of warnings due to missing status, etc.
     """
 
     def __init__(self):
         """Create an empty database."""
         self.database = {}
+        self.warnings = []
 
     def get_status(self, target):
         """Return the status of the given board.
@@ -296,7 +298,7 @@
             str: 'Active', 'Orphan' or '-'.
         """
         if not target in self.database:
-            print(f"WARNING: no status info for '{target}'", file=sys.stderr)
+            self.warnings.append(f"WARNING: no status info for '{target}'")
             return '-'
 
         tmp = self.database[target][0]
@@ -306,7 +308,7 @@
             return 'Active'
         if tmp.startswith('Orphan'):
             return 'Orphan'
-        print(f"WARNING: {tmp}: unknown status for '{target}'", file=sys.stderr)
+        self.warnings.append(f"WARNING: {tmp}: unknown status for '{target}'")
         return '-'
 
     def get_maintainers(self, target):
@@ -320,7 +322,7 @@
             maintainers, they are separated with colons.
         """
         if not target in self.database:
-            print(f"WARNING: no maintainers for '{target}'", file=sys.stderr)
+            self.warnings.append(f"WARNING: no maintainers for '{target}'")
             return ''
 
         return ':'.join(self.database[target][1])
@@ -677,6 +679,9 @@
 
         Args:
             params_list (list of dict): A list of the board parameters
+
+        Returns:
+            list of str: List of warnings collected due to missing status, etc.
         """
         database = MaintainersDatabase()
         for (dirpath, _, filenames) in os.walk('.'):
@@ -688,6 +693,7 @@
             params['status'] = database.get_status(target)
             params['maintainers'] = database.get_maintainers(target)
             params_list[i] = params
+        return database.warnings
 
     @classmethod
     def format_and_output(cls, params_list, output):
@@ -731,11 +737,17 @@
             jobs (int): The number of jobs to run simultaneously
             force (bool): Force to generate the output even if it is new
             quiet (bool): True to avoid printing a message if nothing needs doing
+
+        Returns:
+            bool: True if all is well, False if there were warnings
         """
         if not force and output_is_new(output):
             if not quiet:
                 print(f'{output} is up to date. Nothing to do.')
-            return
+            return True
         params_list = self.scan_defconfigs(jobs)
-        self.insert_maintainers_info(params_list)
+        warnings = self.insert_maintainers_info(params_list)
+        for warn in warnings:
+            print(warn, file=sys.stderr)
         self.format_and_output(params_list, output)
+        return not warnings
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 79ce2f6..0c75466 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -188,12 +188,12 @@
         board_file = os.path.join(options.output_dir, 'boards.cfg')
 
         brds = boards.Boards()
-        brds.ensure_board_list(board_file,
-                               options.threads or multiprocessing.cpu_count(),
-                               force=options.regen_board_list,
-                               quiet=not options.verbose)
+        ok = brds.ensure_board_list(board_file,
+                                    options.threads or multiprocessing.cpu_count(),
+                                    force=options.regen_board_list,
+                                    quiet=not options.verbose)
         if options.regen_board_list:
-            return 0
+            return 0 if ok else 2
         brds.read_boards(board_file)
 
     exclude = []