Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

PROTO_SEPARATOR = ";" if (platform.system() == "Windows") else ":"


def _getprotodeps(deps):
r = set()
for d in deps:
Expand Down
36 changes: 21 additions & 15 deletions build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,37 @@ def collectattrs(*, targets, name, initial=[]):

@functools.cache
def _glob_to_re(glob_str):
opts = re.compile('([.]|[*][*]/|[*]|[?])|(.)')
out = ''
for (pattern_match, literal_text) in opts.findall(glob_str):
if pattern_match == '.':
out += '[.]'
elif pattern_match == '**/':
out += '(?:.*/)?'
elif pattern_match == '*':
out += '[^/]*'
elif pattern_match == '?':
out += '.'
if glob_str.startswith("./"):
glob_str = normpath(join(getcwd(), glob_str))

opts = re.compile("([.]|[*][*]/|[*]|[?])|(.)")
out = ""
for pattern_match, literal_text in opts.findall(glob_str):
if pattern_match == ".":
out += "[.]"
elif pattern_match == "**/":
out += "(?:.*/)?"
elif pattern_match == "*":
out += "[^/]*"
elif pattern_match == "?":
out += "."
elif literal_text:
out += literal_text
return re.compile(out)


def _glob_filter(paths, pattern):
r = _glob_to_re(pattern)
for f in paths:
if r.match(f):
yield f


def _glob_matches(path, pattern):
r = _glob_to_re(pattern)
return r.match(path)


def glob(include=["*"], exclude=[], dir=None, relative_to="."):
if not dir:
dir = getcwd()
Expand All @@ -77,15 +83,15 @@ def iterate():
for dirpath, dirnames, filenames in walk(
dir, topdown=True, followlinks=True
):
dirpath = relpath(dirpath, dir)
dirpath = relpath(dirpath, relative_to)
filenames = [normpath(join(dirpath, f)) for f in filenames]
matching = set()
for p in include:
matching.update(_glob_filter(filenames, p))
matching.update([f for f in _glob_filter(filenames, p)])
for p in exclude:
matching = [n for n in matching if not _glob_matches(n, p)]
matching = [n for n in matching if not _glob_matches(n, p)]
for f in matching:
yield normpath(relpath(join(dir, f), relative_to))
yield f

return list(iterate())

Expand Down
Loading