scons通用构建_生成方法Command

1.需求

同makefile一样,自动构建

  1. QT designer设计的UI文件, 通过pyuic5 将 xxx.ui 转 为 xxx.py
  2. proto序列化文件, 通过 protoc 将 xxx.proto 命令转化为 xxx.py文件
  3. 压缩归档 : tar -zcf archive.tar.gz file1.txt file2.txt file3.txt
  4. 生成/更新 md5值: md5sum xxx.txt > xxx.txt.md5

并实现

  1. 当文件未更新时, 不重新编译/生成
  2. 当文件更新时, 重新编译/生成

2.功能实现

1.QT designer的ui文件转化为.py文件

gitee 在线代码:

SConstruct

# qt designer 自定义构建命令
Command('score.py', 'score.ui', 'pyuic5 -x -o $TARGET $SOURCES')

scons 编译/生成
scons: Reading SConscript files …
scons: done reading SConscript files.
scons: Building targets …
pyuic5 -x -o score.py score.ui
scons: done building targets.

2.proto序列化文件protoc编译为.py文件

gitee 在线代码

example.proto

syntax = "proto3";

package example;

message Person {
  string name = 1;
  int32 id = 2;
  string email = 3;
}

SConstruct

Command("example_pb2.py", "example.proto", action="protoc --python_out=. $SOURCE")

scons 编译/生成
scons: Reading SConscript files …
scons: done reading SConscript files.
scons: Building targets …
protoc --python_out=. example.proto
scons: done building targets.
ls
example_pb2.py example.proto

3. 压缩归档

4. 生成md5文件

gitee 在线代码

# 压缩文件
sources = ['file1.txt', 'file2.txt', 'file3.txt']
tarball = 'archive.tar.gz'
Command(tarball, sources, 'tar -zcf $TARGET $SOURCES')

# 生成md5
Command("file1.txt.md5", "file1.txt", 'md5sum $SOURCES > $TARGET')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值