From 424d3a864c5e307d97f3ad1c3ee51c2cde9d91b9 Mon Sep 17 00:00:00 2001 From: "haonan.yu" Date: Thu, 14 Sep 2023 16:48:20 -0700 Subject: [PATCH] exclude build dirs in a snapshot; include .cc --- alf/utils/common.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/alf/utils/common.py b/alf/utils/common.py index 9d71a6fa5..ef246808f 100644 --- a/alf/utils/common.py +++ b/alf/utils/common.py @@ -1419,9 +1419,13 @@ def _is_subdir(path, directory): relative = os.path.relpath(path, directory) return not relative.startswith(os.pardir) - def rsync(src, target, includes): - args = ['rsync', '-rI', '--include=*/'] - args += ['--include=%s' % i for i in includes] + def rsync(src, target, includes, excludes=[]): + args = [ + 'rsync', + '-rI', + ] + args += ['--exclude=%s' % e for e in excludes] + args += ['--include=*/'] + ['--include=%s' % i for i in includes] args += ['--exclude=*'] args += [src, target] # shell=True preserves string arguments @@ -1429,9 +1433,10 @@ def rsync(src, target, includes): " ".join(args), stdout=sys.stdout, stderr=sys.stdout, shell=True) includes = [ - "*.py", "*.gin", "*.so", "*.json", "*.xml", "*.cpp", "*.c", "*.hpp", - "*.h", "*.stl", "*.png", "*.txt" + "*.py", "*.gin", "*.so", "*.json", "*.xml", "*.cpp", "*.c", "*.cc", + "*.hpp", "*.h", "*.stl", "*.png", "*.txt" ] + excludes = ['*/build/'] repo_roots = {**snapshot_repo_roots(), **{'alf': alf_root}} for name, root in repo_roots.items(): assert not _is_subdir(dest_path, root), ( @@ -1439,7 +1444,7 @@ def rsync(src, target, includes): (dest_path, root) + "Use a different one!") # Only copy the module dir because the root dir might contain many # other modules in the case where repo is pip installed in 'site-packages'. - rsync(root + f'/{name}', dest_path, includes) + rsync(root + f'/{name}', dest_path, includes, excludes) # compress the snapshot repo into a ".tar.gz" file os.system( f"cd {dest_path}; tar -czf {name}.tar.gz {name}; rm -rf {name}")