diff options
author | Christopher Clark <christopher.w.clark@gmail.com> | 2020-02-25 16:15:59 -0800 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2020-02-27 16:59:23 -0500 |
commit | f4eec68635bc516ce99c804bdc876f74dd4523fc (patch) | |
tree | 149b04d3a85851703a72346b9b9247e5ce025b3c /recipes-extended/xen/files/xen-tools-pygrub-py3.patch | |
parent | 593df044c6a18ac3594215f5b93ecbc3ceab9f44 (diff) | |
download | meta-virtualization-f4eec68635bc516ce99c804bdc876f74dd4523fc.tar.gz |
xen, xen-tools: update recipes for python3
Adds patches for packaged scripts to enable deployment with python3
where they have been ported to python 3 upstream.
setuptools3 inherits distutils3 which modifies ${B}, so cd ${S} is
needed in the do_configure, do_compile and do_install steps.
Remove python 2 dependency from the Xen recipes by adding a new
separate recipe, xen-python2, for packaging the remaining optional
scripts which are yet to be ported to python 3. Package naming in
the separate recipe is chosen to support transition back into the
xen-tools recipe if the scripts are ported later.
Use RSUGGESTS to support inclusion of the xen-python2 scripts in
images that include python 2.
Drop the remus package python dependency since the script was removed
in 2014: commit 5b66f84e37a45038f9e5dae7a5768a5525d1e6ba
Add python3 RDEPENDS needed to run xenmon.
Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'recipes-extended/xen/files/xen-tools-pygrub-py3.patch')
-rw-r--r-- | recipes-extended/xen/files/xen-tools-pygrub-py3.patch | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/recipes-extended/xen/files/xen-tools-pygrub-py3.patch b/recipes-extended/xen/files/xen-tools-pygrub-py3.patch new file mode 100644 index 00000000..e486646f --- /dev/null +++ b/recipes-extended/xen/files/xen-tools-pygrub-py3.patch | |||
@@ -0,0 +1,233 @@ | |||
1 | From 83a204e6951c6358f995da3b60dd61224e9d41ac Mon Sep 17 00:00:00 2001 | ||
2 | From: Wei Liu <wei.liu2@citrix.com> | ||
3 | Date: Tue, 5 Mar 2019 14:13:17 +0000 | ||
4 | Subject: [PATCH] pygrub/fsimage: make it work with python 3 | ||
5 | |||
6 | With the help of two porting guides and cpython source code: | ||
7 | |||
8 | 1. Use PyBytes to replace PyString counterparts. | ||
9 | 2. Use PyVarObject_HEAD_INIT. | ||
10 | 3. Remove usage of Py_FindMethod. | ||
11 | 4. Use new module initialisation routine. | ||
12 | |||
13 | For #3, Py_FindMethod was removed, yet an alternative wasn't | ||
14 | documented. The code is the result of reverse-engineering cpython | ||
15 | commit 6116d4a1d1 | ||
16 | |||
17 | https://docs.python.org/3/howto/cporting.html | ||
18 | http://python3porting.com/cextensions.html | ||
19 | |||
20 | Signed-off-by: Wei Liu <wei.liu2@citrix.com> | ||
21 | Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> | ||
22 | --- | ||
23 | tools/pygrub/src/fsimage/fsimage.c | 123 ++++++++++++++++------------- | ||
24 | 1 file changed, 69 insertions(+), 54 deletions(-) | ||
25 | |||
26 | diff --git a/tools/pygrub/src/fsimage/fsimage.c b/tools/pygrub/src/fsimage/fsimage.c | ||
27 | index 780207791c..2ebbbe35df 100644 | ||
28 | --- a/tools/pygrub/src/fsimage/fsimage.c | ||
29 | +++ b/tools/pygrub/src/fsimage/fsimage.c | ||
30 | @@ -26,12 +26,6 @@ | ||
31 | #include <xenfsimage.h> | ||
32 | #include <stdlib.h> | ||
33 | |||
34 | -#if (PYTHON_API_VERSION >= 1011) | ||
35 | -#define PY_PAD 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L | ||
36 | -#else | ||
37 | -#define PY_PAD 0L,0L,0L,0L | ||
38 | -#endif | ||
39 | - | ||
40 | typedef struct fsimage_fs { | ||
41 | PyObject_HEAD | ||
42 | fsi_t *fs; | ||
43 | @@ -59,12 +53,24 @@ fsimage_file_read(fsimage_file_t *file, PyObject *args, PyObject *kwargs) | ||
44 | |||
45 | bufsize = size ? size : 4096; | ||
46 | |||
47 | - if ((buffer = PyString_FromStringAndSize(NULL, bufsize)) == NULL) | ||
48 | + buffer = | ||
49 | +#if PY_MAJOR_VERSION < 3 | ||
50 | + PyString_FromStringAndSize(NULL, bufsize); | ||
51 | +#else | ||
52 | + PyBytes_FromStringAndSize(NULL, bufsize); | ||
53 | +#endif | ||
54 | + | ||
55 | + if (buffer == NULL) | ||
56 | return (NULL); | ||
57 | |||
58 | while (1) { | ||
59 | int err; | ||
60 | - void *buf = PyString_AS_STRING(buffer) + bytesread; | ||
61 | + void *buf = | ||
62 | +#if PY_MAJOR_VERSION < 3 | ||
63 | + PyString_AS_STRING(buffer) + bytesread; | ||
64 | +#else | ||
65 | + PyBytes_AS_STRING(buffer) + bytesread; | ||
66 | +#endif | ||
67 | |||
68 | err = fsi_pread_file(file->file, buf, bufsize, | ||
69 | bytesread + offset); | ||
70 | @@ -84,12 +90,20 @@ fsimage_file_read(fsimage_file_t *file, PyObject *args, PyObject *kwargs) | ||
71 | if (bufsize == 0) | ||
72 | break; | ||
73 | } else { | ||
74 | +#if PY_MAJOR_VERSION < 3 | ||
75 | if (_PyString_Resize(&buffer, bytesread + bufsize) < 0) | ||
76 | +#else | ||
77 | + if (_PyBytes_Resize(&buffer, bytesread + bufsize) < 0) | ||
78 | +#endif | ||
79 | return (NULL); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | +#if PY_MAJOR_VERSION < 3 | ||
84 | _PyString_Resize(&buffer, bytesread); | ||
85 | +#else | ||
86 | + _PyBytes_Resize(&buffer, bytesread); | ||
87 | +#endif | ||
88 | return (buffer); | ||
89 | } | ||
90 | |||
91 | @@ -106,11 +120,13 @@ static struct PyMethodDef fsimage_file_methods[] = { | ||
92 | { NULL, NULL, 0, NULL } | ||
93 | }; | ||
94 | |||
95 | +#if PY_MAJOR_VERSION < 3 | ||
96 | static PyObject * | ||
97 | fsimage_file_getattr(fsimage_file_t *file, char *name) | ||
98 | { | ||
99 | return (Py_FindMethod(fsimage_file_methods, (PyObject *)file, name)); | ||
100 | } | ||
101 | +#endif | ||
102 | |||
103 | static void | ||
104 | fsimage_file_dealloc(fsimage_file_t *file) | ||
105 | @@ -123,29 +139,18 @@ fsimage_file_dealloc(fsimage_file_t *file) | ||
106 | |||
107 | static char fsimage_file_type__doc__[] = "Filesystem image file"; | ||
108 | PyTypeObject fsimage_file_type = { | ||
109 | - PyObject_HEAD_INIT(&PyType_Type) | ||
110 | - 0, /* ob_size */ | ||
111 | - "xenfsimage.file", /* tp_name */ | ||
112 | - sizeof(fsimage_file_t), /* tp_size */ | ||
113 | - 0, /* tp_itemsize */ | ||
114 | - (destructor) fsimage_file_dealloc, /* tp_dealloc */ | ||
115 | - 0, /* tp_print */ | ||
116 | - (getattrfunc) fsimage_file_getattr, /* tp_getattr */ | ||
117 | - 0, /* tp_setattr */ | ||
118 | - 0, /* tp_compare */ | ||
119 | - 0, /* tp_repr */ | ||
120 | - 0, /* tp_as_number */ | ||
121 | - 0, /* tp_as_sequence */ | ||
122 | - 0, /* tp_as_mapping */ | ||
123 | - 0, /* tp_hash */ | ||
124 | - 0, /* tp_call */ | ||
125 | - 0, /* tp_str */ | ||
126 | - 0, /* tp_getattro */ | ||
127 | - 0, /* tp_setattro */ | ||
128 | - 0, /* tp_as_buffer */ | ||
129 | - Py_TPFLAGS_DEFAULT, /* tp_flags */ | ||
130 | - fsimage_file_type__doc__, | ||
131 | - PY_PAD | ||
132 | + PyVarObject_HEAD_INIT(&PyType_Type, 0) | ||
133 | + .tp_name = "xenfsimage.file", | ||
134 | + .tp_basicsize = sizeof(fsimage_file_t), | ||
135 | + .tp_dealloc = (destructor) fsimage_file_dealloc, | ||
136 | +#if PY_MAJOR_VERSION < 3 | ||
137 | + .tp_getattr = (getattrfunc) fsimage_file_getattr, | ||
138 | +#endif | ||
139 | + .tp_flags = Py_TPFLAGS_DEFAULT, | ||
140 | + .tp_doc = fsimage_file_type__doc__, | ||
141 | +#if PY_MAJOR_VERSION >= 3 | ||
142 | + .tp_methods = fsimage_file_methods, | ||
143 | +#endif | ||
144 | }; | ||
145 | |||
146 | static PyObject * | ||
147 | @@ -208,11 +213,13 @@ static struct PyMethodDef fsimage_fs_methods[] = { | ||
148 | { NULL, NULL, 0, NULL } | ||
149 | }; | ||
150 | |||
151 | +#if PY_MAJOR_VERSION < 3 | ||
152 | static PyObject * | ||
153 | fsimage_fs_getattr(fsimage_fs_t *fs, char *name) | ||
154 | { | ||
155 | return (Py_FindMethod(fsimage_fs_methods, (PyObject *)fs, name)); | ||
156 | } | ||
157 | +#endif | ||
158 | |||
159 | static void | ||
160 | fsimage_fs_dealloc (fsimage_fs_t *fs) | ||
161 | @@ -225,29 +232,18 @@ fsimage_fs_dealloc (fsimage_fs_t *fs) | ||
162 | PyDoc_STRVAR(fsimage_fs_type__doc__, "Filesystem image"); | ||
163 | |||
164 | PyTypeObject fsimage_fs_type = { | ||
165 | - PyObject_HEAD_INIT(&PyType_Type) | ||
166 | - 0, /* ob_size */ | ||
167 | - "xenfsimage.fs", /* tp_name */ | ||
168 | - sizeof(fsimage_fs_t), /* tp_size */ | ||
169 | - 0, /* tp_itemsize */ | ||
170 | - (destructor) fsimage_fs_dealloc, /* tp_dealloc */ | ||
171 | - 0, /* tp_print */ | ||
172 | - (getattrfunc) fsimage_fs_getattr, /* tp_getattr */ | ||
173 | - 0, /* tp_setattr */ | ||
174 | - 0, /* tp_compare */ | ||
175 | - 0, /* tp_repr */ | ||
176 | - 0, /* tp_as_number */ | ||
177 | - 0, /* tp_as_sequence */ | ||
178 | - 0, /* tp_as_mapping */ | ||
179 | - 0, /* tp_hash */ | ||
180 | - 0, /* tp_call */ | ||
181 | - 0, /* tp_str */ | ||
182 | - 0, /* tp_getattro */ | ||
183 | - 0, /* tp_setattro */ | ||
184 | - 0, /* tp_as_buffer */ | ||
185 | - Py_TPFLAGS_DEFAULT, /* tp_flags */ | ||
186 | - fsimage_fs_type__doc__, | ||
187 | - PY_PAD | ||
188 | + PyVarObject_HEAD_INIT(&PyType_Type, 0) | ||
189 | + .tp_name = "xenfsimage.fs", | ||
190 | + .tp_basicsize = sizeof(fsimage_fs_t), | ||
191 | + .tp_dealloc = (destructor) fsimage_fs_dealloc, | ||
192 | +#if PY_MAJOR_VERSION < 3 | ||
193 | + .tp_getattr = (getattrfunc) fsimage_fs_getattr, | ||
194 | +#endif | ||
195 | + .tp_flags = Py_TPFLAGS_DEFAULT, | ||
196 | + .tp_doc = fsimage_fs_type__doc__, | ||
197 | +#if PY_MAJOR_VERSION >= 3 | ||
198 | + .tp_methods = fsimage_fs_methods, | ||
199 | +#endif | ||
200 | }; | ||
201 | |||
202 | static PyObject * | ||
203 | @@ -309,8 +305,27 @@ static struct PyMethodDef fsimage_module_methods[] = { | ||
204 | { NULL, NULL, 0, NULL } | ||
205 | }; | ||
206 | |||
207 | +#if PY_MAJOR_VERSION >= 3 | ||
208 | +static struct PyModuleDef fsimage_module_def = { | ||
209 | + PyModuleDef_HEAD_INIT, | ||
210 | + .m_name = "xenfsimage", | ||
211 | + .m_size = -1, | ||
212 | + .m_methods = fsimage_module_methods, | ||
213 | +}; | ||
214 | +#endif | ||
215 | + | ||
216 | PyMODINIT_FUNC | ||
217 | +#if PY_MAJOR_VERSION >= 3 | ||
218 | +PyInit_xenfsimage(void) | ||
219 | +#else | ||
220 | initxenfsimage(void) | ||
221 | +#endif | ||
222 | { | ||
223 | +#if PY_MAJOR_VERSION < 3 | ||
224 | Py_InitModule("xenfsimage", fsimage_module_methods); | ||
225 | +#else | ||
226 | + if (PyType_Ready(&fsimage_fs_type) < 0 || PyType_Ready(&fsimage_file_type) < 0) | ||
227 | + return NULL; | ||
228 | + return PyModule_Create(&fsimage_module_def); | ||
229 | +#endif | ||
230 | } | ||
231 | -- | ||
232 | 2.17.1 | ||
233 | |||