Skip to content

Commit

Permalink
Introduce type checking for dependencies keyword
Browse files Browse the repository at this point in the history
Extend the interpreter's type checking to also cover the
"dependencies" keyword for build targets. As such, deprecate
legacy type checks from add_deps(), as they are no longer
reachable.

Resolves #13539.

Signed-off-by: Eyal Itkin <[email protected]>
  • Loading branch information
Eyal Itkin committed Nov 25, 2024
1 parent 9f3f88f commit 489ac5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
14 changes: 1 addition & 13 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,20 +1372,8 @@ def add_deps(self, deps):
self.external_deps.append(dep)
self.process_sourcelist(dep.get_sources())
self.add_deps(dep.ext_deps)
elif isinstance(dep, BuildTarget):
raise InvalidArguments(f'Tried to use a build target {dep.name} as a dependency of target {self.name}.\n'
'You probably should put it in link_with instead.')
else:
# This is a bit of a hack. We do not want Build to know anything
# about the interpreter so we can't import it and use isinstance.
# This should be reliable enough.
if hasattr(dep, 'held_object'):
# FIXME: subproject is not a real ObjectHolder so we have to do this by hand
dep = dep.held_object
if hasattr(dep, 'project_args_frozen') or hasattr(dep, 'global_args_frozen'):
raise InvalidArguments('Tried to use subproject object as a dependency.\n'
'You probably wanted to use a dependency declared in it instead.\n'
'Access it by calling get_variable() on the subproject object.')
# Kept here for robustness, types are checked by the interpreter
raise InvalidArguments(f'Argument is of an unacceptable type {type(dep).__name__!r}.\nMust be '
'either an external dependency (returned by find_library() or '
'dependency()) or an internal dependency (returned by '
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def _objects_validator(vals: T.List[ObjectTypes]) -> T.Optional[str]:
('1.1.0', 'generated sources as positional "objects" arguments')
},
),
DEPENDENCIES_KW,
]


Expand Down

0 comments on commit 489ac5f

Please sign in to comment.