基于Python的C++构建元生成系统。
SBuildr的Python项目详细描述
sbuilder-愚蠢的构建器
一个愚蠢的、简单的基于Python的C++构建元生成系统。
安装
先决条件
从pypi安装
pip install sbuildr
从源安装
- 克隆sbuildersource repository。
- 使用
python setup.py install
在本地安装
一个小例子
对于本例,我们将假定以下目录结构:
minimal_project
├── build.py
├── include
│ └── math.hpp
├── src
│ ├── factorial.cpp
│ ├── factorial.hpp
│ ├── fibonacci.cpp
│ ├── fibonacci.hpp
│ └── utils.hpp
└── tests
└── test.cpp
相应的build.py
文件可能如下所示:
#!/usr/bin/env pythonimportsbuildrimportosproject=sbuildr.Project()# Build a library using two source files. Note that headers do not have to be specified manually.# Full file paths are only required in cases where a partial path would be ambiguous.libmath=project.library("math",sources=["factorial.cpp","fibonacci.cpp"],libs=["stdc++"])# Specify that math.hpp is part of the public API for this library.project.interfaces(["math.hpp"])# Specify a test for the project using the test.cpp source file. The resulting executable will# be linked against the library created above.test=project.test("test",sources=["test.cpp"],libs=["stdc++",libmath])# Enable this script to be used interactively on the command-linesbuildr.cli(project)
对cli()
函数的调用允许我们使用脚本在shell中交互构建。
例如,要运行为此项目注册的所有测试,可以运行:./build.py test
。这将配置项目,构建所有依赖项,并最终运行测试。
要查看所有可用的命令,可以运行./build.py --help
API文档
有关详细信息,请参见API Documentation
已知限制
- sbuilder的头扫描功能不考虑预处理器
#ifdef
s。这意味着在生成期间,false
分支中的#include
仍将用作依赖项。对于包含转义字符的路径,头扫描也将不起作用。