[PATCH 1/4] binman: Move GetEntryModules() to control

Simon Glass sjg at chromium.org
Wed Aug 5 21:27:46 CEST 2020


When binman is installed its main program is in a different directory
to its modules. This means that __file__ is different and we cannot use
it to obtain the path to etype/ from main.py

To fix this, move the function to the 'control' module, since it is
installed with all the other modules, including the etype/ directory.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/control.py | 13 +++++++++++++
 tools/binman/ftest.py   |  5 ++---
 tools/binman/main.py    | 16 ++--------------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/tools/binman/control.py b/tools/binman/control.py
index 343b0a0c35b..69c36ed6582 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -6,6 +6,7 @@
 #
 
 from collections import OrderedDict
+import glob
 import os
 import sys
 from patman import tools
@@ -51,6 +52,18 @@ def _FindBinmanNode(dtb):
             return node
     return None
 
+def GetEntryModules(include_testing=True):
+    """Get a set of entry class implementations
+
+    Returns:
+        Set of paths to entry class filenames
+    """
+    our_path = os.path.dirname(os.path.realpath(__file__))
+    glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
+    return set([os.path.splitext(os.path.basename(item))[0]
+                for item in glob_list
+                if include_testing or '_testing' not in item])
+
 def WriteEntryDocs(modules, test_missing=None):
     """Write out documentation for all entries
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index bf7f59fb841..fedcc1ada1b 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -24,7 +24,6 @@ from binman import control
 from binman import elf
 from binman import elf_test
 from binman import fmap_util
-from binman import main
 from binman import state
 from dtoc import fdt
 from dtoc import fdt_util
@@ -1440,14 +1439,14 @@ class TestFunctional(unittest.TestCase):
     def testEntryDocs(self):
         """Test for creation of entry documentation"""
         with test_util.capture_sys_output() as (stdout, stderr):
-            control.WriteEntryDocs(main.GetEntryModules())
+            control.WriteEntryDocs(control.GetEntryModules())
         self.assertTrue(len(stdout.getvalue()) > 0)
 
     def testEntryDocsMissing(self):
         """Test handling of missing entry documentation"""
         with self.assertRaises(ValueError) as e:
             with test_util.capture_sys_output() as (stdout, stderr):
-                control.WriteEntryDocs(main.GetEntryModules(), 'u_boot')
+                control.WriteEntryDocs(control.GetEntryModules(), 'u_boot')
         self.assertIn('Documentation is missing for modules: u_boot',
                       str(e.exception))
 
diff --git a/tools/binman/main.py b/tools/binman/main.py
index e543a7d06a7..3e463b0119b 100755
--- a/tools/binman/main.py
+++ b/tools/binman/main.py
@@ -10,7 +10,6 @@
 """See README for more information"""
 
 from distutils.sysconfig import get_python_lib
-import glob
 import os
 import site
 import sys
@@ -78,20 +77,9 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
 
     return test_util.ReportResult('binman', test_name, result)
 
-def GetEntryModules(include_testing=True):
-    """Get a set of entry class implementations
-
-    Returns:
-        Set of paths to entry class filenames
-    """
-    glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
-    return set([os.path.splitext(os.path.basename(item))[0]
-                for item in glob_list
-                if include_testing or '_testing' not in item])
-
 def RunTestCoverage(toolpath):
     """Run the tests and check that we get 100% coverage"""
-    glob_list = GetEntryModules(False)
+    glob_list = control.GetEntryModules(False)
     all_set = set([os.path.splitext(os.path.basename(item))[0]
                    for item in glob_list if '_testing' not in item])
     extra_args = ''
@@ -127,7 +115,7 @@ def RunBinman(args):
                                 args.toolpath)
 
     elif args.cmd == 'entry-docs':
-        control.WriteEntryDocs(GetEntryModules())
+        control.WriteEntryDocs(control.GetEntryModules())
 
     else:
         try:
-- 
2.28.0.163.g6104cc2f0b6-goog



More information about the U-Boot mailing list