Scons。使用Glob进行递归 [英] Scons. Go recursive with Glob

查看:1900
本文介绍了Scons。使用Glob进行递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用香烟几天,困惑了一下。为什么没有内置的工具用于从给定的根目录递归构建源?让我解释一下:
我有这样的源配置:

I using scons for a few days and confused a bit. Why there is no built-in tools for building sources recursively starting from given root? Let me explain: I have such source disposition:

src
    Core
       folder1
       folder2
           subfolder2_1
    Std
       folder1

等等。

现在我用这样的结构构建:

Now I build this with such construction:

sources = Glob('./builds/Std/*/*.cpp')
sources = sources + Glob('./builds/Std/*.cpp')
sources = sources + Glob('./builds/Std/*/*/*.cpp')
sources = sources + Glob('./builds/Std/*/*/*/*.cpp')

这看起来不是那么完美。原因是,我可以写一些python代码,但
有更合适的方法这样做吗?

and this looks not so perfect as at can be. Of cause, I can write some python code, but is there more suitable ways of doing this?

推荐答案


你需要写python包装来走过dirs。你可以在stackoverflow上找到很多食谱。
这是我的简单函数,它返回当前目录中的子目录列表dir(并忽略隐藏dirs,以'。'开头)

Sure. You need to write python wrappers to walking through dirs. You can find many recipes on stackoverflow. Here is my simple function which returns list of subdirs in present dir (and ignore hide dirs starting with '.' - dot)

def getSubdirs(abs_path_dir) :  
    lst = [ name for name in os.listdir(abs_path_dir) if os.path.isdir(os.path.join(abs_path_dir, name)) and name[0] != '.' ]
    lst.sort()
    return lst

例如,我有dir模块什么包含foo,bar,ice。

For example, i've dir modules what containts foo, bar, ice.

corePath = 'abs/path/to/modules'
modules = getSubdirs(corePath)
# modules = [bar, foo, ice]
for module in modules :
  sources += Glob(os.path.join(corePath, module, '*.cpp'))

您可以改善getSubdirs函数,添加递归和更深入地处理subdirs。

You can improve getSubdirs function adding recurse and walking deeper to subdirs.

这篇关于Scons。使用Glob进行递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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