From cca76a7b2c9b16fa45a3e18069e23b47013d9c8d Mon Sep 17 00:00:00 2001 From: Gerion Entrup Date: Mon, 11 Mar 2024 11:21:56 +0100 Subject: [PATCH] depends keyword argument: accept CustomTargetIndex That holds for all of these meson function: run_target, generator and custom_target and additionally to the Windows and Gnome module. --- docs/markdown/Windows-module.md | 2 +- docs/yaml/functions/custom_target.yaml | 5 +++-- docs/yaml/functions/generator.yaml | 5 +++-- docs/yaml/functions/run_target.yaml | 5 +++-- mesonbuild/build.py | 4 ++-- mesonbuild/interpreter/type_checking.py | 6 +++--- test cases/common/51 run target/meson.build | 5 +++++ test cases/common/71 ctarget dependency/meson.build | 5 +++++ 8 files changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/markdown/Windows-module.md b/docs/markdown/Windows-module.md index c6d52841d16a..025f046cc955 100644 --- a/docs/markdown/Windows-module.md +++ b/docs/markdown/Windows-module.md @@ -12,7 +12,7 @@ Windows. windows.compile_resources(...(string | File | CustomTarget | CustomTargetIndex), args: []string, depend_files: [](string | File), - depends: [](BuildTarget | CustomTarget) + depends: [](BuildTarget | CustomTarget | CustomTargetIndex) include_directories: [](IncludeDirectories | string)): []CustomTarget ``` diff --git a/docs/yaml/functions/custom_target.yaml b/docs/yaml/functions/custom_target.yaml index caccd4883bf2..b9075c1893c7 100644 --- a/docs/yaml/functions/custom_target.yaml +++ b/docs/yaml/functions/custom_target.yaml @@ -138,14 +138,15 @@ kwargs: argument. Useful for adding regen dependencies. depends: - type: list[build_tgt | custom_tgt] + type: list[build_tgt | custom_tgt | custom_idx] description: | Specifies that this target depends on the specified target(s), even though it does not take any of them as a command line argument. This is meant for cases where you have a tool that e.g. does globbing internally. Usually you should just put the generated sources as inputs and Meson will set up all dependencies - automatically. + automatically (custom_idx was unavailable as a type between 0.60 + and 1.4.0). depfile: type: str diff --git a/docs/yaml/functions/generator.yaml b/docs/yaml/functions/generator.yaml index cec0b79e3b3f..6079d300f107 100644 --- a/docs/yaml/functions/generator.yaml +++ b/docs/yaml/functions/generator.yaml @@ -50,12 +50,13 @@ kwargs: depends: # Not sure why this is not just `target` - type: list[build_tgt | custom_tgt] + type: list[build_tgt | custom_tgt | custom_idx] since: 0.51.0 description: | An array of build targets that must be built before this generator can be run. This is used if you have a generator that calls - a second executable that is built in this project. + a second executable that is built in this project (custom_idx was not + available between 0.60 and 1.4.0). depfile: type: str diff --git a/docs/yaml/functions/run_target.yaml b/docs/yaml/functions/run_target.yaml index 66d6e8f1dd04..3ede1c91e0de 100644 --- a/docs/yaml/functions/run_target.yaml +++ b/docs/yaml/functions/run_target.yaml @@ -40,11 +40,12 @@ kwargs: the first item will find that command in `PATH` and run it. depends: - type: list[build_tgt | custom_tgt] + type: list[build_tgt | custom_tgt | custom_idx] description: | A list of targets that this target depends on but which are not listed in the command array (because, for example, the - script does file globbing internally) + script does file globbing internally, custom_idx was not possible + as a type between 0.60 and 1.4.0). env: since: 0.57.0 diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 2b6ce8875f17..6dd1eb6044b0 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2815,7 +2815,7 @@ class RunTarget(Target, CommandBase): def __init__(self, name: str, command: T.Sequence[T.Union[str, File, BuildTargetTypes, programs.ExternalProgram]], - dependencies: T.Sequence[Target], + dependencies: T.Sequence[T.Union[Target, 'CustomTargetIndex']], subdir: str, subproject: str, environment: environment.Environment, @@ -2834,7 +2834,7 @@ def __repr__(self) -> str: repr_str = "<{0} {1}: {2}>" return repr_str.format(self.__class__.__name__, self.get_id(), self.command[0]) - def get_dependencies(self) -> T.List[T.Union[BuildTarget, 'CustomTarget']]: + def get_dependencies(self) -> T.List[T.Union[BuildTarget, 'CustomTarget', 'CustomTargetIndex']]: return self.dependencies def get_generated_sources(self) -> T.List['GeneratedTypes']: diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 1256495d1a00..9b7e35c637ef 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -268,12 +268,12 @@ def _env_convertor(value: _FullEnvInitValueType) -> EnvironmentVariables: validator=lambda x: 'Depfile must be a plain filename with a subdirectory' if has_path_sep(x) else None ) -# TODO: CustomTargetIndex should be supported here as well -DEPENDS_KW: KwargInfo[T.List[T.Union[BuildTarget, CustomTarget]]] = KwargInfo( +DEPENDS_KW: KwargInfo[T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]] = KwargInfo( 'depends', - ContainerTypeInfo(list, (BuildTarget, CustomTarget)), + ContainerTypeInfo(list, (BuildTarget, CustomTarget, CustomTargetIndex)), listify=True, default=[], + since_values={CustomTargetIndex: '1.5.0'}, ) DEPEND_FILES_KW: KwargInfo[T.List[T.Union[str, File]]] = KwargInfo( diff --git a/test cases/common/51 run target/meson.build b/test cases/common/51 run target/meson.build index dbb67322030a..3b5c16b3a898 100644 --- a/test cases/common/51 run target/meson.build +++ b/test cases/common/51 run target/meson.build @@ -33,6 +33,11 @@ run_target('upload2', depends : hex, ) +run_target('upload3', + command : [fakeburner, 'x:@0@:y'.format(hex.full_path())], + depends : hex[0], +) + python3 = find_program('python3', required : false) if not python3.found() python3 = find_program('python') diff --git a/test cases/common/71 ctarget dependency/meson.build b/test cases/common/71 ctarget dependency/meson.build index 40f7398fbd20..d3e73cec7f33 100644 --- a/test cases/common/71 ctarget dependency/meson.build +++ b/test cases/common/71 ctarget dependency/meson.build @@ -18,3 +18,8 @@ custom_target('output', output : 'output.dat', command : [g2, '@OUTDIR@', '@OUTPUT@'], depends : c1) + +custom_target('output2', +output : 'output2.dat', +command : [g2, '@OUTDIR@', '@OUTPUT@'], +depends : c1[0])