Scons. Go recursive with Glob

前端 未结 4 1624
一个人的身影
一个人的身影 2021-01-13 06:51

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

4条回答
  •  忘掉有多难
    2021-01-13 07:31

    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
    

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

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

提交回复
热议问题