真正的分层与SCons的构建? [英] Real Hierarchical Builds with SCons?

查看:324
本文介绍了真正的分层与SCons的构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我读过关于这里的问题关于建立分层,如:创建分层与SCons的建立

我想要做两独立式回购实际分层结构的,我设置为使用水银次回购都使用scons的。下面是该文件的布局,说明了什么我想要做的。

所需的布局:

  project_root /(新项目,建立使用从源代码构建安装libfoo栏应用程序)    libfoo_subrepo /(从到位桶单独的项目回购)
        SRC /
            SConscript
            libfoo.c
            libfoo.h
        测试/
            SConscript
            test_foo.c
        SConstruct    barapp_subrepo /(独立项目从到位桶使用libfoo的回购)
        SRC /
            SConscript
            bar.c
            bar.h
        测试/
            SConscript
            test_bar.c
        SConstruct    测试/
        SConscript
        test_bar_with_foo.c
    SConstruct

所以,我有两个单独的回购协议,无论使用scons的。第一个,libfoo时,可以克隆独立并使用scons的构建。当在libfoo的根目录中运行scons的,它建立在SRC libfoo的静态库/并建立测试单元测试的可执行文件/在SRC /.

第二个回购有酒吧的应用程序依赖于libfoo的。它也可以被克隆独立的,如果已经安装了libfoo构建系统上,它可以使用scons的构建。

我想要做的,设置有两个libfoo的,并设置为使用水银subrepos栏应用回购了新的回购协议(project_root)。所以,当你克隆新的回购协议,它会自动向下拉栏的应用程序和它的依赖,libfoo的。然后,我希望能够在这个新的回购协议的根目录运行scons的,让它在libfoo_subrepo /根执行scons的建设libfoo的,它的单元测试。然后,我希望它在barapp_subrepo / root身份运行scons的建设酒吧,告诉它针对libfoo_subrepo / src目录/安装libfoo静态库链接。最后,我想它建立在​​测试一些新的单元测试/使用两个libfoo的静态库和源文件从酒吧应用测试棒的应用程序和libfoo的时候结合在一起。

据我可以告诉从阅读scons的文档,我需要创建subrepo,将在子shell中运行scons的自定义生成器。然后,我可以添加libfoo.subrepo和barapp.subrepo到project_root /目录和一些如何操纵它,这样当建设者去执行命令建立libfoo.subrepo它转换的信号源名称到它在执行scons的路径

 建设libfoo.subrepo'转化为执行CD libfoo_subrepo; scons的

在我看来就像scons的不能循环建立独立scons的项目。我读过的一切假设您必须创建在子文件夹SConscript文件,然后有根SConstruct文件取决于SConscript文件的能力。请告诉我有一种方法做什么,我想与scons的。我不想回去做。

感谢。


解决方案

林不知道你为什么会需要进行自定义生成器,如果我理解正确,我认为你需要的一切可以用SCons的其内置的建设者完成

要你解释什么,你的确需要3单独SConsctruct文件,要能够做到3独立的基础之上。我还要补充3 SConscript文件,使所有的人如下:

编辑:在这个例子中,它能够更好地在SConstruct脚本创建环境()

project_root / SConstruct

 #这SConstruct编排建设3子目录进口OS子目录= ['libfoo_subrepo','barapp_subrepo','测试']
ENV =环境()在子目录子目录:
    SConscript(os.path.join(子目录,SConscript'),出口= ['ENV'])

libfoo_subrepo / SConstruct

 #这SConstruct确实没有什么比加载SConscript在这个DIR更多
#该环境()在SConstruct脚本创建
#这个目录可以通过执行scons的建成独立这里,或一起
#由父目录执行scons的
ENV =环境()
SConscript('SConscript',出口= ['ENV'])

libfoo_subrepo / SConscript

 #这SConstruct编排建设2子目录
进口OS导入(ENV)
子目录= ['src'中,'测试']在子目录子目录:
    SConscript(os.path.join(子目录,SConscript'),出口= ['ENV'])

barapp_subrepo / SConstruct

 #这SConstruct确实没有什么比加载SConscript在这个DIR更多
#该环境()在SConstruct脚本创建
#这个目录可以在这里执行scons的建设进行独立,或一起
#由父目录执行scons的
ENV =环境()
SConscript('SConscript',出口= ['ENV'])

barapp_subrepo / SConscript

 #这SConstruct编排建设2子目录
进口OS导入(ENV)
子目录= ['src'中,'测试']在子目录子目录:
    SConscript(os.path.join(子目录,SConscript'),出口= ['ENV'])

我希望评论中的每个文件解释其目的。

希望这有助于。

So I've read the questions on here about hierarchical builds like: Creating a Hierarchical Build with SCons

I want to do real hierarchical construction of two standalone repos that both use scons that I set up as sub-repos using mercurial. Below is the file layout that illustrates what I want to do.

Desired Layout:

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

So I have two separate repos, both using scons. The first one, libfoo, can be cloned standalone and built using scons. When running scons in the libfoo root directory, it builds a static library of libfoo in src/ and builds a unit test executable in test/ that links against the static library in src/.

The second repo has the bar app that depends on libfoo. It too can be cloned standalone and if libfoo is installed on the build system, it can be built using scons.

What I want to do, is set up a new repo (project_root) that has both the libfoo and bar app repos set as subrepos using mercurial. So when you clone this new repo, it automatically pulls down bar app and it's dependency, libfoo. Then I want to be able to run scons in the root of this new repo and have it execute scons in the libfoo_subrepo/ root to build libfoo and it's unit tests. Then I want it to run scons in the barapp_subrepo/ root to build bar and tell it to link against the libfoo static library in libfoo_subrepo/src/. Lastly, I want it to build some new unit tests in tests/ that use both the libfoo static library and the source files from bar app to test bar app and libfoo when combined together.

As far as I can tell from reading the scons documentation is that I would need to create a custom Builder for "subrepo" that would run scons in a sub-shell. Then I could add libfoo.subrepo and barapp.subrepo to the project_root/ directory and some how rig it so that when the builder goes to execute the command to build libfoo.subrepo that it translates the source name into a path that it executes scons in.

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

It looks to me like scons cannot recursively build standalone scons projects. Everything I've read assumes you have the ability to create SConscript files in the subfolders and then have the root SConstruct file depend on the SConscript files. Please tell me there is a way to do what I want with scons. I don't want to go back to make.

Thanks.

解决方案

Im not sure why you would need to make a custom builder, if I understand you correctly, I think everything you need can be done with SCons and its builtin builders.

To do what you explain, you would indeed need 3 Seperate SConsctruct files, to be able to do 3 seperate builds. I would also add 3 SConscript files and make all of them as follows:

Edit: In this example, its better to create the Environment() in the SConstruct scripts

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'])

I hope the comments in each file explains its purpose.

Hope this helps.

这篇关于真正的分层与SCons的构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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