From 100456de0761ee949e2277c97746cb8571b6ba39 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sat, 10 Dec 2022 22:44:53 -0500 Subject: [PATCH] fix broken fs.copyfile function that crashed if you tried to use it At least, if you tried to use it when passing an install_dir. Because T.Sequence is horrible and we should never use it, and the annotations are a lie that produces bugs. So, fix the annotations on CustomTarget to never allow this to happen again, and also fix the function too. Move some definitions elsewhere inline to satisfy the linter. Fixes #11157 --- mesonbuild/build.py | 2 +- mesonbuild/modules/fs.py | 2 +- mesonbuild/modules/i18n.py | 6 ++---- test cases/common/14 configure file/meson.build | 6 +++++- test cases/common/14 configure file/test.json | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index eb18d843e..60cd0cfcc 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2416,7 +2416,7 @@ class CustomTarget(Target, CommandBase): env: T.Optional[EnvironmentVariables] = None, feed: bool = False, install: bool = False, - install_dir: T.Optional[T.Sequence[T.Union[str, Literal[False]]]] = None, + install_dir: T.Optional[T.List[T.Union[str, Literal[False]]]] = None, install_mode: T.Optional[FileMode] = None, install_tag: T.Optional[T.List[T.Optional[str]]] = None, absolute_paths: bool = False, diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index eb19ec4ff..7d9699588 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -302,7 +302,7 @@ class FSModule(ExtensionModule): [dest], build_by_default=True, install=kwargs['install'], - install_dir=kwargs['install_dir'], + install_dir=[kwargs['install_dir']], install_mode=kwargs['install_mode'], install_tag=[kwargs['install_tag']], backend=state.backend, diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 2a7a9ade3..fcb0aa746 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -189,7 +189,6 @@ class I18nModule(ExtensionModule): if build_by_default is None: build_by_default = kwargs['install'] - install_dir = [kwargs['install_dir']] if kwargs['install_dir'] is not None else None install_tag = [kwargs['install_tag']] if kwargs['install_tag'] is not None else None ct = build.CustomTarget( @@ -202,7 +201,7 @@ class I18nModule(ExtensionModule): [kwargs['output']], build_by_default=build_by_default, install=kwargs['install'], - install_dir=install_dir, + install_dir=[kwargs['install_dir']] if kwargs['install_dir'] is not None else None, install_tag=install_tag, ) @@ -367,7 +366,6 @@ class I18nModule(ExtensionModule): if build_by_default is None: build_by_default = kwargs['install'] - install_dir = [kwargs['install_dir']] if kwargs['install_dir'] is not None else None install_tag = [kwargs['install_tag']] if kwargs['install_tag'] is not None else None ct = build.CustomTarget( @@ -381,7 +379,7 @@ class I18nModule(ExtensionModule): build_by_default=build_by_default, extra_depends=mo_targets, install=kwargs['install'], - install_dir=install_dir, + install_dir=[kwargs['install_dir']] if kwargs['install_dir'] is not None else None, install_tag=install_tag, ) diff --git a/test cases/common/14 configure file/meson.build b/test cases/common/14 configure file/meson.build index 1dd673426..569dd09b7 100644 --- a/test cases/common/14 configure file/meson.build +++ b/test cases/common/14 configure file/meson.build @@ -210,7 +210,11 @@ endif # Test the fs replacement # Test copying of an empty configuration data object inf = 'invalid-utf8.bin.in' -outf = fs.copyfile(inf, 'invalid-utf8-1.bin') +outf = fs.copyfile(inf, 'invalid-utf8-1.bin', + install: true, + install_dir: get_option('datadir') / meson.project_name(), + install_tag: 'copyfile', +) test('fs.copyfile string', check_file, args: [files(inf), outf]) # Test with default outname of string diff --git a/test cases/common/14 configure file/test.json b/test cases/common/14 configure file/test.json index 92f7b1896..5a6ccd57a 100644 --- a/test cases/common/14 configure file/test.json +++ b/test cases/common/14 configure file/test.json @@ -3,6 +3,7 @@ {"type": "file", "file": "usr/share/appdir/config2.h"}, {"type": "file", "file": "usr/share/appdir/config2b.h"}, {"type": "file", "file": "usr/share/appdireh/config2-1.h"}, - {"type": "file", "file": "usr/share/appdirok/config2-2.h"} + {"type": "file", "file": "usr/share/appdirok/config2-2.h"}, + {"type": "file", "file": "usr/share/configure file test/invalid-utf8-1.bin"} ] }