source: rtems-source-builder/source-builder/sb/windows.py @ 7309d94

4.11
Last change on this file since 7309d94 was 7309d94, checked in by Chris Johns <chrisj@…>, on 03/08/16 at 11:23:01

sb: Add support to GDB to select a specific Python.

Detect a suitable Python version on Windows.

Update #2619.

  • Property mode set to 100644
File size: 7.6 KB
RevLine 
[bf13d27]1#
2# RTEMS Tools Project (http://www.rtems.org/)
[9262cd4]3# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
[bf13d27]4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# Windows specific support and overrides.
22#
23
[4f26bdb]24import error
[bf13d27]25import pprint
26import os
[7309d94]27import sys
[bf13d27]28
29import execute
30
31def load():
[4f26bdb]32    # Default to the native Windows Python.
[bf13d27]33    uname = 'win32'
[f88fcf3]34    if 'PROCESSOR_ARCHITECTURE' in os.environ:
[d4eb08f]35        if os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64':
36            hosttype = 'x86_64'
37            machsize = '64'
38        else:
39            hosttype = 'i686'
40            machsize = '32'
[4f26bdb]41    else:
[d4eb08f]42        hosttype = 'x86_64'
43        machsize = '32'
[4f26bdb]44
[f88fcf3]45    uname = 'mingw32'
46    machine = 'w%s' % (machsize)
47
48    # See if this is actually MSYS2/Cygwin Python
[4f26bdb]49    if os.name == 'posix':
[f88fcf3]50        _uname = os.uname()
51        if _uname[0].startswith('MINGW'):
[4f26bdb]52            pass
[f88fcf3]53        elif _uname[0].startswith('CYGWIN'):
54            hosttype = _uname[4]
55            uname = 'cygwin'
56            machine = 'pc'
57        else:
58            raise error.general('invalid POSIX python for Windows')
59
60    host_triple = '%s-%s-%s' % (hosttype, machine, uname)
61    build_triple = '%s-%s-%s' % (hosttype, machine, uname)
[4f26bdb]62
[f88fcf3]63    if 'NUMBER_OF_PROCESSORS' in os.environ:
[0add2ea]64        ncpus = os.environ['NUMBER_OF_PROCESSORS']
[bf13d27]65    else:
[0add2ea]66        ncpus = '1'
[4f26bdb]67
[f88fcf3]68    if 'MSYSTEM' in os.environ:
[a84249d]69        os.environ.pop('NUMBER_OF_PROCESSORS')
70
[a14171f]71    version = uname[2]
[bf13d27]72    defines = {
[a14171f]73        '_ncpus':            ('none',    'none',     ncpus),
74        '_os':               ('none',    'none',     'win32'),
75        '_build':            ('triplet', 'required', build_triple),
76        '_build_vendor':     ('none',    'none',     'microsoft'),
77        '_build_os':         ('none',    'none',     'win32'),
78        '_build_os_version': ('none',    'none',     version),
79        '_build_cpu':        ('none',    'none',     hosttype),
80        '_build_alias':      ('none',    'none',     '%{nil}'),
81        '_build_arch':       ('none',    'none',     hosttype),
82        '_host':             ('triplet', 'required', host_triple),
83        '_host_vendor':      ('none',    'none',     'microsoft'),
84        '_host_os':          ('none',    'none',     'win32'),
85        '_host_cpu':         ('none',    'none',     hosttype),
86        '_host_alias':       ('none',    'none',     '%{nil}'),
87        '_host_arch':        ('none',    'none',     hosttype),
88        '_usr':              ('dir',     'optional', '/opt/local'),
89        '_var':              ('dir',     'optional', '/opt/local/var'),
90        '__bash':            ('exe',     'required', 'bash'),
91        '__bzip2':           ('exe',     'required', 'bzip2'),
92        '__bison':           ('exe',     'required', 'bison'),
93        '__cat':             ('exe',     'required', 'cat'),
94        '__cc':              ('exe',     'required', 'gcc'),
95        '__chgrp':           ('exe',     'required', 'chgrp'),
96        '__chmod':           ('exe',     'required', 'chmod'),
97        '__chown':           ('exe',     'required', 'chown'),
98        '__cp':              ('exe',     'required', 'cp'),
99        '__cvs':             ('exe',     'required', 'cvs'),
100        '__cxx':             ('exe',     'required', 'g++'),
101        '__flex':            ('exe',     'required', 'flex'),
102        '__git':             ('exe',     'required', 'git'),
103        '__grep':            ('exe',     'required', 'grep'),
104        '__gzip':            ('exe',     'required', 'gzip'),
105        '__id':              ('exe',     'required', 'id'),
106        '__install':         ('exe',     'required', 'install'),
107        '__install_info':    ('exe',     'required', 'install-info'),
108        '__ld':              ('exe',     'required', 'ld'),
109        '__ldconfig':        ('exe',     'none',     ''),
110        '__makeinfo':        ('exe',     'required', 'makeinfo'),
111        '__mkdir':           ('exe',     'required', 'mkdir'),
112        '__mv':              ('exe',     'required', 'mv'),
113        '__nm':              ('exe',     'required', 'nm'),
114        '__nm':              ('exe',     'required', 'nm'),
115        '__objcopy':         ('exe',     'required', 'objcopy'),
116        '__objdump':         ('exe',     'required', 'objdump'),
117        '__patch':           ('exe',     'required', 'patch'),
118        '__patch_bin':       ('exe',     'required', 'patch'),
119        '__rm':              ('exe',     'required', 'rm'),
120        '__sed':             ('exe',     'required', 'sed'),
121        '__sh':              ('exe',     'required', 'sh'),
122        '__tar':             ('exe',     'required', 'bsdtar'),
123        '__touch':           ('exe',     'required', 'touch'),
124        '__unzip':           ('exe',     'required', 'unzip'),
125        '__xz':              ('exe',     'required', 'xz'),
126        '_buildshell':       ('exe',     'required', '%{__sh}'),
127        '___setup_shell':    ('exe',     'required', '%{__sh}')
[bf13d27]128        }
[7309d94]129
130    #
131    # Locate a suitable python to use with GDB. Python Windows is more
132    # complicated than most hosts. There are 7 possible pythons on Windows and
133    # we can use only 4 which are split on machine size. The types are:
134    #
135    #  1. Python27 - python.org, cannot use cause built with MSVC.
136    #  2. Python35 - python.org, cannot use cause built with MSVC.
137    #  3. MSYS/Python - MSYS2, cannot use cause it is a MSYS executable.
138    #  4. W64/Python2 - Ok if machsize is 64
139    #  5. W64/Python3 - gdb-7.9 needs python2.
140    #  6. W64/Python2 - Ok if machsize is 32
141    #  7. W64/Python3 - gdb-7.9 needs python2.
142    #
143    if sys.platform == 'win32' and 'MSC' in sys.version:
144        raise error.general('python.org Pythons are built with MSC and cannot be linked with GDB')
145
146    #
147    # Search the MSYS2 install tree for a suitable python.
148    #
149    if sys.platform == 'msys':
150        e = execute.capture_execution()
151        exit_code, proc, output = e.shell("sh -c mount")
152        if exit_code != 0:
153            raise error.general('cannot get MSYS mount points')
154        install_point = None
155        for l in output.split('\n'):
156            if ' on / ' in l:
157                install_point = l.split()[0]
158                break
159        if install_point is None:
160            raise error.general('cannot locate MSYS root mount point')
161        if install_point[1] != ':':
162            raise error.general('invalid MSYS root mount point: %s' % install_point)
163        install_point = '/%s%s' % (install_point[0], install_point[2:])
164        bin = '/mingw%s/bin' % (machsize)
165        bin_list = os.listdir(bin)
166        exe = None
167        for python in ['python2.exe']:
168            for f in bin_list:
169                if f == python:
170                    exe = install_point + os.path.join(bin, f)
171                    break;
172            if exe is not None:
173                break
174        if exe is None:
175            raise error.general('no valid python found; you need a mingw%s python2 installed' % (machsize))
176        defines['with_python_path'] = exe
177
178
[ab8319a]179    return defines
[bf13d27]180
181if __name__ == '__main__':
182    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.