bin/chroot-maint: Enhance the `CROSS_TOOLS' pattern machinery.
[distorted-chroot] / bin / chroot-maint
index ba51ec5..fbd45e3 100755 (executable)
@@ -1431,6 +1431,7 @@ class Config (object):
     "*_DEPS": ("PKGDEPS", _conv_list),
     "*_QEMUHOST": ("QEMUHOST", _conv_str),
     "*_QEMUARCH": ("QEMUARCH", _conv_str),
+    "*_QEMUDIST": ("QEMUDIST", _conv_str),
     "*_ALIASES": ("DISTALIAS", _conv_str)
   }
 
@@ -1858,7 +1859,8 @@ class ChrootJob (BaseJob):
       me._tools_chroot = CrossToolsJob.ensure\
         ("%s-%s" % (me._dist, C.TOOLSARCH), FRESH)
       me._qemu_chroot = CrossToolsJob.ensure\
-        ("%s-%s" % (me._dist, C.QEMUHOST[me._arch]), FRESH)
+        ("%s-%s" % (C.QEMUDIST.get(me._dist, me._dist),
+                    C.QEMUHOST[me._arch]), FRESH)
       me.await(me._tools_chroot)
       me.await(me._qemu_chroot)
 
@@ -1895,9 +1897,10 @@ class ChrootJob (BaseJob):
       crossdir = OS.path.join(C.LOCAL, "cross",
                               "%s-%s" % (dist, C.TOOLSARCH))
 
-      qarch, qhost = C.QEMUARCH[arch], C.QEMUHOST[arch]
+      qarch, qhost, qdist = \
+        C.QEMUARCH[arch], C.QEMUHOST[arch], C.QEMUDIST.get(dist, dist)
       qemudir = OS.path.join(C.LOCAL, "cross",
-                             "%s-%s" % (dist, qhost), "QEMU")
+                             "%s-%s" % (qdist, qhost), "QEMU")
 
       ## Acquire lockfiles in a canonical order to prevent deadlocks.
       donors = [C.TOOLSARCH]
@@ -2381,15 +2384,25 @@ class CrossToolsJob (BaseJob):
 
       ## Work through the shopping list, copying the things it names into the
       ## cross-tools tree.
+      ##
+      ## Each thing in the `CROSS_PATHS' list is a `|'-separated list of glob
+      ## patterns, optionally preceded by `?'.  Unless the list starts with
+      ## `?', at least one of the patterns must match at least one file.
+      ## Patterns may contain the token `MULTI', which is replaced by the
+      ## donor architecture's multiarch triplet.
       scan = []
       for pat in C.CROSS_PATHS:
-        pat = pat.replace("MULTI", mymulti)
         any = False
-        for rootpath in GLOB.iglob(root + pat):
+        pat = pat.replace("MULTI", mymulti)
+        if pat.startswith("?"):
+          pat = pat[1:]
           any = True
-          path = rootpath[len(root):]
-          progress("copy `%s'" % path)
-          run_program(["rsync", "-aHR", "%s/.%s" % (root, path), crossnew])
+        for subpat in pat.split("|"):
+          for rootpath in GLOB.iglob(root + subpat):
+            any = True
+            path = rootpath[len(root):]
+            progress("copy `%s'" % path)
+            run_program(["rsync", "-aHR", "%s/.%s" % (root, path), crossnew])
         if not any:
           raise RuntimeError("no matches for cross-tool pattern `%s'" % pat)