Below is the simple code snippet that illustrates the problem:
def external_dependencies(url, destination):
# this never gets called
print 'whatever!'
# if isinstance(url, basestring):
# urllib.urlretrieve(url, destination)
# else:
# for a, b in map(None, url, destination):
# urllib.urlretrieve(a, b)
return None
env = Environment()
env.Command(['http://archive.apache.org/dist/xmlgraphics/batik/batik-1.6.zip',
'http://archive.apache.org/dist/commons/collections/binaries/commons-collections-3.0.tar.gz',
'http://archive.apache.org/dist/commons/logging/binaries/commons-logging-1.0.4.tar.gz'],
['./thirdparty/batik/batik-1.6.zip',
'./thirdparty/commons-collections-3.0.tar.gz',
'./thirdparty/commons-logging-1.0.4.tar.gz'],
external_dependencies)
When I'm trying to execute this, I get the following error:
scons: *** [http:/archive.apache.org/dist/commons/collections/binaries/commons-
collections-3.0.tar.gz] Source `thirdparty/batik/batik-1.6.zip' not found,
needed by target `http:/archive.apache.org/dist/xmlgraphics/batik/batik-1.6.zip'.
(line breaks added for readability)
Obviously the destination cannot be found because it has not been downloaded yet, and the whole purpose of this operation is to download it.
How to override this behaviour? Validating arguments here is absolutely counter-productive.
EDIT:
A tiny update: I could get it to work in this way, but it feels wrong / hackish:
def external_dependencies(dummy, url, destination):
if isinstance(url, basestring):
urllib.urlretrieve(url, destination)
else:
for a, b in map(None, url, destination):
urllib.urlretrieve(a, b)
return None
env = Environment()
env.AddMethod(external_dependencies, 'ExternalDependencies')
env.ExternalDependencies(
['http://archive.apache.org/dist/xmlgraphics/batik/batik-1.6.zip',
'http://archive.apache.org/dist/commons/collections/binaries/commons-collections-3.0.tar.gz',
'http://archive.apache.org/dist/commons/logging/binaries/commons-logging-1.0.4.tar.gz'],
['./thirdparty/batik/batik-1.6.zip',
'./thirdparty/commons-collections-3.0.tar.gz',
'./thirdparty/commons-logging-1.0.4.tar.gz'])
Note the dummy
argument in the external_dependencies
- for some reason SCons will call this function passing the number of arguments as the first argument. So, it looks like the intended use was different.