以下是说明问题的简单代码段:
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'.
(为了便于阅读而添加了换行符)
显然找不到目的地,因为它尚未下载,此操作的全部目的是下载它。
如何覆盖此行为?在这里验证参数绝对适得其反。
修改
一个小小的更新:我可以通过这种方式让它工作,但感觉不对/黑客:
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将调用此函数作为第一个参数传递参数的数量。因此,看起来预期用途不同。
答案 0 :(得分:0)
Command()构建器的定义如下:
Command(target, source, action, [key=val, ...])
因此您似乎错误地订购了参数。我假设URL列表是源,文件列表是目标,对吗?
如果是这种情况,您可以重新排序参数,或者只是执行以下操作:
Command(source=['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'],
target=['./thirdparty/batik/batik-1.6.zip',
'./thirdparty/commons-collections-3.0.tar.gz',
'./thirdparty/commons-logging-1.0.4.tar.gz'],
action=external_dependencies)
我仍然不相信这会起作用,因为SCons可能会认为url列表实际上是一个文件名列表,它可能会尝试找到它们,你必须测试它。
您尝试的第二个选项实际上不是构建器,而只是一个函数调用,因此依赖项检查可能不会像您期望的那样。至于你提到的虚拟参数,我很确定这将是调用该函数的env,而不是args的数量。