[elbe-devel] [PATCH v4 2/6] Add optional mirror for host architecture

Kory Maincent kory.maincent at bootlin.com
Mon Jun 15 15:46:20 CEST 2020


If the primary mirror does not contain the packages for both target and host
architecture the build_host_sysroot process fails.

This patch adds support for describing in the XML configuration an additional
optional mirror containing packages for the host architecture, like:
<mirror>
<host>http://archive.ubuntu.com/ubuntu</host>
</mirror>

It also adds the architecture type in the sources.list file to avoid issues
with apt-get update.

Signed-off-by: Kory Maincent <kory.maincent at bootlin.com>
---
 elbepack/elbexml.py | 54 +++++++++++++++++++++++++++++----------------
 elbepack/rfs.py     | 24 ++++++++++++--------
 schema/dbsfed.xsd   |  7 ++++++
 3 files changed, 57 insertions(+), 28 deletions(-)

diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index fa81583..d6567dd 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -14,6 +14,8 @@ from elbepack.treeutils import etree
 from elbepack.validate import validate_xml
 from elbepack.xmldefaults import ElbeDefaults
 
+from elbepack.shellhelper import get_command_out
+
 from elbepack.version import elbe_version, is_devel
 try:
     from urllib.request import (urlopen, install_opener, build_opener,
@@ -132,13 +134,16 @@ class ElbeXML(object):
 
         return mirror.replace("LOCALMACHINE", "10.0.2.2")
 
-    def get_primary_mirror(self, cdrompath, initvm=True):
+    def get_primary_mirror(self, cdrompath, initvm=True, hostsdk=False):
         if self.prj.has("mirror/primary_host"):
             m = self.prj.node("mirror")
 
-            mirror = m.text("primary_proto") + "://"
-            mirror += m.text("primary_host") + "/"
-            mirror += m.text("primary_path")
+            if hostsdk and self.prj.has("mirror/host"):
+                mirror = m.text("host")
+            else:
+                mirror = m.text("primary_proto") + "://"
+                mirror += m.text("primary_host") + "/"
+                mirror += m.text("primary_path")
 
         elif self.prj.has("mirror/cdrom") and cdrompath:
             mirror = "file://%s" % cdrompath
@@ -146,7 +151,7 @@ class ElbeXML(object):
         return replace_localmachine(mirror, initvm)
 
     # XXX: maybe add cdrom path param ?
-    def create_apt_sources_list(self, build_sources=False, initvm=True):
+    def create_apt_sources_list(self, build_sources=False, initvm=True, hostsdk=False):
         if self.prj is None:
             return "# No Project"
 
@@ -155,31 +160,42 @@ class ElbeXML(object):
 
         noauth = ""
         if self.prj.has("noauth"):
-            noauth = "[trusted=yes] "
+            noauth = "trusted=yes "
+
+        if hostsdk:
+            arch = get_command_out("dpkg --print-architecture").strip().decode()
+        else:
+            arch = self.text("project/buildimage/arch", key="arch")
+
+        mirror = []
+        options = []
+
+        options.append(noauth)
+        options.append("arch=%s" % arch)
 
-        mirror = ""
         if self.prj.has("mirror/primary_host"):
-            mirror += "deb " + noauth + self.get_primary_mirror(None)
-            mirror += " " + self.prj.text("suite") + " main\n"
+            pmirror = self.get_primary_mirror(None, hostsdk=hostsdk)
+            mirror.append("deb [%s] %s %s main" %
+                          (' '.join(options), pmirror, self.prj.text("suite")))
 
             if build_sources:
-                mirror += "deb-src " + noauth + self.get_primary_mirror(None)
-                mirror += " " + self.prj.text("suite") + " main\n"
+                mirror.append("deb-src [%s] %s %s main" %
+                              (' '.join(options), pmirror, self.prj.text("suite")))
 
-            if self.prj.has("mirror/url-list"):
+            if self.prj.has("mirror/url-list") and not hostsdk:
                 for url in self.prj.node("mirror/url-list"):
                     if url.has("binary"):
-                        mirror += "deb " + noauth + \
-                                   url.text("binary").strip() + "\n"
+                        mirror.append("deb [%s] %s" %
+                                      (' '.join(options), url.text("binary").strip()))
                     if url.has("source"):
-                        mirror += "deb-src " + noauth + \
-                            url.text("source").strip() + "\n"
+                        mirror.append("deb-src [%s] %s" %
+                                      (' '.join(options), url.text("source").strip()))
 
         if self.prj.has("mirror/cdrom"):
-            mirror += "deb copy:///cdrom/targetrepo %s main added\n" % (
-                self.prj.text("suite"))
+            mirror.append("deb copy:///cdrom/targetrepo %s main added" %
+                          (self.prj.text("suite")))
 
-        return replace_localmachine(mirror, initvm)
+        return replace_localmachine('\n'.join(mirror), initvm)
 
     def validate_repo(self, r):
         try:
diff --git a/elbepack/rfs.py b/elbepack/rfs.py
index 6967d28..3aba464 100644
--- a/elbepack/rfs.py
+++ b/elbepack/rfs.py
@@ -96,7 +96,11 @@ class BuildEnv (object):
             self.fresh_debootstrap = False
             self.need_dumpdebootstrap = False
 
-        self.initialize_dirs(build_sources=build_sources)
+        host_arch = get_command_out("dpkg --print-architecture").strip().decode()
+
+        hostsdk = arch == host_arch
+
+        self.initialize_dirs(build_sources=build_sources, hostsdk=hostsdk)
         create_apt_prefs(self.xml, self.rfs)
 
     def cdrom_umount(self):
@@ -161,8 +165,15 @@ class BuildEnv (object):
         cleanup = False
         suite = self.xml.prj.text("suite")
 
+        if arch == "default":
+            arch = self.xml.text("project/buildimage/arch", key="arch")
+
+        host_arch = get_command_out("dpkg --print-architecture").strip().decode()
+
+        hostsdk = arch == host_arch
+
         primary_mirror = self.xml.get_primary_mirror(
-            self.rfs.fname('/cdrom/targetrepo'))
+            self.rfs.fname('/cdrom/targetrepo'), hostsdk=hostsdk)
 
         if self.xml.prj.has("mirror/primary_proxy"):
             os.environ["no_proxy"] = "10.0.2.2,localhost,127.0.0.1"
