あなたのアプローチは、次のように微調整することで機能します。
import fnmatch
import os
def RecursiveGlob(pathname)
matches = []
for root, dirnames, filenames in os.walk(pathname):
for filename in fnmatch.filter(filenames, '*.c'):
matches.append(File(os.path.join(root, filename)))
return matches
「strings」パラメーターがfalseの場合、SCons Glob()関数はノードを返すため、これをFile()に変換したことに注意してください。
VariantDirなどを処理できるようにし、機能を既存のSCons Glob()機能とより適切に統合するには、次のように、既存のGlob()関数への呼び出しを実際に組み込むことができます。
# Notice the signature is similar to the SCons Glob() signature,
# look at scons-2.1.0/engine/SCons/Node/FS.py line 1403
def RecursiveGlob(pattern, ondisk=True, source=True, strings=False):
matches = []
# Instead of using os.getcwd() consider passing-in a path
for root, dirnames, filenames in os.walk(os.getcwd()):
cwd = Dir(root)
# Glob() returns a list, so using extend() instead of append()
# The cwd param isnt documented, (look at the code) but its
# how you tell SCons what directory to look in.
matches.extend(Glob(pattern, ondisk, source, strings, cwd))
return matches
さらに一歩進んで、次のことを行うことができます。
def MyGlob(pattern, ondisk=True, source=True, strings=False, recursive=False):
if not recursive:
return Glob(pattern, ondisk, source, strings)
matches = []
# Instead of using os.getcwd() consider passing-in a path
for root, dirnames, filenames in os.walk(os.getcwd()):
cwd = Dir(root)
# Glob() returns a list, so using extend() instead of append()
# The cwd param isnt documented, (look at the code) but its
# how you tell SCons what directory to look in.
matches.extend(Glob(pattern, ondisk, source, strings, cwd))
return matches