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 \
--- /dev/null
+#!/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
# #
###############################################################################
+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):
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)))
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)
"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,
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
import socket
import tempfile
+from . import arch
from . import shell
from . import _pakfire
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()
"""
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):