欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > scons通用构建_生成方法Command

scons通用构建_生成方法Command

2025/11/28 6:08:35 来源:https://blog.csdn.net/u011326325/article/details/145160358  浏览:    关键词: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 -I zstd -cf $TARGET $SOURCES')# 生成md5
Command("file1.txt.md5", "file1.txt", 'md5sum $SOURCES > $TARGET')

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词