From e052fc95db845a5e0f0b450c8fbffb35f0bbc638 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 24 Apr 2016 23:58:55 +0200 Subject: Add a sip wrapper When sip is executed it is passed one .sip file. However, it uses that to generate multiple cpp source files, one per class in the sip file. Buildsystems need to know the outputs of commands, so this does not work well as the output can't easily be predicted. So, create a unity build of all files to compile into the python module. --- find-modules/run-sip.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 find-modules/run-sip.py (limited to 'find-modules/run-sip.py') diff --git a/find-modules/run-sip.py b/find-modules/run-sip.py new file mode 100755 index 00000000..74c84861 --- /dev/null +++ b/find-modules/run-sip.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import os, sys +import fnmatch +import subprocess + +sipArgs = sys.argv[1:] + +idx = sipArgs.index("--module-name") +modname = sipArgs[idx + 1] +del sipArgs[idx] +del sipArgs[idx] + +idx = sipArgs.index("-c") +loc = sipArgs[idx + 1] + +oldFilenames = fnmatch.filter(os.listdir(loc), "sip" + modname + "*.cpp") +try: + oldFilenames.remove("sip" + modname + "cmodule.cpp") +except: + pass +for f in oldFilenames: + try: + os.remove(os.path.join(loc, f)) + except OSError: + pass + +idx = sipArgs.index("--unify") +unified = sipArgs[idx + 1] +del sipArgs[idx] +del sipArgs[idx] + +idx = sipArgs.index("--sip") +exe = sipArgs[idx + 1] +del sipArgs[idx] +del sipArgs[idx] + +try: + print(subprocess.check_output([exe] + sipArgs)) +except subprocess.CalledProcessError: + sys.exit(1) + +newFilenames = fnmatch.filter(os.listdir(loc), "sip" + modname + "*.cpp") +unifiedString = '\n'.join(['#include "%s"' % f for f in newFilenames]) + '\n' + +for fn in newFilenames: + lines = [] + with open(os.path.join(loc, fn), "r") as f: + lines = f.readlines() + lines = [line for line in lines if not line.startswith("#line")] + with open(os.path.join(loc, fn), "w") as f: + f.write(''.join(lines)) + +with open(unified, "w") as f: + f.write(unifiedString) -- cgit v1.2.1