[elbe-devel] [PATCH v6 1/5] Add optional mirror for host architecture

Torben Hohn torben.hohn at linutronix.de
Wed Jul 22 08:59:43 CEST 2020


From: Kory Maincent <kory.maincent at bootlin.com>

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>
[torbenh: use xml and default mechanism to determine host sdk architecture
          rename hostsdk variable to hostsysroot
          make hostsyroot an attribute of BuildEnv]
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/elbeproject.py |  3 ++-
 elbepack/elbexml.py     | 51 +++++++++++++++++++++++++----------------
 elbepack/rfs.py         |  8 ++++---
 elbepack/xmldefaults.py |  3 ++-
 schema/dbsfed.xsd       |  7 ++++++
 5 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 122399cd2..cd5020dc7 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -324,7 +324,8 @@ class ElbeProject (object):
         self.host_sysrootenv = BuildEnv(self.xml,
                                         hostsysrootpath,
                                         clean=True,
-                                        arch="amd64")
+                                        arch="amd64",
+                                        hostsysroot=True)
         # Import keyring
         self.host_sysrootenv.import_keys()
         logging.info("Keys imported")
diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index 6496e442a..bcfd2054a 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -134,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, hostsysroot=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 hostsysroot 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
@@ -148,40 +151,48 @@ 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, hostsysroot=False):
         if self.prj is None:
             return "# No Project"
 
         if not self.prj.has("mirror") and not self.prj.has("mirror/cdrom"):
             return "# no mirrors configured"
 
-        noauth = ""
+        options = []
         if self.prj.has("noauth"):
-            noauth = "[trusted=yes] "
+            options.append("trusted=yes")
 
-        mirror = ""
+        if hostsysroot:
+            arch = self.text("project/buildimage/sdkarch", key="sdkarch")
+        else:
+            arch = self.text("project/buildimage/arch", key="arch")
+
+        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, hostsysroot=hostsysroot)
+            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 hostsysroot:
                 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)
 
     @staticmethod
     def validate_repo(r):
diff --git a/elbepack/rfs.py b/elbepack/rfs.py
index ffb62641d..76a6485f8 100644
--- a/elbepack/rfs.py
+++ b/elbepack/rfs.py
@@ -66,7 +66,7 @@ class DebootstrapException (Exception):
 # TODO:py3 Remove object inheritance
 # pylint: disable=useless-object-inheritance
 class BuildEnv (object):
-    def __init__(self, xml, path, build_sources=False, clean=False, arch="default"):
+    def __init__(self, xml, path, build_sources=False, clean=False, arch="default", hostsysroot=False):
 
         # pylint: disable=too-many-arguments
 
@@ -74,6 +74,7 @@ class BuildEnv (object):
         self.path = path
         self.rpcaptcache = None
         self.arch = arch
+        self.hostsysroot = hostsysroot
 
         self.rfs = BuildImgFs(path, xml.defs["userinterpr"])
 
@@ -163,7 +164,7 @@ class BuildEnv (object):
         suite = self.xml.prj.text("suite")
 
         primary_mirror = self.xml.get_primary_mirror(
-            self.rfs.fname('/cdrom/targetrepo'))
+            self.rfs.fname('/cdrom/targetrepo'), hostsysroot=self.hostsysroot)
 
         if self.xml.prj.has("mirror/primary_proxy"):
             os.environ["no_proxy"] = "10.0.2.2,localhost,127.0.0.1"
@@ -299,7 +300,8 @@ class BuildEnv (object):
                     self.add_key(key)
 
     def initialize_dirs(self, build_sources=False):
-        mirror = self.xml.create_apt_sources_list(build_sources=build_sources)
+        mirror = self.xml.create_apt_sources_list(build_sources=build_sources,
+                                                  hostsysroot=self.hostsysroot)
 
         if self.rfs.lexists("etc/apt/sources.list"):
             self.rfs.remove("etc/apt/sources.list")
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index ad6f15fe2..7c3c4689b 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -174,7 +174,8 @@ archindep_defaults = {
     "img": "qcow2",
     "mem": "1GiB",
     "swap-size": "0",
-    "max-cpus": "8"
+    "max-cpus": "8",
+    "sdkarch": "amd64",
 }
 
 defaults = {"armel": armel_defaults,
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index 388529b2d..f068c9ba8 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.20.1



More information about the elbe-devel mailing list