]> git.ipfire.org Git - pakfire.git/commitdiff
system: Move architecture-dependent things into an own module
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 Dec 2016 17:36:44 +0000 (18:36 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 Dec 2016 17:43:14 +0000 (18:43 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/pakfire/arch.py [new file with mode: 0644]
src/pakfire/distro.py
src/pakfire/system.py

index e4391b24b2b6bfcf92a5461567bcb183a5e1d38b..df0713fd2151aba9eca45257552e850cff08a565 100644 (file)
@@ -94,6 +94,7 @@ pakfire_PYTHON = \
        src/pakfire/__init__.py \
        src/pakfire/__version__.py \
        src/pakfire/actions.py \
+       src/pakfire/arch.py \
        src/pakfire/base.py \
        src/pakfire/builder.py \
        src/pakfire/cgroup.py \
diff --git a/src/pakfire/arch.py b/src/pakfire/arch.py
new file mode 100644 (file)
index 0000000..62a027a
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/python3
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2016 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import logging
+
+log = logging.getLogger("pakfire.arch")
+log.propagate = 1
+
+class Arch(object):
+       def __init__(self, arch):
+               self.arch = arch
+
+       def __eq__(self, other):
+               return self.arch == other.arch
+
+       @property
+       def platform(self):
+               """
+                       Returns the "class" this architecture belongs to.
+               """
+               if self.arch.startswith("arm") or self.arch == "aarch64":
+                       return "arm"
+
+               if self.arch in ("i686", "x86_64"):
+                       return "x86"
+
+               return "unknown"
+
+       def get_machine(self, vendor=None):
+               if vendor is None:
+                       vendor = "unknown"
+
+               # Make vendor lowercase
+               vendor = vendor.lower()
+               assert vendor
+
+               s = "%s-%s-linux-gnu" % (self.arch, vendor)
+
+               if self.arch.startswith("arm"):
+                       s += "eabi"
+
+               return s
+
+       def get_buildtarget(self, vendor=None):
+               machine = self.get_machine(vendor)
+
+               # Cut off last segment of machine.
+               return machine.replace("-gnu", "")
+
+       @property
+       def compatbile_arches(self):
+               """
+                       Returns a list of all architectures that are
+                       compatible (i.e. can be emulated)
+               """
+               x = {
+                       # Host arch : Can build these arches.
+                       # x86
+                       "x86_64"    : ["x86_64", "i686",],
+                       "i686"      : ["i686",],
+
+                       # ARM
+                       "armv5tel"  : ["armv5tel",],
+                       "armv5tejl" : ["armv5tel",],
+                       "armv6l"    : ["armv5tel",],
+                       "armv7l"    : ["armv7hl", "armv5tel",],
+                       "armv7hl"   : ["armv7hl", "armv5tel",],
+
+                       "aarch64"   : ["aarch64",],
+               }
+
+               try:
+                       return x[self.arch]
+               except KeyError:
+                       return []
+
+       def is_compatible_with(self, arch):
+               """
+                       Returns True if the given architecture is compatible
+                       with this architecture.
+               """
+               return arch in self.compatible_arches
+
+       @property
+       def personality(self):
+               """
+                       Return the personality of the target system.
+
+                       If host and target system are of the same architecture, we return
+                       None to skip the setting of the personality in the build chroot.
+               """
+               arch2personality = {
+                       "x86_64" : "linux64",
+                       "i686"   : "linux32",
+                       "i586"   : "linux32",
+                       "i486"   : "linux32",
+               }
+
+               try:
+                       personality = arch2personality[self.arch]
+               except KeyError:
+                       personality = None
+
+               return personality
index bceba0cb511cd8f697216c3bf873c1f14fc1735a..ddfcde33b09265a78291e16bf1e875001da24bfb 100644 (file)
 #                                                                             #
 ###############################################################################
 
+import logging
 import os
 import re
 
-import logging
-log = logging.getLogger("pakfire")
-
-from . import system
+log = logging.getLogger("pakfire.distro")
+log.propagate = 1
 
 class Distribution(object):
        def __init__(self,  data=None):
@@ -76,9 +75,7 @@ class Distribution(object):
        def dump(self):
                log.debug("Distribution configuration:")
 
-               attrs = ("name", "release", "sname", "dist", "vendor", "contact",
-                       "arch", "machine", "buildtarget", "source_dl",)
-
+               attrs = ("name", "release", "sname", "dist", "vendor", "contact", "source_dl")
                for attr in attrs:
                        log.debug(" %s : %s" % (attr, getattr(self, attr)))
 
@@ -142,57 +139,10 @@ class Distribution(object):
        def contact(self):
                return self._data.get("contact", "N/A")
 
-       def get_arch(self):
-               arch = self._data.get("arch", None) or system.system.arch
-
-               # We can not set up a build environment for noarch.
-               if arch == "noarch":
-                       arch = system.system.arch
-
-               return arch
-       
-       def set_arch(self, arch):
-               # XXX check if we are allowed to set this arch
-               if not arch:
-                       return
-
-               self._data["arch"] = arch
-
-       arch = property(get_arch, set_arch)
-
-       @property
-       def platform(self):
-               """
-                       Returns the "class" this architecture belongs to.
-               """
-               if self.arch.startswith("arm") or self.arch == "aarch64":
-                       return "arm"
-
-               if self.arch in ("i686", "x86_64"):
-                       return "x86"
-
-               return "unknown"
-
        @property
        def dist(self):
                return self.sname[:2] + self.release
 
-       @property
-       def machine(self):
-               vendor = self.vendor.split()[0]
-
-               s = "%s-%s-linux-gnu" % (self.arch, vendor.lower())
-
-               if self.arch.startswith("arm"):
-                       s += "eabi"
-
-               return s
-
-       @property
-       def buildtarget(self):
-               # Cut off last segment of machine.
-               return self.machine.replace("-gnu", "")
-
        @property
        def source_dl(self):
                return self._data.get("source_dl", None)
@@ -208,10 +158,6 @@ class Distribution(object):
                        "DISTRO_SNAME"        : self.sname,
                        "DISTRO_RELEASE"      : self.release,
                        "DISTRO_DISTTAG"      : self.dist,
-                       "DISTRO_ARCH"         : self.arch,
-                       "DISTRO_MACHINE"      : self.machine,
-                       "DISTRO_PLATFORM"     : self.platform,
-                       "DISTRO_BUILDTARGET"  : self.buildtarget,
                        "DISTRO_VENDOR"       : self.vendor,
                        "DISTRO_CONTACT"      : self.contact,
                        "DISTRO_SLOGAN"       : self.slogan,
@@ -227,29 +173,3 @@ class Distribution(object):
                        info[k.lower()] = v
 
                return info
-
-       @property
-       def personality(self):
-               """
-                       Return the personality of the target system.
-
-                       If host and target system are of the same architecture, we return
-                       None to skip the setting of the personality in the build chroot.
-               """
-
-               if self.arch == system.system.native_arch:
-                       return None
-
-               arch2personality = {
-                       "x86_64" : "linux64",
-                       "i686"   : "linux32",
-                       "i586"   : "linux32",
-                       "i486"   : "linux32",
-               }
-
-               try:
-                       personality = arch2personality[self.arch]
-               except KeyError:
-                       personality = None
-
-               return personality
index a4aa255215d664c863b2d37e7d190390e58b2cee..1c4b6dc950f5f7210a1f4c2071d25bddbb68dead 100644 (file)
@@ -24,6 +24,7 @@ import os
 import socket
 import tempfile
 
+from . import arch
 from . import shell
 
 from . import _pakfire
@@ -35,6 +36,9 @@ class System(object):
                Class that grants access to several information about
                the system this software is running on.
        """
+       def __init__(self):
+               self.arch = arch.Arch(self.native_arch)
+
        @property
        def hostname(self):
                hn = socket.gethostname()
@@ -61,48 +65,18 @@ class System(object):
                """
                return os.uname()[4]
 
-       @property
-       def arch(self):
-               """
-                       Return the architecture of the host we are running on.
-               """
-               if self.supported_arches and not self.native_arch in self.supported_arches:
-                       return self.supported_arches[0]
-
-               return self.native_arch
-
        @property
        def supported_arches(self):
                """
                        Check what architectures can be built on this host.
                """
-               host_can_build = {
-                       # Host arch : Can build these arches.
-
-                       # x86
-                       "x86_64"    : ["x86_64", "i686",],
-                       "i686"      : ["i686",],
-
-                       # ARM
-                       "armv5tel"  : ["armv5tel",],
-                       "armv5tejl" : ["armv5tel",],
-                       "armv6l"    : ["armv5tel",],
-                       "armv7l"    : ["armv7hl", "armv5tel",],
-                       "armv7hl"   : ["armv7hl", "armv5tel",],
-
-                       "aarch64"   : ["aarch64",],
-               }
-
-               try:
-                       return host_can_build[self.native_arch]
-               except KeyError:
-                       return []
+               return self.arch.compatible_arches
 
        def host_supports_arch(self, arch):
                """
                        Check if this host can build for the target architecture "arch".
                """
-               return arch in self.supported_arches
+               return self.arch.is_compatible_with(arch)
 
        @property
        def cpu_count(self):