diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-03-20 00:15:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-20 00:15:01 +0200 |
commit | 657836b555ef03c1ad70a855498dee15da19c2dc (patch) | |
tree | 25402a1b78ac09e70d9994a930590d5274ad9655 | |
parent | d012b5b997e917a971bca1236a065453493c780d (diff) | |
parent | 5f81d362078ec1f1de97fc55cdbebb69d5e37865 (diff) | |
download | meson-657836b555ef03c1ad70a855498dee15da19c2dc.zip meson-657836b555ef03c1ad70a855498dee15da19c2dc.tar.gz meson-657836b555ef03c1ad70a855498dee15da19c2dc.tar.bz2 |
Merge pull request #3223 from sarum9in/rename
Add install_data() rename parameter
-rw-r--r-- | docs/markdown/Installing.md | 13 | ||||
-rw-r--r-- | docs/markdown/Reference-manual.md | 7 | ||||
-rw-r--r-- | docs/markdown/snippets/install_data-rename.md | 11 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 9 | ||||
-rw-r--r-- | mesonbuild/build.py | 8 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 5 | ||||
-rw-r--r-- | test cases/common/12 data/installed_files.txt | 4 | ||||
-rw-r--r-- | test cases/common/12 data/meson.build | 6 | ||||
-rw-r--r-- | test cases/common/12 data/to_be_renamed_1.txt | 0 | ||||
-rw-r--r-- | test cases/common/12 data/to_be_renamed_3.txt | 0 | ||||
-rw-r--r-- | test cases/common/12 data/to_be_renamed_4.txt | 0 | ||||
-rw-r--r-- | test cases/common/12 data/vanishing/to_be_renamed_2.txt | 0 | ||||
-rw-r--r-- | test cases/failing/70 install_data rename bad size/file1.txt | 0 | ||||
-rw-r--r-- | test cases/failing/70 install_data rename bad size/file2.txt | 0 | ||||
-rw-r--r-- | test cases/failing/70 install_data rename bad size/meson.build | 3 |
15 files changed, 58 insertions, 8 deletions
diff --git a/docs/markdown/Installing.md b/docs/markdown/Installing.md index 4670544..b8e6a81 100644 --- a/docs/markdown/Installing.md +++ b/docs/markdown/Installing.md @@ -29,6 +29,19 @@ install_man('foo.1') # -> share/man/man1/foo.1.gz install_data('datafile.dat', install_dir : join_paths(get_option('datadir'), 'progname')) # -> share/progname/datafile.dat ``` +`install_data()` supports rename of the file *since 0.46.0*. + +```meson +# file.txt -> {datadir}/{projectname}/new-name.txt +install_data('file.txt', rename : 'new-name.txt') + +# file1.txt -> share/myapp/dir1/data.txt +# file2.txt -> share/myapp/dir2/data.txt +install_data(['file1.txt', 'file2.txt'], + rename : ['dir1/data.txt', 'dir2/data.txt'], + install_dir : 'share/myapp') +``` + Sometimes you want to copy an entire subtree directly. For this use case there is the `install_subdir` command, which can be used like this. ```meson diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 589baf1..0d7dedc 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -737,6 +737,13 @@ arguments. The following keyword arguments are supported: To leave any of these three as the default, specify `false`. +- `rename` if specified renames each source file into corresponding file + from `rename` list. Nested paths are allowed and they are joined with + `install_dir`. Length of `rename` list must be equal to the number of sources. + *(added 0.46.0)* + +See [Installing](Installing.md) for more examples. + ### install_headers() ``` meson diff --git a/docs/markdown/snippets/install_data-rename.md b/docs/markdown/snippets/install_data-rename.md new file mode 100644 index 0000000..6378d0f --- /dev/null +++ b/docs/markdown/snippets/install_data-rename.md @@ -0,0 +1,11 @@ +## install_data() supports rename + +`rename` parameter is used to change names of the installed files. +In order to install +- `file1.txt` into `share/myapp/dir1/data.txt` +- `file2.txt` into `share/myapp/dir2/data.txt` +```meson +install_data(['file1.txt', 'file2.txt'], + rename : ['dir1/data.txt', 'dir2/data.txt'], + install_dir : 'share/myapp') +``` diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 9500d69..f0ea09b 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -878,11 +878,10 @@ int dummy; subdir = de.install_dir if not subdir: subdir = os.path.join(self.environment.get_datadir(), self.interpreter.build.project_name) - for f in de.sources: - assert(isinstance(f, mesonlib.File)) - plain_f = os.path.basename(f.fname) - dstabs = os.path.join(subdir, plain_f) - i = [f.absolute_path(srcdir, builddir), dstabs, de.install_mode] + 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) + i = [src_file.absolute_path(srcdir, builddir), dst_abs, de.install_mode] d.data.append(i) def generate_subdir_install(self, d): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index a1662f7..c2f547b 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1894,13 +1894,19 @@ class ConfigurationData: # A bit poorly named, but this represents plain data files to copy # during install. class Data: - def __init__(self, sources, install_dir, install_mode=None): + def __init__(self, sources, install_dir, install_mode=None, rename=None): self.sources = sources self.install_dir = install_dir self.install_mode = install_mode self.sources = listify(self.sources) for s in self.sources: assert(isinstance(s, File)) + if rename is None: + self.rename = [os.path.basename(f.fname) for f in self.sources] + else: + self.rename = stringlistify(rename) + if len(self.rename) != len(self.sources): + raise MesonException('Size of rename argument is different from number of sources') class RunScript(dict): def __init__(self, script, args): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 1a1f6b4..029fe59 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1500,7 +1500,7 @@ permitted_kwargs = {'add_global_arguments': {'language'}, 'find_program': {'required', 'native'}, 'generator': {'arguments', 'output', 'depfile', 'capture', 'preserve_path_from'}, 'include_directories': {'is_system'}, - 'install_data': {'install_dir', 'install_mode', 'sources'}, + 'install_data': {'install_dir', 'install_mode', 'rename', 'sources'}, 'install_headers': {'install_dir', 'subdir'}, 'install_man': {'install_dir'}, 'install_subdir': {'exclude_files', 'exclude_directories', 'install_dir', 'install_mode', 'strip_directory'}, @@ -2826,7 +2826,8 @@ root and issuing %s. if not isinstance(install_dir, (str, type(None))): raise InvalidArguments('Keyword argument install_dir not a string.') install_mode = self._get_kwarg_install_mode(kwargs) - data = DataHolder(build.Data(sources, install_dir, install_mode)) + rename = kwargs.get('rename', None) + data = DataHolder(build.Data(sources, install_dir, install_mode, rename)) self.build.data.append(data.held_object) return data diff --git a/test cases/common/12 data/installed_files.txt b/test cases/common/12 data/installed_files.txt index ab1a981..43bb0e5 100644 --- a/test cases/common/12 data/installed_files.txt +++ b/test cases/common/12 data/installed_files.txt @@ -2,6 +2,10 @@ usr/share/progname/datafile.dat usr/share/progname/fileobject_datafile.dat usr/share/progname/vanishing.dat usr/share/progname/vanishing2.dat +usr/share/data install test/renamed file.txt usr/share/data install test/somefile.txt +usr/share/data install test/some/nested/path.txt +usr/share/renamed/renamed 2.txt +usr/share/renamed/renamed 3.txt etc/etcfile.dat usr/bin/runscript.sh diff --git a/test cases/common/12 data/meson.build b/test cases/common/12 data/meson.build index 4528afe..d855bba 100644 --- a/test cases/common/12 data/meson.build +++ b/test cases/common/12 data/meson.build @@ -15,3 +15,9 @@ install_data(files('somefile.txt')) subdir('vanishing') install_data(sources : 'vanishing/vanishing2.dat', install_dir : 'share/progname') + +install_data(sources : 'to_be_renamed_1.txt', rename : 'renamed file.txt') +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') diff --git a/test cases/common/12 data/to_be_renamed_1.txt b/test cases/common/12 data/to_be_renamed_1.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/12 data/to_be_renamed_1.txt diff --git a/test cases/common/12 data/to_be_renamed_3.txt b/test cases/common/12 data/to_be_renamed_3.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/12 data/to_be_renamed_3.txt diff --git a/test cases/common/12 data/to_be_renamed_4.txt b/test cases/common/12 data/to_be_renamed_4.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/12 data/to_be_renamed_4.txt diff --git a/test cases/common/12 data/vanishing/to_be_renamed_2.txt b/test cases/common/12 data/vanishing/to_be_renamed_2.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/12 data/vanishing/to_be_renamed_2.txt diff --git a/test cases/failing/70 install_data rename bad size/file1.txt b/test cases/failing/70 install_data rename bad size/file1.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/failing/70 install_data rename bad size/file1.txt diff --git a/test cases/failing/70 install_data rename bad size/file2.txt b/test cases/failing/70 install_data rename bad size/file2.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/failing/70 install_data rename bad size/file2.txt diff --git a/test cases/failing/70 install_data rename bad size/meson.build b/test cases/failing/70 install_data rename bad size/meson.build new file mode 100644 index 0000000..c7cde08 --- /dev/null +++ b/test cases/failing/70 install_data rename bad size/meson.build @@ -0,0 +1,3 @@ +project('data install test', 'c') + +install_data(['file1.txt', 'file2.txt'], rename : 'just one name') |