[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH] tools/python: Correct extension filenames for Python 3



Python distutils really looks like between 2 and 3, it took two steps
forward and then two steps backward.

First, it broke the linking step off of the compile step.  Thus CC and
LDSHARED were separated, thus CFLAGS and LDFLAGS were separated.  A
substantial step forwards.  Yet then CFLAGS was appended to LDFLAGS,
meaning LDSHARED needed to be able to accept CFLAGS as arguments.  Thus
effectively reuniting them.

Second, now distutils includes the host type in the object file area and
the full host triplet in the shared object name.  As such now a
filesystem can be shared by hosts with distinct architectures.  Great for
mixed environments.  Yet the build machine architecture/triplet is
assumed to be the runtime architecture, thus we end up with a workaround
something like the below.

The current state of this seems like a pretty awful hack.  I'm making
assumptions about the architecture which I won't bet on holding.  This
was really a quick hack for Pry Mar to assist with the current situation.

A proper solution is needed.  This feels like a proof-of-concept, but
needs refinement before ending up in any tree.

---
 tools/pygrub/setup.py | 16 +++++++++++++++-
 tools/python/setup.py | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
index b8f1dc4590..737f97d679 100644
--- a/tools/pygrub/setup.py
+++ b/tools/pygrub/setup.py
@@ -7,6 +7,19 @@ extra_compile_args  = [ "-fno-strict-aliasing", "-Werror" ]
 
 XEN_ROOT = "../.."
 
+from distutils import command
+import distutils.command.build_ext
+class BuildExtArch(distutils.command.build_ext.build_ext):
+       arch_map = {
+               'x86_64':       'amd64',
+               'x86_32':       'i386',
+               'arm64':        'aarch64',
+               'arm32':        'armel',
+       }
+       def get_ext_filename(self, ext_name):
+               name = super().get_ext_filename(ext_name)
+               return name.replace(os.getenv("XEN_COMPILE_ARCH"), 
self.arch_map[os.getenv("XEN_TARGET_ARCH")])
+
 xenfsimage = Extension("xenfsimage",
     extra_compile_args = extra_compile_args,
     include_dirs = [ XEN_ROOT + "/tools/libfsimage/common/" ],
@@ -25,5 +38,6 @@ setup(name='pygrub',
       package_dir={'grub': 'src', 'fsimage': 'src'},
       scripts = ["src/pygrub"],
       packages=pkgs,
-      ext_modules = [ xenfsimage ]
+      ext_modules = [ xenfsimage ],
+      cmdclass = {'build_ext': BuildExtArch},
       )
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8c95db7769..4d761f9360 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -17,6 +17,19 @@ PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
 PATH_LIBXENGUEST = XEN_ROOT + "/tools/libs/guest"
 PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
+from distutils import command
+import distutils.command.build_ext
+class BuildExtArch(distutils.command.build_ext.build_ext):
+       arch_map = {
+               'x86_64':       'amd64',
+               'x86_32':       'i386',
+               'arm64':        'aarch64',
+               'arm32':        'armel',
+       }
+       def get_ext_filename(self, ext_name):
+               name = super().get_ext_filename(ext_name)
+               return name.replace(os.getenv("XEN_COMPILE_ARCH"), 
self.arch_map[os.getenv("XEN_TARGET_ARCH")])
+
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
                include_dirs       = [ PATH_XEN,
@@ -51,5 +64,6 @@ setup(name            = 'xen',
                          'xen.lowlevel',
                         ],
       ext_package = "xen.lowlevel",
-      ext_modules = modules
+      ext_modules = modules,
+      cmdclass = {'build_ext': BuildExtArch},
       )
-- 


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         ehem+sigmsg@xxxxxxx  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445






 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.