[rtems-source-builder commit] sb: Add support to GDB to select a specific Python.

Chris Johns chrisj at rtems.org
Tue Mar 8 11:29:58 UTC 2016


Module:    rtems-source-builder
Branch:    master
Commit:    334c22c12d2f60e0cd710a0fe27dd7e03795bdf9
Changeset: http://git.rtems.org/rtems-source-builder/commit/?id=334c22c12d2f60e0cd710a0fe27dd7e03795bdf9

Author:    Chris Johns <chrisj at rtems.org>
Date:      Tue Mar  8 22:23:01 2016 +1100

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

Detect a suitable Python version on Windows.

Update #2619.

---

 source-builder/config/gdb-7-1.cfg | 12 ++++++++-
 source-builder/sb/windows.py      | 51 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/source-builder/config/gdb-7-1.cfg b/source-builder/config/gdb-7-1.cfg
index 90a1f5a..0fef5b3 100644
--- a/source-builder/config/gdb-7-1.cfg
+++ b/source-builder/config/gdb-7-1.cfg
@@ -60,6 +60,16 @@ BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
 %endif
 
 #
+# The --with-python option is either the default which is auto or the path to
+# the specific python to be used.
+#
+%if %{defined with_python_path}
+  %define with_python_option --with-python=%{with_python_path}
+%else
+  %define with_python_option --with-python
+%endif
+
+#
 #
 # Prepare the source code.
 #
@@ -104,7 +114,7 @@ BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
     %{?gdb-sim-options:%{gdb-sim-options}} \
     --without-zlib \
     --with-expat \
-    %{!?without_python:--with-python} \
+    %{!?without_python:%{with_python_option}} \
     --prefix=%{_prefix} --bindir=%{_bindir} \
     --exec-prefix=%{_exec_prefix} \
     --includedir=%{_includedir} --libdir=%{_libdir} \
diff --git a/source-builder/sb/windows.py b/source-builder/sb/windows.py
index f613da2..5e732b5 100644
--- a/source-builder/sb/windows.py
+++ b/source-builder/sb/windows.py
@@ -24,6 +24,7 @@
 import error
 import pprint
 import os
+import sys
 
 import execute
 
@@ -125,6 +126,56 @@ def load():
         '_buildshell':       ('exe',     'required', '%{__sh}'),
         '___setup_shell':    ('exe',     'required', '%{__sh}')
         }
+
+    #
+    # Locate a suitable python to use with GDB. Python Windows is more
+    # complicated than most hosts. There are 7 possible pythons on Windows and
+    # we can use only 4 which are split on machine size. The types are:
+    #
+    #  1. Python27 - python.org, cannot use cause built with MSVC.
+    #  2. Python35 - python.org, cannot use cause built with MSVC.
+    #  3. MSYS/Python - MSYS2, cannot use cause it is a MSYS executable.
+    #  4. W64/Python2 - Ok if machsize is 64
+    #  5. W64/Python3 - gdb-7.9 needs python2.
+    #  6. W64/Python2 - Ok if machsize is 32
+    #  7. W64/Python3 - gdb-7.9 needs python2.
+    #
+    if sys.platform == 'win32' and 'MSC' in sys.version:
+        raise error.general('python.org Pythons are built with MSC and cannot be linked with GDB')
+
+    #
+    # Search the MSYS2 install tree for a suitable python.
+    #
+    if sys.platform == 'msys':
+        e = execute.capture_execution()
+        exit_code, proc, output = e.shell("sh -c mount")
+        if exit_code != 0:
+            raise error.general('cannot get MSYS mount points')
+        install_point = None
+        for l in output.split('\n'):
+            if ' on / ' in l:
+                install_point = l.split()[0]
+                break
+        if install_point is None:
+            raise error.general('cannot locate MSYS root mount point')
+        if install_point[1] != ':':
+            raise error.general('invalid MSYS root mount point: %s' % install_point)
+        install_point = '/%s%s' % (install_point[0], install_point[2:])
+        bin = '/mingw%s/bin' % (machsize)
+        bin_list = os.listdir(bin)
+        exe = None
+        for python in ['python2.exe']:
+            for f in bin_list:
+                if f == python:
+                    exe = install_point + os.path.join(bin, f)
+                    break;
+            if exe is not None:
+                break
+        if exe is None:
+            raise error.general('no valid python found; you need a mingw%s python2 installed' % (machsize))
+        defines['with_python_path'] = exe
+
+
     return defines
 
 if __name__ == '__main__':



More information about the vc mailing list