Skip to content

Commit ba8d96d

Browse files
committed
Rewrite file clone implementation
This method avoids calling `__init__` on the clones, and instead clones each member. It also improves how we track "parent" objects and how shallow clones work.
1 parent 80d5064 commit ba8d96d

4 files changed

Lines changed: 375 additions & 273 deletions

File tree

‎bfg9000/builtins/copy_file.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def convert_args(context, name, file, kwargs):
3434
directory = buildpath(context, directory, strict=True)
3535
file = context['auto_file'](file)
3636

37-
def pathfn(file):
37+
def pathfn(p, obj):
3838
if name is None:
39-
path = file.path.reroot()
39+
path = p.reroot()
4040
if directory:
4141
return within_directory(path, directory)
4242
return path
@@ -62,8 +62,8 @@ def __init__(self, context, output, file, *, extra_deps=None,
6262
def convert_args(context, file, kwargs):
6363
file = context['auto_file'](file)
6464

65-
def pathfn(file):
66-
return file.path.reroot().addext('.gz')
65+
def pathfn(p, obj):
66+
return p.reroot().addext('.gz')
6767

6868
output = file.clone(pathfn)
6969
return output, file, kwargs

‎bfg9000/builtins/install.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,28 @@ def __iter__(self):
4949

5050

5151
def installify(file, *, directory=None, cross=None):
52-
def pathfn(f):
53-
if f is not file and f.private:
52+
def pathfn(p, obj):
53+
if obj is not file and obj.private:
5454
# Private subfiles won't (and in some cases can't) be installed.
55-
return f.path
56-
if f.path.root not in (path.Root.srcdir, path.Root.builddir):
55+
return p
56+
if p.root not in (path.Root.srcdir, path.Root.builddir):
5757
raise ValueError('external files are not installable')
5858

5959
# Get the install root.
6060
if isinstance(directory, path.Path):
6161
install_root = directory
6262
if not isinstance(install_root.root, path.InstallRoot):
6363
raise ValueError('not an install directory')
64-
elif f.install_root is None:
64+
elif obj.install_root is None:
6565
raise TypeError(('{!r} is not installable; specify an absolute ' +
66-
'install directory?').format(type(f).__name__))
66+
'install directory?').format(type(obj).__name__))
6767
elif directory:
68-
install_root = path.Path(directory, f.install_root)
68+
install_root = path.Path(directory, obj.install_root)
6969
else:
70-
install_root = f.install_root
70+
install_root = obj.install_root
7171

72-
cls = cross.target_platform.Path if cross else type(f.path)
73-
return cls(f.install_suffix, install_root, destdir=not cross)
72+
cls = cross.target_platform.Path if cross else type(p)
73+
return cls(obj.install_suffix, install_root, destdir=not cross)
7474

7575
if not isinstance(file, BaseFile):
7676
raise TypeError('expected a file or directory')

0 commit comments

Comments
 (0)