Skip to content

Commit 0af126f

Browse files
ArsenArseneli-schwartz
authored andcommitted
install_{data,headers,subdir}: implement follow_symlinks
This permits users who rely on following symlinks to stay on the old default of following them.
1 parent 56ef698 commit 0af126f

15 files changed

Lines changed: 139 additions & 24 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Added follow_symlinks arg to install_data, install_header, and install_subdir
2+
3+
The [[install_data]], [[install_headers]], [[install_subdir]] functions now
4+
have an optional argument `follow_symlinks` that, if set to `true`, makes it so
5+
symbolic links in the source are followed, rather than copied into the
6+
destination tree, to match the old behavior. The default, which is currently
7+
to follow links, is subject to change in the future.

‎docs/yaml/functions/install_data.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ kwargs:
6969
sources:
7070
type: list[file | str]
7171
description: Additional files to install.
72+
73+
follow_symlinks:
74+
type: bool
75+
since: 1.3.0
76+
default: true
77+
description: |
78+
If true, dereferences links and copies their target instead. The default
79+
value will become false in the future.

‎docs/yaml/functions/install_headers.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ kwargs:
7373
Disable stripping child-directories from header files when installing.
7474
7575
This is equivalent to GNU Automake's `nobase` option.
76+
77+
follow_symlinks:
78+
type: bool
79+
since: 1.3.0
80+
default: true
81+
description: |
82+
If true, dereferences links and copies their target instead. The default
83+
value will become false in the future.

‎docs/yaml/functions/install_subdir.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,11 @@ kwargs:
106106
description: |
107107
Install directory contents.
108108
If `strip_directory=true` only the last component of the source path is used.
109+
110+
follow_symlinks:
111+
type: bool
112+
since: 1.3.0
113+
default: true
114+
description: |
115+
If true, dereferences links and copies their target instead. The default
116+
value will become false in the future.

‎mesonbuild/backend/backends.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class InstallDataBase:
172172
subproject: str
173173
tag: T.Optional[str] = None
174174
data_type: T.Optional[str] = None
175+
follow_symlinks: T.Optional[bool] = None
175176

176177
@dataclass(eq=False)
177178
class InstallSymlinkData:
@@ -186,8 +187,9 @@ class InstallSymlinkData:
186187
class SubdirInstallData(InstallDataBase):
187188
def __init__(self, path: str, install_path: str, install_path_name: str,
188189
install_mode: 'FileMode', exclude: T.Tuple[T.Set[str], T.Set[str]],
189-
subproject: str, tag: T.Optional[str] = None, data_type: T.Optional[str] = None):
190-
super().__init__(path, install_path, install_path_name, install_mode, subproject, tag, data_type)
190+
subproject: str, tag: T.Optional[str] = None, data_type: T.Optional[str] = None,
191+
follow_symlinks: T.Optional[bool] = None):
192+
super().__init__(path, install_path, install_path_name, install_mode, subproject, tag, data_type, follow_symlinks)
191193
self.exclude = exclude
192194

193195

@@ -1832,7 +1834,7 @@ def generate_header_install(self, d: InstallData) -> None:
18321834
if not isinstance(f, File):
18331835
raise MesonException(f'Invalid header type {f!r} can\'t be installed')
18341836
abspath = f.absolute_path(srcdir, builddir)
1835-
i = InstallDataBase(abspath, outdir, outdir_name, h.get_custom_install_mode(), h.subproject, tag='devel')
1837+
i = InstallDataBase(abspath, outdir, outdir_name, h.get_custom_install_mode(), h.subproject, tag='devel', follow_symlinks=h.follow_symlinks)
18361838
d.headers.append(i)
18371839

18381840
def generate_man_install(self, d: InstallData) -> None:
@@ -1877,7 +1879,8 @@ def generate_data_install(self, d: InstallData) -> None:
18771879
dstdir_name = os.path.join(subdir_name, dst_name)
18781880
tag = de.install_tag or self.guess_install_tag(dst_abs)
18791881
i = InstallDataBase(src_file.absolute_path(srcdir, builddir), dst_abs, dstdir_name,
1880-
de.install_mode, de.subproject, tag=tag, data_type=de.data_type)
1882+
de.install_mode, de.subproject, tag=tag, data_type=de.data_type,
1883+
follow_symlinks=de.follow_symlinks)
18811884
d.data.append(i)
18821885

