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
3 changes: 2 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if _SCRIPTS_DIR not in sys.path:

# Local
from build.option_handler import OptionsClass
from build.glob_recursive import GlobRecursive
from build.glob_recursive import GlobRecursive, GlobRecursiveVariant
from build.git_info import get_git_info, git_builder
from build.license_info import license_builder
from build.author_info import author_builder
Expand Down Expand Up @@ -287,6 +287,7 @@ def FinalizeOptions():
env.SetupOptions = SetupOptions
env.FinalizeOptions = FinalizeOptions
env.GlobRecursive = GlobRecursive
env.GlobRecursiveVariant = lambda pattern, src, variant, exclude=None: GlobRecursiveVariant(env, pattern, src, variant, exclude)
env.get_git_info = get_git_info
env.license_builder = license_builder
env.git_builder = git_builder
Expand Down
20 changes: 20 additions & 0 deletions build/glob_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ def norm(s):
norm_exclude = [norm(p) for p in exclude]
results = [r for r in results if not any(fnmatch.fnmatch(norm(r), p) for p in norm_exclude)]
return results


def GlobRecursiveVariant(env, pattern, src_root, variant_root, exclude=None):
src_nodes = GlobRecursive(pattern, [src_root])
src_abs = env.Dir(src_root).abspath.replace("\\", "/").rstrip("/") + "/"
variant_prefix = env.Dir(variant_root).abspath.replace("\\", "/").rstrip("/") + "/"
if exclude is None:
exclude_abs = set()
else:
if isinstance(exclude, str):
exclude = [exclude]
exclude_abs = {env.File(e).abspath.replace("\\", "/") for e in exclude}
out = []
for n in src_nodes:
p = n.abspath.replace("\\", "/")
if p in exclude_abs:
continue
assert p.startswith(src_abs), f"{p!r} not under {src_abs!r}"
out.append(env.File(variant_prefix + p[len(src_abs) :]))
return out
Loading