scons通用构建_生成方法Command

发布于:2025-02-10 ⋅ 阅读:(68) ⋅ 点赞:(0)

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


网站公告

今日签到

点亮在社区的每一天
去签到