18831886
def generate_symlink_install(self, d: InstallData) -> None:
@@ -1908,7 +1911,8 @@ def generate_subdir_install(self, d: InstallData) -> None:
19081911
dst_dir = os.path.join(dst_dir, os.path.basename(src_dir))
19091912
dst_name = os.path.join(dst_name, os.path.basename(src_dir))
19101913
tag = sd.install_tag or self.guess_install_tag(os.path.join(sd.install_dir, 'dummy'))
1911-
i = SubdirInstallData(src_dir, dst_dir, dst_name, sd.install_mode, sd.exclude, sd.subproject, tag)
1914+
i = SubdirInstallData(src_dir, dst_dir, dst_name, sd.install_mode, sd.exclude, sd.subproject, tag,
1915+
follow_symlinks=sd.follow_symlinks)
19121916
d.install_subdirs.append(i)
19131917

19141918
def get_introspection_data(self, target_id: str, target: build.Target) -> T.List['TargetIntrospectionData']:

‎mesonbuild/build.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class Headers(HoldableObject):
156156
custom_install_dir: T.Optional[str]
157157
custom_install_mode: 'FileMode'
158158
subproject: str
159+
follow_symlinks: T.Optional[bool] = None
159160

160161
# TODO: we really don't need any of these methods, but they're preserved to
161162
# keep APIs relying on them working.
@@ -214,6 +215,7 @@ class InstallDir(HoldableObject):
214215
subproject: str
215216
from_source_dir: bool = True
216217
install_tag: T.Optional[str] = None
218+
follow_symlinks: T.Optional[bool] = None
217219

218220
@dataclass(eq=False)
219221
class DepManifest:
@@ -2973,6 +2975,7 @@ class Data(HoldableObject):
29732975
rename: T.List[str] = None
29742976
install_tag: T.Optional[str] = None
29752977
data_type: str = None
2978+
follow_symlinks: T.Optional[bool] = None
29762979

29772980
def __post_init__(self) -> None:
29782981
if self.rename is None:

‎mesonbuild/interpreter/interpreter.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
INSTALL_KW,
7979
INSTALL_DIR_KW,
8080
INSTALL_MODE_KW,
81+
INSTALL_FOLLOW_SYMLINKS,
8182
LINK_WITH_KW,
8283
LINK_WHOLE_KW,
8384
CT_INSTALL_TAG_KW,
@@ -2238,6 +2239,7 @@ def add_test(self, node: mparser.BaseNode,
22382239
KwargInfo('subdir', (str, NoneType)),
22392240
INSTALL_MODE_KW.evolve(since='0.47.0'),
22402241
INSTALL_DIR_KW,
2242+
INSTALL_FOLLOW_SYMLINKS,
22412243
)
22422244
def func_install_headers(self, node: mparser.BaseNode,
22432245
args: T.Tuple[T.List['mesonlib.FileOrString']],
@@ -2264,7 +2266,8 @@ def func_install_headers(self, node: mparser.BaseNode,
22642266

22652267
for childdir in dirs:
22662268
h = build.Headers(dirs[childdir], os.path.join(install_subdir, childdir), kwargs['install_dir'],
2267-
install_mode, self.subproject)
2269+
install_mode, self.subproject,
2270+
follow_symlinks=kwargs['follow_symlinks'])
22682271
ret_headers.append(h)
22692272
self.build.headers.append(h)
22702273

@@ -2459,6 +2462,7 @@ def _warn_kwarg_install_mode_sticky(self, mode: FileMode) -> None:
24592462
INSTALL_TAG_KW.evolve(since='0.60.0'),
24602463
INSTALL_DIR_KW,
24612464
PRESERVE_PATH_KW.evolve(since='0.64.0'),
2465+
INSTALL_FOLLOW_SYMLINKS,
24622466
)
24632467
def func_install_data(self, node: mparser.BaseNode,
24642468
args: T.Tuple[T.List['mesonlib.FileOrString']],
@@ -2486,15 +2490,16 @@ def func_install_data(self, node: mparser.BaseNode,
24862490

24872491
install_mode = self._warn_kwarg_install_mode_sticky(kwargs['install_mode'])
24882492
return self.install_data_impl(sources, install_dir, install_mode, rename, kwargs['install_tag'],
2489-
preserve_path=kwargs['preserve_path'])
2493+
preserve_path=kwargs['preserve_path'],
2494+
follow_symlinks=kwargs['follow_symlinks'])
24902495

24912496
def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: str,
24922497
install_mode: FileMode, rename: T.Optional[str],
24932498
tag: T.Optional[str],
24942499
install_data_type: T.Optional[str] = None,
2495-
preserve_path: bool = False) -> build.Data:
2500+
preserve_path: bool = False,
2501+
follow_symlinks: T.Optional[bool] = None) -> build.Data:
24962502
install_dir_name = install_dir.optname if isinstance(install_dir, P_OBJ.OptionString) else install_dir
2497-
24982503
dirs = collections.defaultdict(list)
24992504
if preserve_path:
25002505
for file in sources:
@@ -2506,7 +2511,8 @@ def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: str,
25062511
ret_data = []
25072512
for childdir, files in dirs.items():
25082513
d = build.Data(files, os.path.join(install_dir, childdir), os.path.join(install_dir_name, childdir),
2509-
install_mode, self.subproject, rename, tag, install_data_type)
2514+
install_mode, self.subproject, rename, tag, install_data_type,
2515+
follow_symlinks)
25102516
ret_data.append(d)
25112517

