如何从预制构建脚本运行自定义工具?
我在 C++ 应用程序中使用协议缓冲区进行数据序列化。我想在我的 premake 构建脚本中添加对 protoc
代码生成器的调用(从而确保生成的类的最新状态并避免需要在版本控制下存储生成的源)。
甚至他们的 FAQ 也有关于此的问题和答案,但答案对我来说非常不完整。能够调用任何 lua 函数固然很棒,但是我到底该把调用放在哪里呢?我需要在构建应用程序或单元测试之前运行协议编译器。
I'm using protocol buffers for data serialization in my C++ application. I would like to add the invokation of the protoc
code generator in my premake build script (thus ensure the up-to-date state of the generated classes and avoid the need to store generated source under version control).
Even their FAQ has a question and answer about this, but the answer is very incomplete for me. Having the ability to call any lua function is great, but where exactly do I put that call? I need to run the protoc compiler before building either the application or the unit tests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您当然可以从 Premake 脚本调用外部代码。但请记住:Premake 脚本用于生成构建文件:Makefile、C++ 项目等。Premake 脚本在构建项目之前运行。
如果您希望此预处理在实际构建文件之外运行(而不是通过 make、VC++、Code::Blocks 等),那么这很简单。 Lua 的 os.execute 将会执行命令行。
Premake 脚本仍然是 Lua 脚本。所有 Premake 命令只是 Lua 调用 Premake 定义的函数。 Premake 执行脚本,然后使用其中的数据生成构建文件。因此,所有 Lua 代码都会在脚本执行期间运行。将此命令放在脚本中的位置无关紧要;无论它在哪里,它都会在生成构建文件之前执行。
You can certainly call outside code from Premake scripts. But remember: Premake scripts are used to generate build files: Makefiles, C++ projects, etc. The Premake script is run before building the project.
If you want this preprocess to be run outside of the actual build files (and not by make, VC++, Code::Blocks, etc), then it's easy. Lua's
os.execute
will execute a command-line.Premake scripts are still Lua scripts. All of the Premake commands are just Lua calls into functions that Premake defines. Premake executes the scripts, then uses the data from them to generate the build files. So all of your Lua code is run during the execution of the script. Where you put this command in your script is irrelevant; wherever it is, it will execute before your build files are generated.
如果您想在构建过程中运行 protoc 步骤(通过 VC++、makefile 等),您可以设置预构建命令。有关详细信息和示例,请参阅 http://industriousone.com/prebuildcommands。
And if you want to run the protoc step during the build (from VC++, makefile, etc.) you can set up a prebuild command. See http://industriousone.com/prebuildcommands for more info and an example.