[gobject-introspection] scanner: Support running under MSYS



commit c82933bb6622eb816d87c2a1b2ab0ba273ee419c
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date:   Fri Feb 21 11:16:35 2014 +0000

    scanner: Support running under MSYS
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724880

 giscanner/dumper.py |   15 +++++++++++++++
 giscanner/utils.py  |   24 ++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index b415dd1..a63440e 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -295,10 +295,25 @@ class DumpCompiler(object):
             print "g-ir-scanner: link: %s" % (
                 subprocess.list2cmdline(args), )
             sys.stdout.flush()
+        msys = os.environ.get('MSYSTEM', None)
+        if msys:
+            shell = os.environ.get('SHELL', 'sh.exe')
+            # Create a temporary script file that
+            # runs the command we want
+            tf, tf_name = tempfile.mkstemp()
+            f = os.fdopen(tf, 'wb')
+            fcontents = '#!/bin/sh\nunset PWD\n{}\n'.format(' '.join ([x.replace ('\\','/') for x in args]))
+            f.write(fcontents)
+            f.close()
+            shell = utils.which(shell)
+            args = [shell, tf_name.replace('\\','/')]
         try:
             subprocess.check_call(args)
         except subprocess.CalledProcessError as e:
             raise LinkerError(e)
+        finally:
+            if msys:
+                os.remove(tf_name)
 
     def _add_link_internal_args(self, args, libtool):
         # An "internal" link is where the library to be introspected
diff --git a/giscanner/utils.py b/giscanner/utils.py
index c0d49d2..b1fdcb4 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -182,3 +182,27 @@ def cflag_real_include_path(cflag):
         return cflag
 
     return "-I" + os.path.realpath(cflag[2:])
+
+def which(program):
+    def is_exe(fpath):
+        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+    def is_nt_exe(fpath):
+        return not fpath.lower().endswith('.exe') and os.path.isfile(fpath + '.exe') and os.access(fpath + 
'.exe', os.X_OK)
+
+    fpath, fname = os.path.split(program)
+    if fpath:
+        if is_exe(program):
+            return program
+        if os.name == 'nt' and is_nt_exe(program):
+            return program + '.exe'
+    else:
+        for path in os.environ["PATH"].split(os.pathsep):
+            path = path.strip('"')
+            exe_file = os.path.join(path, program)
+            if is_exe(exe_file):
+                return exe_file
+            if os.name == 'nt' and is_nt_exe(exe_file):
+                return exe_file + '.exe'
+
+    return None


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]