From d334d55c1156d3286c272efe3b1d6c8c03541363 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 26 Oct 2017 21:27:23 +0200 Subject: [PATCH] scanobj: Don't depend on the system shell * Instead of piping to /dev/null use check_output which pipes the output to a return value by default * Instead of passing the argument list through as is, split them with shlex.split() and pass them as a proper argument list. This makes it possible to run gtk-doc under Windows with mingw. https://bugzilla.gnome.org/show_bug.cgi?id=789531 --- gtkdoc/scangobj.py | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py index 235a851..0bfb434 100644 --- a/gtkdoc/scangobj.py +++ b/gtkdoc/scangobj.py @@ -29,6 +29,7 @@ import logging import os import string import subprocess +import shlex from . import common, config @@ -1254,32 +1255,44 @@ def run(options): x_file = options.module + '-scan' + config.exeext - stdout = "" - if not options.verbose: - stdout = ">/dev/null" + if options.verbose: + call = subprocess.check_call + else: + call = subprocess.check_output logging.debug('Intermediate scanner files: %s, %s, %s', c_file, o_file, x_file) # Compiling scanner - command = '%s %s %s -c -o %s %s' % (options.cc, stdout, options.cflags, o_file, c_file) - res = subprocess.check_call(command, shell=True) - if res > 0: - logging.warning('Compilation of scanner failed: %d', res) - return res + try: + call(shlex.split(options.cc) + shlex.split(options.cflags) + + ["-c", "-o", o_file, c_file]) + except subprocess.CalledProcessError as e: + logging.warning('Compilation of scanner failed: %d', e.returncode) + return e.returncode + except OSError as e: + logging.warning(str(e)) + return 1 # Linking scanner - command = '%s %s %s %s -o %s' % (options.ld, stdout, o_file, options.ldflags, x_file) - res = subprocess.check_call(command, shell=True) - if res > 0: - logging.warning('Linking of scanner failed: %d', res) - return res + try: + call(shlex.split(options.ld) + [o_file] + + shlex.split(options.ldflags) + ['-o', x_file]) + except subprocess.CalledProcessError as e: + logging.warning('Linking of scanner failed: %d', e.returncode) + return e.returncode + except OSError as e: + logging.warning(str(e)) + return 1 # Running scanner - command = '%s ./%s' % (options.run, x_file) - res = subprocess.check_call(command, shell=True) - if res > 0: - logging.warning('Running scanner failed: %d', res) - return res + try: + call(shlex.split(options.run) + ['./' + x_file]) + except subprocess.CalledProcessError as e: + logging.warning('Running scanner failed: %d', e.returncode) + return e.returncode + except OSError as e: + logging.warning(str(e)) + return 1 logging.debug('Scan complete') if 'GTK_DOC_KEEP_INTERMEDIATE' not in os.environ: -- 2.11.4.GIT