如何让 SCons 安装与在不同层次结构级别上构建的行为相同? [英] How to get SCons Install to behave the same way as build at different hierarchy levels?

查看:50
本文介绍了如何让 SCons 安装与在不同层次结构级别上构建的行为相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目如下树

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

我想将A的内容安装到/install/A中,将B的内容安装到/install/B,我通过从顶部 SConstruct 调用的两个外观相似的 SConscripts 来实现这一点.SConstruct 设置 env['INSTALL_DIR'] = '/install' 并导出它.A SConscript 如下所示:

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)

B类似.

AB 都过时,并且我在 A 子目录中时,我可以运行 scons -u 那里,它只会构建 A.但是如果我在那里运行 scons -u install,那么它也会尝试安装 B,导致它也构建 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.

我可以通过为安装使用不同的别名(install-Ainstall-B)和一个合二为一来解决它,但我不想要记住所有这些名字.我只希望安装在当前位置的行为与构建相同.如何实现?

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?

推荐答案

您必须将安装目标添加到默认目标列表中.有一个方法 env.Default() 为此,请查看 SCons 的文档.请注意,您还可以如何将别名添加到默认列表中(一旦定义,它们几乎被视为文件目标).

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)

就像在其他所有构建系统中一样,SCons 会将您的安装文件夹视为最新的,只要它存在……然后就不会更新您要安装的文件.相反,在调用安装构建器之后定义别名,并添加返回值...代表程序"节点的路径:

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)

这篇关于如何让 SCons 安装与在不同层次结构级别上构建的行为相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