tags:

views:

66

answers:

1

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.

+2  A: 

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")
rq
Thanks so much. This worked perfectly except the --noout switch has to be dropped when using the --output switch in the second example.
Robert Gowland
OK, good to know. I've edited the example so it makes sense, just in case.
rq