Scons Install()仅适用于--install-sandbox

时间:2009-07-22 15:27:52

标签: scons

我有一个用于我正在构建的python模块的SConstruct文件:

import distutils.sysconfig

env = Environment(CPPPATH=['include', distutils.sysconfig.get_python_inc()], 
                  CPPFLAGS='-ggdb', SWIGFLAGS=['-python'], 
                  SWIGPATH=['include'])

env.ParseConfig( 'net-snmp-config --libs --cflags' )
env.Append( LIBS = 'pthread' )

backend_interface = 'src/backend_interface.c'
backend_thread = 'src/backend_thread.c'
python_wrapper = 'src/backend_thread.i'


lib = env.SharedLibrary( target = "_rpdu_backend", 
                         source = [ backend_interface,
                         backend_thread, python_wrapper ],
                         SHLIBPREFIX='' )

env.Install( distutils.sysconfig.get_python_lib(),
             [ lib, 'src/rpdu_backend.py'] )

运行:

$ scons --install-sandbox=./sandbox

导致库和相关的.py模块安装在./sandbox/usr/local/lib/python2.6/site-packages中。如果我只是跑:

# scons

以root身份,没有安装到/usr/local/lib/python2.6/site-packages。

为什么scons在没有沙盒选项的情况下不构建安装目标?

1 个答案:

答案 0 :(得分:4)

因此,经过深入研究,结果证明最好的方法如下:

import distutils.sysconfig

env = Environment(CPPPATH=['include', distutils.sysconfig.get_python_inc()], 
                  CPPFLAGS='-ggdb', SWIGFLAGS=['-python'], 
                  SWIGPATH=['include'])

env.ParseConfig( 'net-snmp-config --libs --cflags' )
env.Append( LIBS = 'pthread' )

backend_interface = 'src/backend_interface.c'
backend_thread = 'src/backend_thread.c'
python_wrapper = 'src/backend_thread.i'


lib = env.SharedLibrary( target = "_rpdu_backend", 
                         source = [ backend_interface,
                         backend_thread, python_wrapper ],
                         SHLIBPREFIX='' )
inst = env.Install( distutils.sysconfig.get_python_lib(),
                    [ lib, 'src/rpdu_backend.py'] )

env.Alias( "install", inst )
env.Depends( inst, lib )
Ignore( '.', inst )

这会设置一个伪目标,当被调用时,会强制SCons超出其通常的“仅在当前目录中构建”的方法。它还确保在安装之前完成构建,并使用以下方式提供方便的卸载:

# scons install --clean