@@ -183,11 +194,6 @@ class BuildEnv (object):
 
         logging.info("Debootstrap log")
 
-        if arch == "default":
-            arch = self.xml.text("project/buildimage/arch", key="arch")
-
-        host_arch = get_command_out("dpkg --print-architecture").strip().decode()
-
         includepkgs = None
         strapcmd  = 'debootstrap '
         if self.xml.has("target/debootstrapvariant"):
@@ -297,8 +303,8 @@ class BuildEnv (object):
                     key = "\n".join(line.strip(" \t") for line in url.text('raw-key').splitlines()[1:-1])
                     self.add_key(key)
 
-    def initialize_dirs(self, build_sources=False):
-        mirror = self.xml.create_apt_sources_list(build_sources=build_sources)
+    def initialize_dirs(self, build_sources=False, hostsdk=False):
+        mirror = self.xml.create_apt_sources_list(build_sources=build_sources, hostsdk=hostsdk)
 
         if self.rfs.lexists("etc/apt/sources.list"):
             self.rfs.remove("etc/apt/sources.list")
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index a78501e..e3709de 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -273,6 +273,13 @@
           </documentation>
         </annotation>
       </element>
+      <element name="host" type="rfs:string" minOccurs="0" maxOccurs="1">
+        <annotation>
+          <documentation>
+            Url of the host mirror.
+          </documentation>
+        </annotation>
+      </element>
       <element name="url-list" type="rfs:url-list" minOccurs="0">
         <annotation>
           <documentation>
-- 
2.17.1




More information about the elbe-devel mailing list