使用 scons 执行验证
我的公司正在从 make 转向 scons。我们的 make 过程的一部分是对许多 xml 文件调用 xmllint,以根据模式验证它们。
我的 SConstruct 中有以下内容:
import os;
Env = DefaultEnvironment()
pwd = Dir('.').path
xmlValidator = Builder(action = 'xmllint --noout --schema '+pwd+'/path/schema.xsd '+pwd+'file.xml')
Env.Append(BUILDERS = {'ValidateXML' : xmlValidator})
Env.ValidateXML()
当我运行时:
scons -Q
我得到:
scons: `.' is up to date.
但没有运行验证。
我做错了什么?
我对 scons 完全陌生,对 Python 还算熟悉。
My company is switching from make to scons. Part of our make process is to call xmllint on a number of xml files to validate them against a schema.
I've got the following in my SConstruct:
import os;
Env = DefaultEnvironment()
pwd = Dir('.').path
xmlValidator = Builder(action = 'xmllint --noout --schema '+pwd+'/path/schema.xsd '+pwd+'file.xml')
Env.Append(BUILDERS = {'ValidateXML' : xmlValidator})
Env.ValidateXML()
When I run:
scons -Q
I get:
scons: `.' is up to date.
But no validation is run.
What am I doing wrong?
I'm completely new to scons, and moderately familiar with Python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要向 scons 提供输入文件。您当前已将源文件硬编码到构建器“配方”中。最好在操作字符串中使用 SOURCE 占位符,然后在调用构建器时指定输入文件。
这将始终运行验证,因此您可能希望将其结果输出到文件中。为此,您可以使用 TARGET 占位符,例如:
You need to provide scons with an input file. You currently have the source file hard-coded into the builder "recipe". It is better to use the SOURCE placeholder in the action string and then specify the input file when you call the builder.
This will always run the validation, so you might want to have it output the result to a file. To do that you would use the TARGET placeholder, for example:
您可能还使用 XML 文件作为其他构建器的输入。通过使用具有多个操作的构建器,您可以在该阶段执行验证。像这样:
使用此解决方案,无需创建任何不必要的文件。如果生成了 XML 文件,您可以类似地创建一个生成器来生成文件并执行验证。
Presumably you also use the XML files as input to some other builder. By using a builder with multiple actions you could perform the validation at that stage instead. Something like this:
With this solution there is no need to create any unnecessary files. If the XML files are generated you could similarly create a builder that both generates the file and perform the validation.