Skip to content

Commit

Permalink
depends keyword argument: accept CustomTargetIndex
Browse files Browse the repository at this point in the history
That holds for all of these meson function: run_target, generator and
custom_target and additionally to the Windows and Gnome module.
  • Loading branch information
gerion0 committed Apr 5, 2024
1 parent 2d010c6 commit e707a1c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/markdown/Windows-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
5 changes: 3 additions & 2 deletions docs/yaml/functions/custom_target.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/yaml/functions/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/yaml/functions/run_target.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,12 @@ def get_obj_target_deps(self, obj_list):
result[o.target.get_id()] = o.target
return result.items()

def get_target_deps(self, t: T.Dict[T.Any, build.Target], recursive=False):
def get_target_deps(self, t: T.Dict[T.Any, T.Union[build.Target, build.CustomTargetIndex]], recursive=False):
all_deps: T.Dict[str, build.Target] = {}
for target in t.values():
if isinstance(target, build.CustomTargetIndex):
# just transfer it to the CustomTarget code
target = target.target
if isinstance(target, build.CustomTarget):
for d in target.get_target_dependencies():
# FIXME: this isn't strictly correct, as the target doesn't
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2815,11 +2815,11 @@ 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,
env: T.Optional['EnvironmentVariables'] = None,
env: T.Optional[EnvironmentVariables] = None,
default_env: bool = True):
# These don't produce output artifacts
super().__init__(name, subdir, subproject, False, MachineChoice.BUILD, environment)
Expand All @@ -2834,10 +2834,10 @@ 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']:
def get_generated_sources(self) -> T.List[GeneratedTypes]:
return []

def get_sources(self) -> T.List[File]:
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions test cases/common/51 run target/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions test cases/common/71 ctarget dependency/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit e707a1c

Please sign in to comment.