我的公司正在从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。
答案 0 :(得分:2)
您需要为scons提供输入文件。您当前将源文件硬编码到构建器“recipe”中。最好在操作字符串中使用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")
答案 1 :(得分:0)
大概您也将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文件,则可以类似地创建一个生成器,该生成器既生成文件又执行验证。