gpt4 book ai didi

SCons:依赖循环?

转载 作者:行者123 更新时间:2023-12-04 15:14:58 27 4
gpt4 key购买 nike

我试图让 SCons 将 Makefile 项目从源目录复制到构建目录并运行一些命令来生成 libmoo.a,但我遇到了依赖循环错误。详情如下:

./S构造:

env = Environment()
Export('env')

dirs = ['.']

variant_dir = 'build'

for dir in dirs:
SConscript(dir + '/' + 'SConscript', variant_dir=variant_dir + '/' + dir, duplicate=0)

./SConscript:
import os
Import('env')

env.Command(env.Dir('moo2').abspath, env.Dir('#moo').abspath, ["echo copying moo to the build dir", Copy("$TARGET", "$SOURCE")])

env.Command(env.Dir('moo2/Makefile').abspath, env.Dir('moo2').abspath, 'echo would run moo2.configure')

moolib = env.Command(env.Dir('moo2/libmoo.a').abspath, env.Dir('moo2/Makefile').abspath, 'echo would run make')

Default(moolib)

运行 scons 时出错:
scons: *** Found dependency cycle(s):
build/moo2/Makefile -> build/moo2 -> build/moo2/Makefile
build/moo2/libmoo.a -> build/moo2 -> build/moo2/Makefile -> build/moo2/libmoo.a

也试过不使用 .abspath,但这应该没关系,对吧?

我没有看到任何循环:
  • build/moo2/libmoo.a 需要 build/moo2/Makefile
  • build/moo2/Makefile 需要 build/moo2
  • build/moo2 需要 (source/)moo

  • scons 如何看待循环?似乎认为build/moo2/Makefile依赖于build/moo2/libmoo.a,这不是我想指定的。

    也欢迎任何相关建议:-)

    最佳答案

    SConscript 中的任何地方都不需要 env.Dir('moo').abspath。所以这会将其更改为:

    Import('env')
    env.Command('moo2', '#moo', ["echo copying moo to the build dir", Copy("$TARGET", "$SOURCE")])
    env.Command('moo2/Makefile', 'moo2', 'echo would run moo2.configure') # Look Here
    moolib = env.Command('moo2/libmoo.a', 'moo2/Makefile', 'echo would run make')
    Default(moolib)

    但这仍然会产生相同的错误:
    scons: *** Found dependency cycle(s):
    build/moo2/Makefile -> build/moo2 -> build/moo2/Makefile
    build/moo2/libmoo.a -> build/moo2/Makefile -> build/moo2/libmoo.a

    那是为什么?
    SCons 自动使目录依赖于其中包含的所有文件。
    请参阅带有“# Look Here”注释的行。您已经添加了依赖项 moo2/Makefile 现在依赖于 moo2。默认情况下,moo2 取决于它的所有内容,因此取决于您的周期。

    那么我们该如何修复呢?
    Import('env')
    env.Install('moo2',Glob('#moo/*'))
    env.Command('moo2/Makefile', env.Glob('moo2/*'), 'echo would run moo2.configure')
    moolib = env.Command('moo2/libmoo.a', 'moo2/Makefile', 'echo would run make')
    Default(moolib)

    我已经从使用 Copy() 更改为 env.Install()。由于 Copy 未附加到构建 Environment() 对象,因此它不会知道变体目录。 Install() 和 Copy() 在功能上是等效的, env.Install() 是 env 感知的。
    另外我有它复制/依赖于目录中的所有文件,而不是目录本身。

    现在让我们试一试:
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python /Users/bdbaddog/devel/scons/trunk/bootstrap/src/script/scons.py --tree=prune
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    Install file: "moo/abc.c" as "build/moo2/abc.c"
    Install file: "moo/configure" as "build/moo2/configure"
    Install file: "moo/def.c" as "build/moo2/def.c"
    echo would run moo2.configure
    would run moo2.configure
    echo would run make
    would run make
    +-build/moo2/libmoo.a
    +-build/moo2/Makefile
    | +-build/moo2/abc.c
    | | +-moo/abc.c
    | +-build/moo2/configure
    | | +-moo/configure
    | +-build/moo2/def.c
    | | +-moo/def.c
    | +-/bin/echo
    +-/bin/echo
    scons: done building targets.

    注意“--tree=prune”这个标志会让 SCons 打印出依赖树并修剪树中的重复(所以如果 2 个文件依赖于同一个文件树,你只会看到一次)

    关于SCons:依赖循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391126/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com