25122518
self.build.data.extend(ret_data)
@@ -2525,6 +2531,7 @@ def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: str,
25252531
validator=lambda x: 'cannot be absolute' if any(os.path.isabs(d) for d in x) else None),
25262532
INSTALL_MODE_KW.evolve(since='0.38.0'),
25272533
INSTALL_TAG_KW.evolve(since='0.60.0'),
2534+
INSTALL_FOLLOW_SYMLINKS,
25282535
)
25292536
def func_install_subdir(self, node: mparser.BaseNode, args: T.Tuple[str],
25302537
kwargs: 'kwtypes.FuncInstallSubdir') -> build.InstallDir:
@@ -2550,7 +2557,8 @@ def func_install_subdir(self, node: mparser.BaseNode, args: T.Tuple[str],
25502557
exclude,
25512558
kwargs['strip_directory'],
25522559
self.subproject,
2553-
install_tag=kwargs['install_tag'])
2560+
install_tag=kwargs['install_tag'],
2561+
follow_symlinks=kwargs['follow_symlinks'])
25542562
self.build.install_dirs.append(idir)
25552563
return idir
25562564

‎mesonbuild/interpreter/kwargs.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class FuncInstallSubdir(TypedDict):
124124
exclude_files: T.List[str]
125125
exclude_directories: T.List[str]
126126
install_mode: FileMode
127+
follow_symlinks: T.Optional[bool]
127128

128129

129130
class FuncInstallData(TypedDict):
@@ -132,13 +133,15 @@ class FuncInstallData(TypedDict):
132133
sources: T.List[FileOrString]
133134
rename: T.List[str]
134135
install_mode: FileMode
136+
follow_symlinks: T.Optional[bool]
135137

136138

137139
class FuncInstallHeaders(TypedDict):
138140

139141
install_dir: T.Optional[str]
140142
install_mode: FileMode
141143
subdir: T.Optional[str]
144+
follow_symlinks: T.Optional[bool]
142145

143146

144147
class FuncInstallMan(TypedDict):

‎mesonbuild/interpreter/type_checking.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ def _output_validator(outputs: T.List[str]) -> T.Optional[str]:
368368

369369
INSTALL_TAG_KW: KwargInfo[T.Optional[str]] = KwargInfo('install_tag', (str, NoneType))
370370

371+
INSTALL_FOLLOW_SYMLINKS: KwargInfo[T.Optional[bool]] = KwargInfo(
372+
'follow_symlinks',
373+
(bool, NoneType),
374+
since='1.3.0',
375+
)
376+
371377
INSTALL_KW = KwargInfo('install', bool, default=False)
372378

