我公司从make切换到scons的。我们的化妆过程中有一部分是调用xmllint在多个XML文件以验证它们针对某个架构。

我有我的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。

有帮助吗?

解决方案

您需要提供与scons的输入文件。您目前拥有的源文件的硬编码到建设者的“秘方”。这是更好地使用源占位符的操作字符串,然后指定输入文件,当调用生成器。

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")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top