File: 01_wrap_python_for_tests.diff

package info (click to toggle)
libfiu 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 376 kB
  • sloc: ansic: 1,272; makefile: 412; python: 397; sh: 263
file content (117 lines) | stat: -rw-r--r-- 3,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 83fb1e675de26ad5409e554e2947e53c8f1b10c0 Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Tue, 3 Apr 2012 21:59:31 +0100
Subject: [PATCH] Properly wrap python to use the built bindings

The Python tests should run using the built bindings, not the installed ones.

This patch adds a wrapper to do the invocation of the python binary with the
appropriate environment variables to make that happen.

Thanks to Chris Lamb for reporting this issue.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 tests/Makefile    |    9 ++-----
 tests/wrap-python |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 6 deletions(-)
 create mode 100755 tests/wrap-python

diff --git a/tests/Makefile b/tests/Makefile
index 9fb7875..40a22a9 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -14,14 +14,11 @@ endif
 ifneq ($(V), 1)
 	NICE_CC = @echo "  CC  $@"; $(CC)
 	NICE_RUN = @echo "  RUN $<"; LD_LIBRARY_PATH=../libfiu/
-	NICE_PY_RUN = @echo "  PY  $<"; \
-		      LD_LIBRARY_PATH=../libfiu/ \
-		      PYTHONPATH=../bindings/python/
+	NICE_PY = @echo "  PY  $<"; python ./wrap-python 2
 else
 	NICE_CC = $(CC)
 	NICE_RUN = LD_LIBRARY_PATH=../libfiu/
-	NICE_PY_RUN = LD_LIBRARY_PATH=../libfiu/ \
-		      PYTHONPATH=../bindings/python/
+	NICE_PY = python ./wrap-python 2
 endif
 
 default: tests
@@ -69,7 +66,7 @@ PY_TESTS := $(wildcard test-*.py)
 py-tests: $(patsubst %.py,py-run-%,$(PY_TESTS))
 
 py-run-%: %.py
-	$(NICE_PY_RUN) python ./$<
+	$(NICE_PY) ./$<
 
 
 clean:
diff --git a/tests/wrap-python b/tests/wrap-python
new file mode 100755
index 0000000..aab0667
--- /dev/null
+++ b/tests/wrap-python
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+# Python wrapper, which makes it able to import the built (and not the
+# installed) version of libfiu.
+#
+# The first parameter must be the python version (2 or 3)
+
+import sys
+import os
+import glob
+
+
+if len(sys.argv) < 2 or sys.argv[1] not in ("2", "3"):
+	sys.stderr.write("Error: the first argument must be the " +
+				"version (2 or 3)\n")
+	sys.exit(1)
+
+py_ver = sys.argv[1]
+
+
+# Find the path where the library was built and add it to the lookup paths, so
+# we run against it
+lib_bin = os.path.dirname(sys.argv[0]) + "/../libfiu/libfiu.so"
+
+if not os.path.exists(lib_bin):
+	sys.stderr.write("Can't find library (run make)\n")
+	sys.exit(1)
+
+lib_path = os.path.dirname(os.path.abspath(lib_bin))
+os.environ["LD_LIBRARY_PATH"] = ":".join([lib_path, \
+				os.environ.get("LD_LIBRARY_PATH", "")])
+
+
+# Find out the corresponding module path for the desired python version. The
+# path must be absolute
+mod_bins = glob.glob(os.path.dirname(sys.argv[0]) +
+			"/../bindings/python/build/lib*-%s.*/fiu_ll.so" \
+				% py_ver)
+if not mod_bins:
+	sys.stderr.write(("Can't find python%s bindings, run " +
+				"make python%s\n") % (py_ver, py_ver))
+	sys.exit(1)
+
+if len(mod_bins) > 1:
+	sys.stderr.write("Found too many matching python%s bindings" \
+				% py_ver)
+	sys.exit(1)
+
+mod_path = os.path.dirname(os.path.abspath(mod_bins[0]))
+os.environ["PYTHONPATH"] = ":".join([mod_path,
+					os.environ.get("PYTHONPATH", "")])
+
+if py_ver == '2':
+	py_bin = "python"
+else:
+	py_bin = "python3"
+
+os.execvp(py_bin, [py_bin] + sys.argv[2:])
+
-- 
1.7.1