source: rtems-source-builder/source-builder/sb/windows.py @ a0c1f0f

5
Last change on this file since a0c1f0f was a0c1f0f, checked in by Chris Johns <chrisj@…>, on 10/23/18 at 22:16:56

windows: Remove debugging code that fails on Cygwin.

  • Property mode set to 100644
File size: 8.0 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2018 Chris Johns (chrisj@rtems.org)
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
24import os
25import sys
26
27import error
28import execute
29import path
30
31def load():
32    # Default to the native Windows Python.
33    uname = 'win32'
34    if 'PROCESSOR_ARCHITECTURE' in os.environ:
35        if os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64':
36            hosttype = 'x86_64'
37            machsize = '64'
38        else:
39            hosttype = 'i686'
40            machsize = '32'
41    else:
42        hosttype = 'x86_64'
43        machsize = '32'
44
45    uname = 'mingw32'
46    machine = 'w%s' % (machsize)
47
48    # Set the C/C++ compilers we want to use.
49    cc = '%s-%s-%s-gcc' % (hosttype, machine, uname)
50    cxx = '%s-%s-%s-g++' % (hosttype, machine, uname)
51
52    # See if this is actually MSYS2/Cygwin Python
53    if os.name == 'posix':
54        _uname = os.uname()
55        if _uname[0].startswith('MINGW'):
56            pass
57        elif _uname[0].startswith('CYGWIN'):
58            hosttype = _uname[4]
59            uname = 'cygwin'
60            machine = 'pc'
61            cc = 'gcc'
62            cxx = 'g++'
63        else:
64            raise error.general('invalid POSIX python for Windows')
65
66    host_triple = '%s-%s-%s' % (hosttype, machine, uname)
67    build_triple = '%s-%s-%s' % (hosttype, machine, uname)
68
69    if 'NUMBER_OF_PROCESSORS' in os.environ:
70        ncpus = os.environ['NUMBER_OF_PROCESSORS']
71    else:
72        ncpus = '1'
73
74    if 'MSYSTEM' in os.environ:
75        os.environ.pop('NUMBER_OF_PROCESSORS')
76
77    version = uname[2]
78    defines = {
79        '_ncpus':            ('none',    'none',     ncpus),
80        '_os':               ('none',    'none',     'win32'),
81        '_build':            ('triplet', 'required', build_triple),
82        '_build_vendor':     ('none',    'none',     'microsoft'),
83        '_build_os':         ('none',    'none',     'win32'),
84        '_build_os_version': ('none',    'none',     version),
85        '_build_cpu':        ('none',    'none',     hosttype),
86        '_build_alias':      ('none',    'none',     '%{nil}'),
87        '_build_arch':       ('none',    'none',     hosttype),
88        '_host':             ('triplet', 'required', host_triple),
89        '_host_vendor':      ('none',    'none',     'microsoft'),
90        '_host_os':          ('none',    'none',     'win32'),
91        '_host_cpu':         ('none',    'none',     hosttype),
92        '_host_alias':       ('none',    'none',     '%{nil}'),
93        '_host_arch':        ('none',    'none',     hosttype),
94        '_usr':              ('dir',     'optional', '/opt/local'),
95        '_var':              ('dir',     'optional', '/opt/local/var'),
96        '__bash':            ('exe',     'required', 'bash'),
97        '__bzip2':           ('exe',     'required', 'bzip2'),
98        '__bison':           ('exe',     'required', 'bison'),
99        '__cat':             ('exe',     'required', 'cat'),
100        '__cc':              ('exe',     'required', cc),
101        '__chgrp':           ('exe',     'required', 'chgrp'),
102        '__chmod':           ('exe',     'required', 'chmod'),
103        '__chown':           ('exe',     'required', 'chown'),
104        '__cp':              ('exe',     'required', 'cp'),
105        '__cvs':             ('exe',     'optional', 'cvs'),
106        '__cxx':             ('exe',     'required', cxx),
107        '__flex':            ('exe',     'required', 'flex'),
108        '__git':             ('exe',     'required', 'git'),
109        '__grep':            ('exe',     'required', 'grep'),
110        '__gzip':            ('exe',     'required', 'gzip'),
111        '__id':              ('exe',     'required', 'id'),
112        '__install':         ('exe',     'required', 'install'),
113        '__install_info':    ('exe',     'required', 'install-info'),
114        '__ld':              ('exe',     'required', 'ld'),
115        '__ldconfig':        ('exe',     'none',     ''),
116        '__makeinfo':        ('exe',     'required', 'makeinfo'),
117        '__mkdir':           ('exe',     'required', 'mkdir'),
118        '__mv':              ('exe',     'required', 'mv'),
119        '__nm':              ('exe',     'required', 'nm'),
120        '__nm':              ('exe',     'required', 'nm'),
121        '__objcopy':         ('exe',     'required', 'objcopy'),
122        '__objdump':         ('exe',     'required', 'objdump'),
123        '__patch':           ('exe',     'required', 'patch'),
124        '__patch_bin':       ('exe',     'required', 'patch'),
125        '__rm':              ('exe',     'required', 'rm'),
126        '__sed':             ('exe',     'required', 'sed'),
127        '__sh':              ('exe',     'required', 'sh'),
128        '__tar':             ('exe',     'required', 'bsdtar'),
129        '__touch':           ('exe',     'required', 'touch'),
130        '__unzip':           ('exe',     'required', 'unzip'),
131        '__xz':              ('exe',     'required', 'xz'),
132        '_buildshell':       ('exe',     'required', '%{__sh}'),
133        '___setup_shell':    ('exe',     'required', '%{__sh}')
134        }
135
136    #
137    # Locate a suitable python to use with GDB. Python Windows is more
138    # complicated than most hosts. There are 7 possible pythons on Windows and
139    # we can use only 4 which are split on machine size. The types are:
140    #
141    #  1. Python27 - python.org, cannot use cause built with MSVC.
142    #  2. Python35 - python.org, cannot use cause built with MSVC.
143    #  3. MSYS/Python - MSYS2, cannot use cause it is a MSYS executable.
144    #  4. W64/Python2 - Ok if machsize is 64
145    #  5. W64/Python3 - gdb-7.9 needs python2.
146    #  6. W64/Python2 - Ok if machsize is 32
147    #  7. W64/Python3 - gdb-7.9 needs python2.
148    #
149    # Find a suitable python2 and python3.
150    #
151    for p in os.environ['PATH'].split(os.pathsep):
152        sh = os.path.join(p, 'sh.exe')
153        if os.path.exists(sh) and os.path.isfile(sh):
154            break
155        sh = None
156    if sh is None:
157        raise error.general('cannot find a shell (sh.exe) in the PATH')
158    #
159    # Search the MSYS2 install tree for a suitable python.
160    #
161    if sys.platform == 'msys':
162        e = execute.capture_execution()
163        exit_code, proc, output = e.shell("sh -c mount")
164        if exit_code != 0:
165            raise error.general('cannot get MSYS mount points')
166        install_point = None
167        for l in output.split('\n'):
168            if ' on / ' in l:
169                install_point = l.split()[0]
170                break
171        if install_point is None:
172            raise error.general('cannot locate MSYS root mount point')
173        if install_point[1] != ':':
174            raise error.general('invalid MSYS root mount point: %s' % install_point)
175        install_point = path.shell(install_point)
176        mingw = path.join(install_point, 'mingw%s' % (machsize))
177        if not path.exists(mingw) or not path.isdir(mingw):
178            raise error.general('cannot find MinGW install: %s' % (path.host(mingw)))
179        for version in ['2', '3']:
180            python = 'python%s' % (version)
181            exe = path.join(mingw, 'bin', '%s.exe' % (python))
182            if not path.exists(exe) or not path.isdir(exe):
183                defines['gdb_python%s' % (version)] = exe
184                header = path.join(mingw, python)
185
186    return defines
187
188if __name__ == '__main__':
189    import pprint
190    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.