代码之家  ›  专栏  ›  技术社区  ›  Marcelo Cantos

pythondistutils在不同的机器上构建不同的扩展

  •  1
  • Marcelo Cantos  · 技术社区  · 15 年前

    python setup.py build 将很高兴地检测更改的文件,只构建这些文件,并将整个内容链接在一起,就像make一样。但是,在另一台机器上,对任何文件的一次更改都会触发对所有源代码的重新编译。

    我只是想说清楚。这两台机器都能检测到包何时是最新的,不会做任何事情。只有当单个文件发生更改时,它们的行为才会发生分歧。

    为什么第二台机器要这样做?

    计算机1(执行正确的每个文件依赖项检查和生成。)

    Python 2.6.4 (r264:75706, Feb 15 2010, 17:06:03) 
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    
    setuptools-0.6c11-py2.6
    
    LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
    Distributor ID: CentOS
    Description: CentOS release 5.4 (Final)
    Release: 5.4
    Codename: Final
    

    Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    
    setuptools-0.6c11-py2.6
    
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 10.04 LTS
    Release: 10.04
    Codename: lucid
    
    2 回复  |  直到 15 年前
        1
  •  2
  •   merwok    13 年前

    我查看了Mercurial回购,发现了以下变化:

    Issue #5372 :删除Distutils的ccompiler中.o文件的重用(因为Extension extra选项可能会更改输出而不更改.c文件)。

        2
  •  1
  •   Marcelo Cantos    15 年前

    我追踪到了Python2.6.4和Python2.6.5之间的差异。中的两种方法 distutils.ccompiler.CCompiler _setup_compile _prep_compile ,删除了相同的代码块:

    if self.force:
        skip_source = {}            # rebuild everything
        for source in sources:
            skip_source[source] = 0
    elif depends is None:
        # If depends is None, figure out which source files we
        # have to recompile according to a simplistic check. We
        # just compare the source and object file, no deep
        # dependency checking involving header files.
        skip_source = {}            # rebuild everything
        for source in sources:      # no wait, rebuild nothing
            skip_source[source] = 1
    
        n_sources, n_objects = newer_pairwise(sources, objects)
        for source in n_sources:    # no really, only rebuild what's
            skip_source[source] = 0 # out-of-date
    else:
        # If depends is a list of files, then do a different
        # simplistic check.  Assume that each object depends on
        # its source and all files in the depends list.
        skip_source = {}
        # L contains all the depends plus a spot at the end for a
        # particular source file
        L = depends[:] + [None]
        for i in range(len(objects)):
            source = sources[i]
            L[-1] = source
            if newer_group(L, objects[i]):
                skip_source[source] = 0
            else:
                skip_source[source] = 1
    

    这段代码将每个源文件与其目标对象进行检查,如果源文件早于目标对象,则将其标记为跳过。我不知道为什么它被删除,但它解释了差异。当我把它作为一个测试放回去时,编译器会恢复到每源依赖性分析。