Вопрос

Using python 2.6, I'm attempting to build an RPM for a python C extension module.

The setup.py that I'm using contains something like:

from distutils.core import setup, Extension

foo_ext = Extension('foo',
                    sources=['foo.c', '../src/common.c'],
                    include_dirs=['../includes'])

setup(... , ext_modules=[foo_ext])

If I run python setup.py build from /devel/foo for example, it compiles and builds without any errors, and gcc is called with the correct paths, i.e.:

gcc ... -I/devel/includes ...

When I use python setup.py bdist_rpm instead, then the relative paths used above are converted to absolute paths relative to the RPM build dir, this results in gcc trying to compile using:

gcc ... -I/devel/foo/build/bdist.linux-x86_64/rpm/BUILD/includes ...

Compilation then fails as a required .h file is not found in the include path.

Any suggestions or workarounds to this?

Это было полезно?

Решение

Solved by setting an environment variable during the first pass through the script, which is then read again when building the RPM:

import os
from distutils.core import setup, Extension

src_path = os.path.abspath('../src/common.c')
inc_path = os.path.abspath('../includes')

if 'SRC_PATH' not in os.environ:
    os.environ['SRC_PATH'] = src_path
    os.environ['INC_PATH'] = inc_path
else:
    src_path = os.environ['SRC_PATH']
    inc_path = os.environ['INC_PATH']

foo_ext = Extension('foo',
                sources=['foo.c', src_path],
                include_dirs=[inc_path])

setup(... , ext_modules=[foo_ext])

Другие советы

I could solve a similar problem by providing distutils with a proper MANIFEST.in file, which enumerated all header files I wanted to include. In my case it was like this:

include src/_rvlm_fdtd/include/rvlm/fdtd/* –or–
recursive-include src/_rvlm_fdtd *.h

but I think this will not work with your ../ paths. Instead I recommend you putting all your source code inside a package base directory.

The reason why RPM build phase was not able to find out your headers is because it builds a source distribution first (with setup.py sdist) and unpacks resulted tarball into a temporary build directory. So your source distribution just did not contain all files necessary for building.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top