[U-Boot] [PATCH 08/11] buildman: Avoid overwriting existing toolchain entries

Simon Glass sjg at chromium.org
Sun Jul 3 23:14:24 CEST 2016


The current code for setting up the toolchain config always writes the new
paths to an item called 'toolchain'. This means that it will overwrite any
existing toolchain item with the same name. In practice, this means that:

   buildman --fetch-arch all

will fetch all toolchains, but only the path of the final one will be added
to the config. This normally works out OK, since most toolchains are the
same version (e.g. gcc 4.9) and will be found on the same path. But it is
not correct and toolchains for archs which don't use the same version will
not function as expected.

Adjust the code to use unique names for each toolchain path entry.

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

 tools/buildman/bsettings.py | 21 +++++++++++++++++++++
 tools/buildman/toolchain.py | 29 +++++++++++++++++++++++++----
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/tools/buildman/bsettings.py b/tools/buildman/bsettings.py
index 6f8fdfd..655fef8 100644
--- a/tools/buildman/bsettings.py
+++ b/tools/buildman/bsettings.py
@@ -47,6 +47,27 @@ def GetItems(section):
     except:
         raise
 
+def GetItemsAsDict(section):
+    """Get the items from a section of the config.
+
+    Args:
+        section: name of section to retrieve
+
+    Returns:
+        Dict:
+           key: name of item
+           value: value of item
+    """
+    try:
+        items = {}
+        for item in settings.items(section):
+            items[item[0]] = item[1]
+        return items
+    except ConfigParser.NoSectionError as e:
+        return {}
+    except:
+        raise
+
 def SetItem(section, tag, value):
     """Set an item and write it back to the settings file"""
     global settings
diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index 584c9f2..293b297 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -550,9 +550,30 @@ class Toolchains:
         toolchain = Toolchain(compiler_fname_list[0], True, True)
 
         # Make sure that it will be found by buildman
-        if not self.TestSettingsHasPath(dirpath):
-            print ("Adding 'download' to config file '%s'" %
-                   bsettings.config_fname)
+        if self.TestSettingsHasPath(dirpath):
+            print col.Color(col.GREEN, 'Reusing existing config item')
+        else:
             tools_dir = os.path.dirname(dirpath)
-            bsettings.SetItem('toolchain', 'download', '%s/*' % tools_dir)
+            self.AddToolchainSetting('%s/*' % tools_dir)
         return 0
+
+    def AddToolchainSetting(self, tools_path):
+        """Add a new toolchain setting to the [toolchain] section.
+
+        Be careful to avoid overwriting an existing entry.
+
+        Args:
+            tools_path: New tools patch to add (normally ends with "/*")
+        """
+        col = terminal.Color()
+        items = bsettings.GetItemsAsDict('toolchain')
+        for upto in xrange(100):
+            name = 'download%d' % upto
+            if name not in items:
+                break
+        if upto == 100:
+            print 'Internal error: too many items in [toolchain]'
+            return 1
+        print col.Color(col.YELLOW, "Adding '%s' to config file '%s'" %
+                        (name, bsettings.config_fname))
+        bsettings.SetItem('toolchain', name, tools_path)
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list