How to get SCons Install to behave the same way as build at different hierarchy levels?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:37:28

问题


My project is the following tree

|-- A
|   `-- SConscript
|-- B
|   `-- SConscript
`-- SConstruct

and I want to install A's content into /install/A, and B's into /install/B, I achieve this by two similar looking SConscripts called from the top SConstruct. SConstruct sets up env['INSTALL_DIR'] = '/install' and exports it. The A SConscript looks like this:

Import('env')
env = env.Clone(
    INSTALL_DIR = os.path.join(env['INSTALL_DIR'], "A"))
env.Alias('install', env['INSTALL_DIR'])

build_result_obj = Program(...)
env.Install(env['INSTALL_DIR'], build_result_obj)

and similar for B.

When both, A and B are outdated, and I am in A subdirectory, I can run scons -u there, and it will only build A. But if I run scons -u install there, then it would try to install B as well, causing it to build B too.

I could resolve it by having different Alias names for install (install-A, install-B) and a combined one for two, but I don't want to remember all such names. I just want the install to behave the same as build with respect to the current location. How to achieve that?


回答1:


You'll have to add your install targets to the Default target list. There is a method env.Default() for this, please check the docs of SCons. Note, how you can add Aliases to the Default list, too (once defined they're pretty much treated like file targets).

Another thing to regard here is, that you shouldn't define the install Aliases as simply

Alias('name', path_to_folder)

Like in every other build system, SCons will regard your install folder as up to date, as soon as it exists...and then no updates of your to-be-installed files happen. Instead, define the Alias after you called the Install builder, and add the return value...which represents the path to the "program" node:

build_result_obj = Program(...)
instobj = env.Install(env['INSTALL_DIR'], build_result_obj)
env.Alias('install', instobj)


来源:https://stackoverflow.com/questions/25560291/how-to-get-scons-install-to-behave-the-same-way-as-build-at-different-hierarchy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!