当前位置: 首页 > 工具软件 > Blade > 使用案例 >

Debian/Ubuntu--blade安装与使用

龙昊焱
2023-12-01

blade是腾讯推出的一个构建工具。本来感觉很新奇,后来发现了:Bazel,才发现blade原来是学Bazel的,很多方面都很像。

仓库地址:chen3feng/blade-build: A powerful build system from Tencent, support many mainstream programming languages, such as C/C++, java, scala, python, protobuf…

先自己安装python2或者python3,然后安装scons

sv=3.1.0
wget http://prdownloads.sourceforge.net/scons/scons-$sv.tar.gz
tar -xf scons-$sv.tar.gz
sudo python3 scons-$sv/setup.py install

然后进行安装:

git clone https://github.com/chen3feng/blade-build.git
cd blade-build
./install 
-> # ls -l `which blade`
lrwxrwxrwx 1 root root 36 Jul 23 22:40 /root/bin/blade -> /home/zhang/blade-build-master/blade

Blade要求项目源代码有一个明确的根目录,C++ 中的 #include 的路径也需要从这个目录开始写起,这个目录成为工作空间

Blade并不从某个配置文件或者环境变量读取这个信息,因为开发人员往往需要同时有多个工作空间并存。 Blade获取当前工作空间的方法是,无论当前从哪一级子目录运行,都从当前目录开始向上查找BLADE_ROOT文件,有这个文件的目录即为工作空间。

测试:

mkdir test && cd test
touch BLADE_ROOT #建空文件
touch BUILD hello.cpp

BUILD内容如下:

cc_binary(
   name = 'hello_test',
   srcs = [
     'hello.cpp'
   ]
 )

hello.cpp内容如下:

#include <iostream>
//using namespace std;
int main() {
 std::cout << "Hello World" << std::endl;
}

然后编译:

blade build .

会报错:

scons: Reading SConscript files ...
Blade(warning): Failed to get version control info in proj
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build64_release
cc1plus: error: thirdparty: No such file or directory [-Werror=missing-include-dirs]
cc1plus: some warnings being treated as errors
scons: *** [build64_release/proj/hello_test.objs/hello.cpp.o] Error 1
scons: building terminated because of errors.
Blade(error): building failure.
Blade(error): failure

这是因为GitHub仓库中默认的配置是存在问题的,修改文件blade.conf

cd blade-build
nano blade.conf

把第二行用#号注释了:

#    extra_incs='thirdparty',

然后编译就可以了:

-> # blade build .    
Blade: Entering directory `/root/test'
Blade(info): loading config file "/root/blade-build/blade.conf"
Blade(info): loading config file "/root/test/BLADE_ROOT"
Blade(info): loading BUILDs...
Blade(info): loading done.
Blade(info): analyzing dependency graph...
Blade(info): analyzing done.
Blade(info): generating build rules...
Blade(warning): Unsupported C/C++ flags: -Werror=format-nonliteral
Blade(info): generating done.
Blade(info): building...
Blade(info): tunes the parallel jobs number(-j N) to be 2
scons: Reading SConscript files ...
Blade(warning): Failed to get version control info in .
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build64_release
scons: done building targets.se/hello_test
Blade(info): building done.
Blade(info): cost time 3s

可以运行了:

-> # cd build64_release 
-> # ./hello_test
Hello World

更多内容参考:浅谈blade中C++Build的设计与实现 | 云烟记事录

 类似资料: