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) 2006, 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.
28 # 'Linux' : 3, # Linux (lots of systems support emulation)
30 _uname
[0] : 1, # Current OS
33 # All chosen machine-specific implementations must come from the same group
34 # Unlisted archs are in group 0
40 def _get_machine_ranks(target_machine
):
41 # Binaries compiled for _this_machine are best...
42 machine_ranks
= {target_machine
: 0}
44 # If target_machine appears in the first column of this table, all
45 # following machine types on the line will also run on this one
46 # (earlier ones preferred):
49 'i586': ['i486', 'i386'],
50 'i686': ['i586', 'i486', 'i386'],
51 'x86_64': ['i686', 'i586', 'i486', 'i386'],
54 for supported
in _machine_matrix
.get(target_machine
, []):
55 machine_ranks
[supported
] = len(machine_ranks
)
57 # At the lowest priority, try a machine-independant implementation
58 machine_ranks
[None] = len(machine_ranks
)
61 machine_ranks
= _get_machine_ranks(_uname
[-1])
65 """A description of an architecture. Use by L{solver} to make sure it chooses
67 @ivar os_ranks: supported operating systems and their desirability
68 @type os_ranks: {str: int}
69 @ivar machine_ranks: supported CPU types and their desirability
70 @type machine_ranks: {str: int}
71 @ivar child_arch: architecture for dependencies (usually C{self})
72 @type child_arch: L{Architecture}"""
73 def __init__(self
, os_ranks
, machine_ranks
):
74 self
.os_ranks
= os_ranks
75 self
.machine_ranks
= machine_ranks
76 self
.child_arch
= self
79 return "<Arch: %s %s>" % (self
.os_ranks
, self
.machine_ranks
)
81 class SourceArchitecture(Architecture
):
82 """Matches source code that creates binaries for a particular architecture.
83 Note that the L{child_arch} here is the binary; source code depends on binary tools,
84 not on other source packages.
86 def __init__(self
, binary_arch
):
87 Architecture
.__init
__(self
, binary_arch
.os_ranks
, {'src': 1})
88 self
.child_arch
= binary_arch
90 def get_host_architecture():
91 """Get an Architecture that matches implementations that will run on the host machine.
92 @rtype: L{Architecture}"""
93 return Architecture(os_ranks
, machine_ranks
)
95 def get_architecture(os
, machine
):
96 """Get an Architecture that matches binaries that will work on the given system.
97 @param os: OS type, or None for host's type
98 @param machine: CPU type, or None for host's type
99 @return: an Architecture object
100 @rtype: L{Architecture}"""
104 os
: 1, # Perfer binaries for target OS
105 None : 2, # Otherwise, generic OS is fine
108 target_os_ranks
= os_ranks
110 target_machine_ranks
= _get_machine_ranks(machine
)
112 target_machine_ranks
= machine_ranks
113 return Architecture(target_os_ranks
, target_machine_ranks
)