下面是说明问题的简单代码片段:
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)
当我尝试执行此操作时,出现以下错误:
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'.
(为便于阅读添加了换行符)
显然找不到目的地,因为它还没有下载,而这个操作的全部目的就是下载它。
如何覆盖这种行为?在这里验证论点绝对适得其反。
编辑:
一个小小的更新:我可以让它以这种方式工作,但感觉不对 / 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'])
请注意 - 中的dummy
参数,external_dependencies
出于某种原因,SCons 将调用此函数,并将参数的数量作为第一个参数传递。因此,看起来预期用途有所不同。