diff options
author | Stephen Kelly <steveire@gmail.com> | 2016-04-24 23:58:55 +0200 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2016-10-31 15:35:56 +0000 |
commit | e052fc95db845a5e0f0b450c8fbffb35f0bbc638 (patch) | |
tree | 15b919231e2635712167f63c1240092f8b880837 /find-modules/run-sip.py | |
parent | 9e83e56088057a68589ffa99ce6019058f4e4fd9 (diff) | |
download | extra-cmake-modules-e052fc95db845a5e0f0b450c8fbffb35f0bbc638.tar.gz extra-cmake-modules-e052fc95db845a5e0f0b450c8fbffb35f0bbc638.tar.bz2 |
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.
Diffstat (limited to 'find-modules/run-sip.py')
-rwxr-xr-x | find-modules/run-sip.py | 55 |
1 files changed, 55 insertions, 0 deletions
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) |