0

下面是说明问题的简单代码片段:

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 将调用此函数,并将参数的数量作为第一个参数传递。因此,看起来预期用途有所不同。

4

1 回答 1

0

Command() 构建器的定义如下:

Command(target, source, action, [key=val, ...])

因此,您似乎错误地订购了参数。我假设 URL 列表是源,文件列表是目标,对吧?

如果是这种情况,您可以重新排序 args,或者只执行以下操作:

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 列表实际上是一个文件名列表,并且它可能会尝试找到它们,你必须对其进行测试。

您尝试的第二个选项实际上不是构建器,而只是一个函数调用,因此依赖项检查可能不会像您期望的那样。至于您提到的虚拟参数,我很确定那将是调用该函数的环境,而不是参数的数量。

于 2012-08-31T15:15:09.363 回答