in src/com/facebook/buck/parser/buck.py [0:0]
def glob(includes, excludes=[], build_env=None):
search_base = build_env['BUILD_FILE_DIRECTORY']
# Ensure the user passes lists of strings rather than just a string.
assert not isinstance(includes, basestring), \
"The first argument to glob() must be a list of strings."
assert not isinstance(excludes, basestring), \
"The excludes argument must be a list of strings."
inclusions = [pattern_to_regex(p) for p in includes]
exclusions = [pattern_to_regex(p) for p in excludes]
def passes_glob_filter(path):
for exclusion in exclusions:
if exclusion.match(path):
return False
for inclusion in inclusions:
if inclusion.match(path):
return True
return False
# Return the filtered set of includes as an array.
paths = []
def check_path(path):
if passes_glob_filter(path):
paths.append(path)
for root, dirs, files in symlink_aware_walk(search_base):
if len(files) == 0:
continue
relative_root = relpath(root, search_base)
# The regexes generated by glob_pattern_to_regex_string don't
# expect a leading './'
if relative_root == '.':
for file_path in files:
check_path(file_path)
else:
relative_root += '/'
for file_path in files:
relative_path = relative_root + file_path
check_path(relative_path)
return paths