gpt4 book ai didi

scons - 告诉 SCons 不要自动创建目录?

转载 作者:行者123 更新时间:2023-12-03 10:02:57 26 4
gpt4 key购买 nike

我正在尝试让 SCons 检查我需要的 git 存储库(并希望使该存储库保持最新状态)。问题是我必须告诉它 git repo 包含哪些文件才能在构建中使用它们,如果我这样做,SCons 将在尝试克隆它之前创建该 repo。

例如,假设我想克隆 GStreamer,并使用 create-uninstalled-setup.sh脚本(这不是我真正在做的,但它是一个更简单/更快的脚本,它存在同样的问题):

Command(['gstreamer/.git', 'gstreamer/scripts/create-uninstalled-setup.sh'],
None, 'git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')
Command('~/gst/git', 'gstreamer/scripts/create-uninstalled-setup.sh',
'gstreamer/scripts/create-uninstalled-setup.sh')

但它失败了,因为 SCons 在尝试克隆 gstreamer 之前创建了 gstreamer/脚本:

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer
fatal: destination path 'gstreamer' already exists and is not an empty directory.
scons: *** [gstreamer/.git] Error 128
scons: building terminated because of errors.
$ ls gstreamer/
scripts



如果我告诉第一个命令它创建了“gstreamer”文件夹,它会创建一个依赖循环:
Command(['gstreamer', 'gstreamer/scripts/create-uninstalled-setup.sh'],
None, 'git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')
Command('~/gst/git', 'gstreamer/scripts/create-uninstalled-setup.sh',
'gstreamer/scripts/create-uninstalled-setup.sh')

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: done building targets.

scons: *** Found dependency cycle(s):
gstreamer/scripts -> gstreamer/scripts/create-uninstalled-setup.sh -> gstreamer/scripts
gstreamer/scripts/create-uninstalled-setup.sh -> gstreamer/scripts -> gstreamer/scripts> /create-uninstalled-setup.sh

File "/usr/lib/scons/SCons/Taskmaster.py", line 1019, in cleanup



如果我不告诉第一个命令它创建“create-uninstalled-setup.sh”,它会因为它不存在而感到困惑:
Command(['gstreamer'],
None, 'git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')
Command('~/gst/git', 'gstreamer/scripts/create-uninstalled-setup.sh',
'gstreamer/scripts/create-uninstalled-setup.sh')

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: *** [~/gst/git] Source `gstreamer/scripts/create-uninstalled-setup.sh' not found, needed by target `~/gst/git'.
scons: building terminated because of errors.



作为解决方法,我可以 rm -rf我克隆之前的文件夹,但这显然不理想:
Command(['gstreamer/.git', 'gstreamer/scripts/create-uninstalled-setup.sh'], None,
'rm -rf gstreamer && git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')
Command('~/gst/git', 'gstreamer/scripts/create-uninstalled-setup.sh',
'gstreamer/scripts/create-uninstalled-setup.sh')

有没有更好的方法来处理这个问题?

最佳答案

既然没办法告诉git目录确实是空的(即使它有空的子目录),我们不知道如何告诉 SCons不要自动创建子目录,您可以创建自己的依赖项检查并调用 git cloneSCons Execute()函数,在任何 SCons 之前执行执行内置依赖项检查,如下所示:

import os.path

setup_file = 'gstreamer/scripts/create-uninstalled-setup.sh'
if not os.path.exists(setup_file)
Execute('git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')

Command('~/gst/git', setup_file, setup_file)

关于scons - 告诉 SCons 不要自动创建目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18025187/

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