[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [extra-cmake-modules] find-modules: Add a sip wrapper
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2016-10-31 15:39:47
Message-ID: E1c1Egd-0003hC-Sp () code ! kde ! org
[Download RAW message or body]

Git commit e052fc95db845a5e0f0b450c8fbffb35f0bbc638 by Stephen Kelly.
Committed on 31/10/2016 at 15:35.
Pushed by skelly into branch 'master'.

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.

A  +55   -0    find-modules/run-sip.py

http://commits.kde.org/extra-cmake-modules/e052fc95db845a5e0f0b450c8fbffb35f0bbc638

diff --git a/find-modules/run-sip.py b/find-modules/run-sip.py
new file mode 100755
index 0000000..74c8486
--- /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)

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic