python - 使用 SCons 进行真正的分层构建?

所以我在这里阅读了有关分层构建的问题,例如:Creating a Hierarchical Build with SCons

我想对两个独立的存储库进行真正的分层构造,它们都使用我使用 mercurial 设置为子存储库的 scons。下面是说明我想要做什么的文件布局。

所需的布局:

project_root/  (new project that builds bar app using the libfoo built from source)

    libfoo_subrepo/  (standalone project repo from bitbucket)
        src/
            SConscript
            libfoo.c
            libfoo.h
        test/
            SConscript
            test_foo.c
        SConstruct

    barapp_subrepo/  (standalone project repo from bitbucket that uses libfoo)
        src/
            SConscript
            bar.c
            bar.h
        test/
            SConscript
            test_bar.c
        SConstruct

    test/
        SConscript
        test_bar_with_foo.c
    SConstruct

所以我有两个单独的 repos,都使用 scons。第一个 libfoo 可以独立克隆并使用 scons 构建。在 libfoo 根目录下运行 scons 时,它会在 src/中构建一个 libfoo 的静态库,并在 test/中构建一个与 src/中的静态库链接的单元测试可执行文件。

第二个 repo 有依赖于 libfoo 的 bar 应用程序。它也可以独立克隆,如果在构建系统上安装了 libfoo,则可以使用 scons 构建它。

我想要做的是设置一个新的 repo (project_root),它使用 mercurial 将 libfoo 和 bar app repos 设置为 subrepos。所以当你克隆这个新的 repo 时,它会自动拉下 bar 应用程序及其依赖项 libfoo。然后我希望能够在这个新仓库的根目录中运行 scons 并让它在 libfoo_subrepo/根目录中执行 scons 来构建 libfoo 和它的单元测试。然后我希望它在 barapp_subrepo/根目录中运行 scons 来构建 bar 并告诉它链接到 libfoo_subrepo/src/中的 libfoo 静态库。最后,我希望它在 tests/中构建一些新的单元测试,它们同时使用 libfoo 静态库和来自 bar app 的源文件,以便在组合在一起时测试 bar app 和 libfoo。

据我阅读 scons 文档可知,我需要为“subrepo”创建一个自定义构建器,该构建器将在子 shell 中运行 scons。然后我可以将 libfoo.subrepo 和 barapp.subrepo 添加到 project_root/目录以及如何安装它,以便当构建器执行构建 libfoo.subrepo 的命令时,它将源名称转换为它执行 scons 的路径.

building 'libfoo.subrepo' translates into executing 'cd libfoo_subrepo; scons'

在我看来 scons 不能递归地构建独立的 scons 项目。我读过的所有内容都假设您能够在子文件夹中创建 SConscript 文件,然后让根 SConstruct 文件依赖于 SConscript 文件。请告诉我有一种方法可以用 scons 做我想做的事。我不想回去做。

谢谢。

最佳答案

我不确定您为什么需要制作自定义构建器,如果我理解正确,我认为您需要的一切都可以使用 SCons 及其内置构建器完成。

要按照您的说明进行操作,您确实需要 3 个单独的 SConstruct 文件,才能进行 3 个单独的构建。我还将添加 3 个 SConscript 文件并将它们全部制作如下:

编辑:在本例中,最好在 SConstruct 脚本中创建 Environment()

project_root/SConstruct

# This SConstruct orchestrates building 3 subdirs

import os

subdirs = ['libfoo_subrepo', 'barapp_subrepo', 'test']
env = Environment()

for subdir in subdirs:
    SConscript(os.path.join(subdir, 'SConscript'), exports = ['env'])

libfoo_subrepo/SConstruct

# This SConstruct does nothing more than load the SConscript in this dir
# The Environment() is created in the SConstruct script
# This dir can be built standalone by executing scons here, or together
# by executing scons in the parent directory
env = Environment()
SConscript('SConscript', exports = ['env'])

libfoo_subrepo/SConscript

# This SConstruct orchestrates building 2 subdirs
import os

Import('env')
subdirs = ['src', 'test']

for subdir in subdirs:
    SConscript(os.path.join(subdir, 'SConscript'), exports = ['env'])

barapp_subrepo/SConstruct

# This SConstruct does nothing more than load the SConscript in this dir
# The Environment() is created in the SConstruct script
# This dir can be build standalone by executing scons here, or together
# by executing scons in the parent directory
env = Environment()
SConscript('SConscript', exports = ['env'])

barapp_subrepo/SConscript

# This SConstruct orchestrates building 2 subdirs
import os

Import('env')
subdirs = ['src', 'test']

for subdir in subdirs:
    SConscript(os.path.join(subdir, 'SConscript'), exports = ['env'])

我希望每个文件中的注释都能解释其用途。

希望这会有所帮助。

https://stackoverflow.com/questions/9950474/

相关文章:

javascript - 内联 require.js 文本!使用咕噜声

swift - Xcode 10 新构建系统清理问题

java - Gradle Application 插件的 Maven 替代(等效)

java - 在行中找不到可执行代码

msbuild - 为什么我的 .wpp.targets 文件没有应用到我的构建服务器上?

visual-studio - 如何更改 Visual Studio 中构建命令的默认行为

build - 是否有适用于多种语言的类似 Maven 的工具?

visual-studio-2010 - 极简 Qt 构建的推荐标志

java - 查看缓存 bazel 目标的编译警告

android - 有没有办法让 Android NDK-build 使用更新版本的 gcc?