From 036e4e84d7594a2f799501dc3ed173f2d6ddfcc4 Mon Sep 17 00:00:00 2001 From: Clark Williams Date: Wed, 14 Jul 2010 13:13:23 -0500 Subject: added logic to detect invalid architecture combinations (BZ# 607144) Modified py/mock.py to dectect invalid build combinations (e.g. trying to build x86_64 packages on an i386 host) and to throw an InvalidArchitecture exception when detected. Added the above exception to py/mock/execption.py Signed-off-by: Clark Williams --- py/mock.py | 24 ++++++++++++++++++++++++ py/mock/exception.py | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/py/mock.py b/py/mock.py index 6702ba6..b33d247 100755 --- a/py/mock.py +++ b/py/mock.py @@ -363,6 +363,27 @@ def set_config_opts_per_cmdline(config_opts, options, args): config_opts['online'] = options.online +legal_arches = { + 'i386' : ('i386'), + 'x86_64' : ('i386', 'x86_64'), + 'ppc' : ('ppc'), + 'ppc64' : ('ppc', 'ppc64'), + 'sparc' : ('sparc'), + 'sparc64': ('sparc', 'sparc64'), + 's390x' : ('s390x'), +} + +decorate(traceLog()) +def check_arch_combination(target_arch): + host_arch = os.uname()[-1] + try: + if target_arch not in legal_arches[host_arch]: + raise mock.exception.InvalidArchitecture( + "Cannot build target %d on arch %s" % (target_arch, host_arch)) + except KeyError: + raise mock.exception.InvalidArchitecture( + "Unknown target architcture: %s" % target_arch) + decorate(traceLog()) def do_rebuild(config_opts, chroot, srpms): "rebuilds a list of srpms using provided chroot" @@ -543,6 +564,9 @@ def main(ret): # cmdline options override config options set_config_opts_per_cmdline(config_opts, options, args) + # verify that we're not trying to build an arch that we can't + check_arch_combination(config_opts['rpmbuild_arch']) + # default /etc/hosts contents if not config_opts['use_host_resolv'] and not config_opts['files'].has_key('etc/hosts'): config_opts['files']['etc/hosts'] = ''' diff --git a/py/mock/exception.py b/py/mock/exception.py index 16fcbff..d28fdf2 100644 --- a/py/mock/exception.py +++ b/py/mock/exception.py @@ -78,6 +78,13 @@ class BadCmdline(Error): self.msg = msg self.resultcode = 05 +class InvalidArchitecture(Error): + "invalid host/target architecture specified." + def __init(self, msg): + Error.__init__(self, msg) + self.msg = msg + self.resultcode = 06 + class ResultDirNotAccessible(Error): """ Could not create output directory for built rpms. The directory specified was: -- cgit