aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Nicolodi <daniele@grinta.net>2023-06-26 16:24:53 +0200
committerEli Schwartz <eschwartz93@gmail.com>2023-07-26 13:30:49 -0400
commit9eb7fe332f6a6a8babd040b76ad2a6808faf0423 (patch)
treec52b1c241f7f77e2e2beee8281c50ec39e32c569
parenta0f165b2fa57653a44c97398c00c453ec28e6dcc (diff)
downloadmeson-9eb7fe332f6a6a8babd040b76ad2a6808faf0423.zip
meson-9eb7fe332f6a6a8babd040b76ad2a6808faf0423.tar.gz
meson-9eb7fe332f6a6a8babd040b76ad2a6808faf0423.tar.bz2
Fix install_data() default install path
This fixes two issues in constructing the default installation path when install_dir is not specified: - inside a subproject, install_data() would construct the destination path using the parent project name instead than the current project name, - when specifying preserve_path, install_data() would construct the destination path omitting the project name. Fixes #11910.
-rw-r--r--docs/yaml/functions/install_data.yaml2
-rw-r--r--mesonbuild/backend/backends.py3
-rw-r--r--mesonbuild/interpreter/interpreter.py28
-rw-r--r--mesonbuild/modules/python.py1
-rw-r--r--test cases/common/12 data/meson.build4
-rw-r--r--test cases/common/12 data/subdir/data.txt0
-rw-r--r--test cases/common/12 data/subprojects/moredata/data.txt1
-rw-r--r--test cases/common/12 data/subprojects/moredata/meson.build3
-rw-r--r--test cases/common/12 data/test.json4
-rw-r--r--unittests/allplatformstests.py13
10 files changed, 38 insertions, 21 deletions
diff --git a/docs/yaml/functions/install_data.yaml b/docs/yaml/functions/install_data.yaml
index b083479..5ecc318 100644
--- a/docs/yaml/functions/install_data.yaml
+++ b/docs/yaml/functions/install_data.yaml
@@ -12,6 +12,8 @@ varargs:
warnings:
- the `install_mode` kwarg ignored integer values between 0.59.0 -- 1.1.0.
+ - an omitted `install_dir` kwarg did not work correctly inside of a subproject until 1.3.0.
+ - an omitted `install_dir` kwarg did not work correctly when combined with the `preserve_path` kwarg untill 1.3.0.
kwargs:
install_dir:
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index e18906c..3e6d652 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -1866,9 +1866,6 @@ class Backend:
assert isinstance(de, build.Data)
subdir = de.install_dir
subdir_name = de.install_dir_name
- if not subdir:
- subdir = os.path.join(self.environment.get_datadir(), self.interpreter.build.project_name)
- subdir_name = os.path.join('{datadir}', self.interpreter.build.project_name)
for src_file, dst_name in zip(de.sources, de.rename):
assert isinstance(src_file, mesonlib.File)
dst_abs = os.path.join(subdir, dst_name)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index d891fa6..dc24312 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -2465,24 +2465,31 @@ class Interpreter(InterpreterBase, HoldableObject):
'"rename" and "sources" argument lists must be the same length if "rename" is given. '
f'Rename has {len(rename)} elements and sources has {len(sources)}.')
+ install_dir = kwargs['install_dir']
+ if not install_dir:
+ subdir = self.active_projectname
+ install_dir = P_OBJ.OptionString(os.path.join(self.environment.get_datadir(), subdir), os.path.join('{datadir}', subdir))
+ if self.is_subproject():
+ FeatureNew.single_use('install_data() without install_dir inside of a subproject', '1.3.0', self.subproject,
+ 'This was broken and would install to the project name of the parent project instead',
+ node)
+ if kwargs['preserve_path']:
+ FeatureNew.single_use('install_data() with preserve_path and without install_dir', '1.3.0', self.subproject,
+ 'This was broken and would not add the project name to the install path',
+ node)
+
install_mode = self._warn_kwarg_install_mode_sticky(kwargs['install_mode'])
- return self.install_data_impl(sources, kwargs['install_dir'], install_mode,
- rename, kwargs['install_tag'],
+ return self.install_data_impl(sources, install_dir, install_mode, rename, kwargs['install_tag'],
preserve_path=kwargs['preserve_path'])
- def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: T.Optional[str],
+ def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: str,
install_mode: FileMode, rename: T.Optional[str],
tag: T.Optional[str],
- install_dir_name: T.Optional[str] = None,
install_data_type: T.Optional[str] = None,
preserve_path: bool = False) -> build.Data:
+ install_dir_name = install_dir.optname if isinstance(install_dir, P_OBJ.OptionString) else install_dir
- idir = install_dir or ''
- idir_name = install_dir_name or idir or '{datadir}'
- if isinstance(idir_name, P_OBJ.OptionString):
- idir_name = idir_name.optname
dirs = collections.defaultdict(list)
- ret_data = []
if preserve_path:
for file in sources:
dirname = os.path.dirname(file.fname)
@@ -2490,8 +2497,9 @@ class Interpreter(InterpreterBase, HoldableObject):
else:
dirs[''].extend(sources)
+ ret_data = []
for childdir, files in dirs.items():
- d = build.Data(files, os.path.join(idir, childdir), os.path.join(idir_name, childdir),
+ d = build.Data(files, os.path.join(install_dir, childdir), os.path.join(install_dir_name, childdir),
install_mode, self.subproject, rename, tag, install_data_type)
ret_data.append(d)
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index f6c82e0..75b291f 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -224,7 +224,6 @@ class PythonInstallation(ExternalProgramHolder):
self.interpreter.source_strings_to_files(args[0]),
install_dir,
mesonlib.FileMode(), rename=None, tag=tag, install_data_type='python',
- install_dir_name=install_dir.optname,
preserve_path=kwargs['preserve_path'])
@noPosargs
diff --git a/test cases/common/12 data/meson.build b/test cases/common/12 data/meson.build
index d318633..aa02131 100644
--- a/test cases/common/12 data/meson.build
+++ b/test cases/common/12 data/meson.build
@@ -22,3 +22,7 @@ install_data(sources : ['vanishing/to_be_renamed_2.txt', 'to_be_renamed_3.txt'],
install_dir : 'share/renamed',
rename : ['renamed 2.txt', 'renamed 3.txt'])
install_data(sources : 'to_be_renamed_4.txt', rename : 'some/nested/path.txt')
+
+install_data('subdir/data.txt', preserve_path : true)
+
+subproject('moredata')
diff --git a/test cases/common/12 data/subdir/data.txt b/test cases/common/12 data/subdir/data.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test cases/common/12 data/subdir/data.txt
diff --git a/test cases/common/12 data/subprojects/moredata/data.txt b/test cases/common/12 data/subprojects/moredata/data.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/test cases/common/12 data/subprojects/moredata/data.txt
@@ -0,0 +1 @@
+
diff --git a/test cases/common/12 data/subprojects/moredata/meson.build b/test cases/common/12 data/subprojects/moredata/meson.build
new file mode 100644
index 0000000..6234e26
--- /dev/null
+++ b/test cases/common/12 data/subprojects/moredata/meson.build
@@ -0,0 +1,3 @@
+project('moredata')
+
+install_data('data.txt')
diff --git a/test cases/common/12 data/test.json b/test cases/common/12 data/test.json
index f392e9a..c5fef01 100644
--- a/test cases/common/12 data/test.json
+++ b/test cases/common/12 data/test.json
@@ -10,6 +10,8 @@
{"type": "file", "file": "usr/share/renamed/renamed 2.txt"},
{"type": "file", "file": "usr/share/renamed/renamed 3.txt"},
{"type": "file", "file": "etc/etcfile.dat"},
- {"type": "file", "file": "usr/bin/runscript.sh"}
+ {"type": "file", "file": "usr/bin/runscript.sh"},
+ {"type": "file", "file": "usr/share/moredata/data.txt"},
+ {"type": "file", "file": "usr/share/data install test/subdir/data.txt"}
]
}
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index baf5875..5a6e88b 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -4130,7 +4130,8 @@ class AllPlatformTests(BasePlatformTests):
]
bar_expected = [
'bar',
- 'share/foo/bar.dat',
+ 'share/bar',
+ 'share/bar/bar.dat',
'include/bar.h',
'bin/bar' + exe_suffix,
'bar/barfile'
@@ -4410,9 +4411,9 @@ class AllPlatformTests(BasePlatformTests):
Path(installpath, 'usr/share/foo2.h'),
Path(installpath, 'usr/share/out1.txt'),
Path(installpath, 'usr/share/out2.txt'),
- Path(installpath, 'usr/share/install tag'),
- Path(installpath, 'usr/share/install tag/aaa.txt'),
- Path(installpath, 'usr/share/install tag/bbb.txt'),
+ Path(installpath, 'usr/share/subproject'),
+ Path(installpath, 'usr/share/subproject/aaa.txt'),
+ Path(installpath, 'usr/share/subproject/bbb.txt'),
}
def do_install(tags, expected_files, expected_scripts):
@@ -4613,12 +4614,12 @@ class AllPlatformTests(BasePlatformTests):
'subproject': None,
},
f'{testdir}/subprojects/subproject/aaa.txt': {
- 'destination': '{datadir}/install tag/aaa.txt',
+ 'destination': '{datadir}/subproject/aaa.txt',
'tag': None,
'subproject': 'subproject',
},
f'{testdir}/subprojects/subproject/bbb.txt': {
- 'destination': '{datadir}/install tag/bbb.txt',
+ 'destination': '{datadir}/subproject/bbb.txt',
'tag': 'data',
'subproject': 'subproject',
},