Skip to content

Commit c77707f

Browse files
committedMar 19, 2024
WIP: added source_copy: False option
1 parent 7a77c9b commit c77707f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
 

‎lib/pavilion/builder.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from pavilion.test_config import parse_timeout
2727
from pavilion.test_config.spack import SpackEnvConfig
2828

29+
from pavilion.output import dbg_print
30+
2931
class TestBuilder:
3032
"""Manages a test build and their organization.
3133
@@ -638,7 +640,6 @@ def _setup_build_dir(self, dest, tracker: BuildTracker):
638640
:param tracker: Build tracker for this build.
639641
:return: None
640642
"""
641-
642643
umask = os.umask(0)
643644
os.umask(umask)
644645

@@ -666,18 +667,23 @@ def _setup_build_dir(self, dest, tracker: BuildTracker):
666667

667668
elif src_path.is_dir():
668669
# Recursively copy the src directory to the build directory.
670+
# FRANCINE: add option to symlink everything recursively rather than copy
669671
tracker.update(
670672
state=STATES.BUILDING,
671673
note=("Copying source directory {} for build {} "
672674
"as the build directory."
673675
.format(src_path, dest)))
674676

675-
utils.copytree(
676-
src_path.as_posix(),
677-
dest.as_posix(),
678-
copy_function=shutil.copyfile,
679-
copystat=utils.make_umask_filtered_copystat(umask),
680-
symlinks=True)
677+
source_copy = self._config.get('source_copy')
678+
if source_copy.lower() == 'true':
679+
utils.copytree(
680+
src_path.as_posix(),
681+
dest.as_posix(),
682+
copy_function=shutil.copyfile,
683+
copystat=utils.make_umask_filtered_copystat(umask),
684+
symlinks=True)
685+
else:
686+
utils.symlinktree(src_path, dest)
681687

682688
elif src_path.is_file():
683689
category, subtype = utils.get_mime_type(src_path)

‎lib/pavilion/test_config/file_format.py

+4
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ class TestConfigLoader(yc.YamlConfigLoader):
663663
"source, tracking changes by "
664664
"file size/timestamp/hash."
665665
),
666+
yc.StrElem(
667+
'source_copy', default='True', choices=['true', 'false', 'True', 'False'],
668+
help_text="Whether to copy everything in source_path into the working dir."
669+
),
666670
yc.KeyedElem(
667671
'spack', elements=[
668672
yc.ListElem(

‎lib/pavilion/utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from typing import Iterator, Union, TextIO
1515
from typing import List, Dict
1616

17+
from pavilion.output import dbg_print
18+
1719

1820
def glob_to_re(glob):
1921
"""Translate the given glob to one that is compatible with (extended) grep.
@@ -193,6 +195,18 @@ def path_is_external(path: Path):
193195
return not_up_refs - up_refs <= 0
194196

195197

198+
def symlinktree(source_directory, destination_directory):
199+
for root, dirs, files in os.walk(source_directory):
200+
for file in files:
201+
src_path = os.path.join(root, file)
202+
rel_path = os.path.relpath(src_path, source_directory)
203+
dst_path = os.path.join(destination_directory, rel_path)
204+
205+
# Create
206+
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
207+
os.symlink(src_path, dst_path)
208+
209+
196210
def flat_walk(path, *args, **kwargs) -> Iterator[Path]:
197211
"""Perform an os.walk on path, but simply generate each item walked over.
198212

0 commit comments

Comments
 (0)