aboutsummaryrefslogtreecommitdiff
path: root/tools/ccc/ccclib/HostInfo.py
blob: 12fdfef404afb8aafca8fcf6fa8ad71931849bc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import ToolChain

class HostInfo(object):
    """HostInfo - Config information about a particular host which may
    interact with driver behavior. This can be very different from the
    target(s) of a particular driver invocation."""

    def __init__(self, driver):
        self.driver = driver

    def getArchName(self):
        abstract

    def useDriverDriver(self):
        abstract

    def getToolChain(self):
        abstract

    def getToolChainForArch(self, arch):
        raise RuntimeError,"getToolChainForArch() unsupported on this host."

# Darwin

class DarwinHostInfo(HostInfo):
    def __init__(self, driver):
        super(DarwinHostInfo, self).__init__(driver)
        
        # FIXME: Find right regex for this.
        import re
        m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)', driver.getHostReleaseName())
        if not m:
            raise RuntimeError,"Unable to determine Darwin version."
        self.darwinVersion = tuple(map(int, m.groups()))
        self.gccVersion = (4,2,1)

    def useDriverDriver(self):
        return True

    def getToolChain(self):
        return self.getToolChainForArch(self.getArchName())

    def getToolChainForArch(self, arch):
        if arch in ('i386', 'x86_64'):
            return ToolChain.Darwin_X86_ToolChain(self.driver,
                                                  self.darwinVersion,
                                                  self.gccVersion)

        return ToolChain.Generic_GCC_ToolChain(self.driver)

class DarwinPPCHostInfo(DarwinHostInfo):
    def getArchName(self):
        return 'ppc'

class DarwinPPC_64HostInfo(DarwinHostInfo):
    def getArchName(self):
        return 'ppc64'

class DarwinX86HostInfo(DarwinHostInfo):
    def getArchName(self):
        return 'i386'

class DarwinX86_64HostInfo(DarwinHostInfo):
    def getArchName(self):
        return 'x86_64'

def getDarwinHostInfo(driver):
    machine = driver.getHostMachine()
    bits = driver.getHostBits()
    if machine == 'i386':
        if bits == '32':
            return DarwinX86HostInfo(driver)
        if bits == '64':
            return DarwinX86_64HostInfo(driver)
    elif machine == 'ppc':
        if bits == '32':
            return DarwinPPCHostInfo(driver)
        if bits == '64':
            return DarwinPPC_64HostInfo(driver)
            
    raise RuntimeError,'Unrecognized Darwin platform: %r:%r' % (machine, bits)

# Unknown

class UnknownHostInfo(HostInfo):
    def getArchName(self):
        raise RuntimeError,'getArchName() unsupported on unknown host.'

    def useDriverDriver(self):
        return False

    def getToolChain(self):
        return ToolChain.Generic_GCC_ToolChain(self.driver)

def getUnknownHostInfo(driver):
    return UnknownHostInfo(driver)

####

kSystems = {
    'darwin' : getDarwinHostInfo,
    'unknown' : getUnknownHostInfo,
    }

def getHostInfo(driver):
    system = driver.getHostSystemName()
    handler = kSystems.get(system)
    if handler:
        return handler(driver)

    driver.warning('Unknown host %r, using generic host information.' % system)
    return UnknownHostInfo(driver)