使用 scons 执行验证

发布于 2024-08-13 04:29:26 字数 548 浏览 4 评论 0原文

我的公司正在从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞慾 2024-08-20 04:29:26

您需要向 scons 提供输入文件。您当前已将源文件硬编码到构建器“配方”中。最好在操作字符串中使用 SOURCE 占位符,然后在调用构建器时指定输入文件。

xmlValidator = Builder(action='xmllint --noout --schema '+
                               pwd+'/path/schema.xsd $SOURCE')
Env.Append(BUILDERS = {'ValidateXML' : xmlValidator})
Env.ValidateXML(source='file.xml')

这将始终运行验证,因此您可能希望将其结果输出到文件中。为此,您可以使用 TARGET 占位符,例如:

xmlValidator = Builder(action='xmllint --schema '+
                       pwd+'/path/schema.xsd $SOURCE --output $TARGET')
Env.ValidateXML(source='file.xml', target="out.txt")

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.

xmlValidator = Builder(action='xmllint --noout --schema '+
                               pwd+'/path/schema.xsd $SOURCE')
Env.Append(BUILDERS = {'ValidateXML' : xmlValidator})
Env.ValidateXML(source='file.xml')

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:

xmlValidator = Builder(action='xmllint --schema '+
                       pwd+'/path/schema.xsd $SOURCE --output $TARGET')
Env.ValidateXML(source='file.xml', target="out.txt")
小…楫夜泊 2024-08-20 04:29:26

您可能还使用 XML 文件作为其他构建器的输入。通过使用具有多个操作的构建器,您可以在该阶段执行验证。像这样:

xslt = Builder(action=['xmllint --noout --schema /path/to/schema.xsd $SOURCE',
                       'xsltproc --output $TARGET /path/to/style.xsl $SOURCE'])
Env.Append(BUILDERS = {'XSLT' : xslt})

使用此解决方案,无需创建任何不必要的文件。如果生成了 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:

xslt = Builder(action=['xmllint --noout --schema /path/to/schema.xsd $SOURCE',
                       'xsltproc --output $TARGET /path/to/style.xsl $SOURCE'])
Env.Append(BUILDERS = {'XSLT' : xslt})

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文