373379
CT_INSTALL_DIR_KW: KwargInfo[T.List[T.Union[str, Literal[False]]]] = KwargInfo(

‎mesonbuild/minstall.py‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ class ArgumentType(Protocol):
6464
strip: bool
6565

6666

67-
symlink_warning = '''Warning: trying to copy a symlink that points to a file. This will copy the file,
68-
but this will be changed in a future version of Meson to copy the symlink as is. Please update your
69-
build definitions so that it will not break when the change happens.'''
67+
symlink_warning = '''\
68+
Warning: trying to copy a symlink that points to a file. This currently copies
69+
the file by default, but will be changed in a future version of Meson to copy
70+
the link instead. Set follow_symlinks to true to preserve current behavior, or
71+
false to copy the link.'''
7072

7173
selinux_updates: T.List[str] = []
7274

@@ -389,7 +391,8 @@ def should_preserve_existing_file(self, from_file: str, to_file: str) -> bool:
389391
return from_time <= to_time
390392

391393
def do_copyfile(self, from_file: str, to_file: str,
392-
makedirs: T.Optional[T.Tuple[T.Any, str]] = None) -> bool:
394+
makedirs: T.Optional[T.Tuple[T.Any, str]] = None,
395+
follow_symlinks: T.Optional[bool] = None) -> bool:
393396
outdir = os.path.split(to_file)[0]
394397
if not os.path.isfile(from_file) and not os.path.islink(from_file):
395398
raise MesonException(f'Tried to install something that isn\'t a file: {from_file!r}')
@@ -417,10 +420,10 @@ def do_copyfile(self, from_file: str, to_file: str,
417420
# Dangling symlink. Replicate as is.
418421
self.copy(from_file, outdir, follow_symlinks=False)
419422
else:
420-
# Remove this entire branch when changing the behaviour to duplicate
421-
# symlinks rather than copying what they point to.
422-
print(symlink_warning)
423-
self.copy2(from_file, to_file)
423+
if follow_symlinks is None:
424+
follow_symlinks = True # TODO: change to False when removing the warning
425+
print(symlink_warning)
426+
self.copy2(from_file, to_file, follow_symlinks=follow_symlinks)
424427
else:
425428
self.copy2(from_file, to_file)
426429
selinux_updates.append(to_file)
@@ -454,7 +457,7 @@ def do_symlink(self, target: str, link: str, destdir: str, full_dst_dir: str, al
454457

455458
def do_copydir(self, data: InstallData, src_dir: str, dst_dir: str,
456459
exclude: T.Optional[T.Tuple[T.Set[str], T.Set[str]]],
457-
install_mode: 'FileMode', dm: DirMaker) -> None:
460+
install_mode: 'FileMode', dm: DirMaker, follow_symlinks: T.Optional[bool] = None) -> None:
458461
'''
459462
Copies the contents of directory @src_dir into @dst_dir.
460463
@@ -519,7 +522,7 @@ def do_copydir(self, data: InstallData, src_dir: str, dst_dir: str,
519522
dm.makedirs(parent_dir)
520523
self.copystat(os.path.dirname(abs_src), parent_dir)
521524
# FIXME: what about symlinks?
522-
self.do_copyfile(abs_src, abs_dst)
525+
self.do_copyfile(abs_src, abs_dst, follow_symlinks=follow_symlinks)
523526
self.set_mode(abs_dst, install_mode, data.install_umask)
524527

525528
def do_install(self, datafilename: str) -> None:
@@ -613,7 +616,8 @@ def install_subdirs(self, d: InstallData, dm: DirMaker, destdir: str, fullprefix
613616
full_dst_dir = get_destdir_path(destdir, fullprefix, i.install_path)
614617
self.log(f'Installing subdir {i.path} to {full_dst_dir}')
615618
dm.makedirs(full_dst_dir, exist_ok=True)
616-
self.do_copydir(d, i.path, full_dst_dir, i.exclude, i.install_mode, dm)
619+
self.do_copydir(d, i.path, full_dst_dir, i.exclude, i.install_mode, dm,
620+
follow_symlinks=i.follow_symlinks)
617621

618622
def install_data(self, d: InstallData, dm: DirMaker, destdir: str, fullprefix: str) -> None:
619623
for i in d.data:
@@ -622,7 +626,7 @@ def install_data(self, d: InstallData, dm: DirMaker, destdir: str, fullprefix: s
622626
fullfilename = i.path
623627
outfilename = get_destdir_path(destdir, fullprefix, i.install_path)
624628
outdir = os.path.dirname(outfilename)
625-
if self.do_copyfile(fullfilename, outfilename, makedirs=(dm, outdir)):
629+
if self.do_copyfile(fullfilename, outfilename, makedirs=(dm, outdir), follow_symlinks=i.follow_symlinks):
626630
self.did_install_something = True
627631
self.set_mode(outfilename, i.install_mode, d.install_umask)
628632

@@ -668,7 +672,8 @@ def install_headers(self, d: InstallData, dm: DirMaker, destdir: str, fullprefix
668672
fname = os.path.basename(fullfilename)
669673
outdir = get_destdir_path(destdir, fullprefix, t.install_path)
670674
outfilename = os.path.join(outdir, fname)
671-
if self.do_copyfile(fullfilename, outfilename, makedirs=(dm, outdir)):
675+
if self.do_copyfile(fullfilename, outfilename, makedirs=(dm, outdir),
676+
follow_symlinks=t.follow_symlinks):
672677
self.did_install_something = True
673678
self.set_mode(outfilename, t.install_mode, d.install_umask)
674679

0 commit comments

Comments
 (0)