告诉 SCons 不要自动创建目录? [英] Tell SCons not to auto-create directories?

查看:29
本文介绍了告诉 SCons 不要自动创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

例如,假设我想克隆 GStreamer,并使用 create-uninstalled-setup.sh 脚本(这不是我实际要做的,但它更简单/更快出现相同问题的脚本):

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

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

<块引用>

$ scons
scons:读取 SConscript 文件 ...
scons:完成读取 SConscript 文件.
scons:构建目标...
git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer
致命:目标路径gstreamer"已存在且不是空目录.
scons: *** [gstreamer/.git] 错误 128
scons:建筑物因错误而终止.
$ ls gstreamer/
脚本

如果我告诉第一个命令它创建了gstreamer"文件夹,它会创建一个依赖循环:

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

<块引用>

$ scons
scons:读取 SConscript 文件 ...
scons:完成读取 SConscript 文件.
scons:构建目标...
scons:完成构建目标.

scons: *** 找到依赖循环:
gstreamer/scripts -> gstreamer/scripts/create-uninstalled-setup.sh -> gstreamer/scripts
gstreamer/scripts/create-uninstalled-setup.sh -> gstreamer/scripts -> gstreamer/scripts>/create-uninstalled-setup.sh

文件/usr/lib/scons/SCons/Taskmaster.py",第 1019 行,清理中

如果我不告诉第一个命令它创建了create-uninstalled-setup.sh",它会因为它不存在而感到困惑:

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

<块引用>

$ scons
scons:读取 SConscript 文件 ...
scons:完成读取 SConscript 文件.
scons:构建目标...
scons: *** [~/gst/git] 未找到源 `gstreamer/scripts/create-uninstalled-setup.sh',目标 `~/gst/git' 需要.
scons:构建因错误而终止.

作为一种解决方法,我可以在克隆之前 rm -rf 文件夹,但这显然不理想:

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

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

解决方案

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

import os.pathsetup_file = 'gstreamer/scripts/create-uninstalled-setup.sh'如果不是 os.path.exists(setup_file)执行('git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer')命令('~/gst/git', setup_file, setup_file)

I'm trying to make SCons check out a git repo that I need (and hopefully keep that repo up-to-date). The problem is that I have to tell it which files the git repo contains for it to use them in the build, and if I do that, SCons will create the repo before it tries to clone it.

For example, say I want to clone GStreamer, and use the create-uninstalled-setup.sh script (this isn't what I'm actually doing, but it's a much simpler/faster script that exibits the same problem):

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')

But it fails because SCons creates gstreamer/scripts before it tries to clone 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

If I tell the first command that it creates the "gstreamer" folder, it creates a dependency cycle:

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

If I don't tell the first command that it creates "create-uninstalled-setup.sh", it gets confused because it doesn't exist:

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.

As a workaround, I can rm -rf the folder before I clone, but that's obviously not ideal:

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')

Is there a better way of handling this?

解决方案

Since there is no way to tell git that the dir is indeed empty (even though it has empty subdirs), and we cant figure out how to tell SCons not to auto-create the subdirs, you could create your own dependency check and call git clone with the SCons Execute() function, which is executed before any SCons builtin dependency checking is performed, as follows:

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 不要自动创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