summaryrefslogtreecommitdiff
path: root/scripting/build_tools/fix_swig_imports.py
diff options
context:
space:
mode:
authorsaurabhb172020-02-26 16:40:14 +0530
committerGitHub2020-02-26 16:40:14 +0530
commit02c614b4e64b68758f223391cb5357b3eec78cac (patch)
treead18839d8b4eb1f13419d07878cc4ec4c9b70032 /scripting/build_tools/fix_swig_imports.py
parentb77f5d9d8097c38159c6f60917995d6af13bbe1c (diff)
parent07a8c86216b6b1f694b136ec64c281d62941952e (diff)
downloadKiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.tar.gz
KiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.tar.bz2
KiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.zip
Merge pull request #6 from saurabhb17/master
minor additions
Diffstat (limited to 'scripting/build_tools/fix_swig_imports.py')
-rw-r--r--scripting/build_tools/fix_swig_imports.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/scripting/build_tools/fix_swig_imports.py b/scripting/build_tools/fix_swig_imports.py
new file mode 100644
index 0000000..bcf9dbd
--- /dev/null
+++ b/scripting/build_tools/fix_swig_imports.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+# the purpose of this script is rewriting the swig_import_helper
+# call so it will not load _xxxxx.so/dso from inside a kicad executable
+# because the kicad executable itself sill provide an _xxxxx module
+# that's linked inside itself.
+#
+# for the normal module import it should work the same way with this
+# fix in the swig_import_helper
+#
+
+from sys import argv,exit
+
+if len(argv)<2:
+ print "usage:"
+ print " fix_swig_imports.py file.py"
+ print ""
+ print " will fix the swig import code for working inside KiCad"
+ print " where it happended that the external _pcbnew.so/dll was"
+ print " loaded too -and the internal _pcbnew module was to be used"
+ exit(1)
+
+
+filename = argv[1]
+
+f = open(filename,"rb")
+lines = f.readlines()
+f.close()
+
+
+doneOk = False
+
+if (len(lines)<4000):
+ print "still building"
+ exit(0)
+
+txt = ""
+
+for l in lines:
+ if l.startswith("if _swig_python_version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.10
+ l = l.replace("_swig_python_version_info >= (2, 7, 0)","False")
+ doneOk = True
+ elif l.startswith("elif _swig_python_version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.10
+ l = l.replace("_swig_python_version_info >= (2, 6, 0)","False")
+ doneOk = True
+ if l.startswith("if version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.9
+ l = l.replace("version_info >= (2, 7, 0)","False")
+ doneOk = True
+ elif l.startswith("elif version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.9
+ l = l.replace("version_info >= (2, 6, 0)","False")
+ doneOk = True
+ elif l.startswith("if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
+ l = l.replace("version_info >= (2,6,0)","False")
+ doneOk = True
+ elif l.startswith("if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
+ l = l.replace("version_info >= (2, 6, 0)","False")
+ doneOk = True
+ elif l.startswith("if False:"): # it was already patched?
+ doneOk = True
+ txt = txt + l
+
+f = open(filename,"wb")
+f.write(txt)
+f.close()
+
+if doneOk:
+ print "swig_import_helper fixed for",filename
+else:
+ print "Error: the swig import helper was not fixed, check",filename
+ print " and fix this script: fix_swig_imports.py"
+ exit(2)
+
+
+exit(0)
+
+
+