2 Information about the current system's architecture.
4 This module provides information about the current system. It is used to determine
5 whether an implementation is suitable for this machine, and to compare different implementations.
7 For example, it will indicate that:
9 - An i486 machine cannot run an i686 binary.
10 - An i686 machine can run an i486 binary, but would prefer an i586 one.
11 - A Windows binary cannot run on a Linux machine.
13 Each dictionary maps from a supported architecture type to a preference level. Lower numbers are
14 better, Unsupported architectures are not listed at all.
17 # Copyright (C) 2009, Thomas Leonard
18 # See the README file for details, or visit http://0install.net.
22 # os_ranks and mapping are mappings from names to how good they are.
24 # Higher numbers are worse but usable.
27 except AttributeError:
28 # No uname. Probably Windows (untested).
32 _uname
= ('Windows', 'i486')
34 _uname
= ('Windows', 'x86_64')
39 # 'Linux' : 3, # Linux (lots of systems support emulation)
41 _uname
[0] : 1, # Current OS
44 # All chosen machine-specific implementations must come from the same group
45 # Unlisted archs are in group 0
51 def _get_machine_ranks(target_machine
):
52 # Binaries compiled for _this_machine are best...
53 machine_ranks
= {target_machine
: 0}
55 # If target_machine appears in the first column of this table, all
56 # following machine types on the line will also run on this one
57 # (earlier ones preferred):
60 'i586': ['i486', 'i386'],
61 'i686': ['i586', 'i486', 'i386'],
62 'x86_64': ['i686', 'i586', 'i486', 'i386'],
65 for supported
in _machine_matrix
.get(target_machine
, []):
66 machine_ranks
[supported
] = len(machine_ranks
)
68 # At the lowest priority, try a machine-independant implementation
69 machine_ranks
[None] = len(machine_ranks
)
72 machine_ranks
= _get_machine_ranks(_uname
[-1])
76 """A description of an architecture. Use by L{solver} to make sure it chooses
78 @ivar os_ranks: supported operating systems and their desirability
79 @type os_ranks: {str: int}
80 @ivar machine_ranks: supported CPU types and their desirability
81 @type machine_ranks: {str: int}
82 @ivar child_arch: architecture for dependencies (usually C{self})
83 @type child_arch: L{Architecture}"""
84 def __init__(self
, os_ranks
, machine_ranks
):
85 self
.os_ranks
= os_ranks
86 self
.machine_ranks
= machine_ranks
87 self
.child_arch
= self
90 return "<Arch: %s %s>" % (self
.os_ranks
, self
.machine_ranks
)
92 class SourceArchitecture(Architecture
):
93 """Matches source code that creates binaries for a particular architecture.
94 Note that the L{child_arch} here is the binary; source code depends on binary tools,
95 not on other source packages.
97 def __init__(self
, binary_arch
):
98 Architecture
.__init
__(self
, binary_arch
.os_ranks
, {'src': 1})
99 self
.child_arch
= binary_arch
101 def get_host_architecture():
102 """Get an Architecture that matches implementations that will run on the host machine.
103 @rtype: L{Architecture}"""
104 return Architecture(os_ranks
, machine_ranks
)
106 def get_architecture(os
, machine
):
107 """Get an Architecture that matches binaries that will work on the given system.
108 @param os: OS type, or None for host's type
109 @param machine: CPU type, or None for host's type
110 @return: an Architecture object
111 @rtype: L{Architecture}"""
115 os
: 1, # Perfer binaries for target OS
116 None : 2, # Otherwise, generic OS is fine
119 target_os_ranks
= os_ranks
121 target_machine_ranks
= _get_machine_ranks(machine
)
123 target_machine_ranks
= machine_ranks
124 return Architecture(target_os_ranks
, target_machine_ranks
)