aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/build.py12
-rw-r--r--mesonbuild/dependencies/base.py11
-rw-r--r--mesonbuild/interpreter/interpreter.py10
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py3
-rw-r--r--mesonbuild/modules/gnome.py4
5 files changed, 32 insertions, 8 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 03f97b2..707f5d2 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1715,6 +1715,9 @@ class Executable(BuildTarget):
# Only linkwithable if using export_dynamic
self.is_linkwithable = self.export_dynamic
+ # Remember that this exe was returned by `find_program()` through an override
+ self.was_returned_by_find_program = False
+
def get_default_install_dir(self, environment: environment.Environment) -> str:
return environment.get_bindir()
@@ -2154,6 +2157,10 @@ class BothLibraries(HoldableObject):
self._preferred_library = 'shared'
self.shared = shared
self.static = static
+ self.subproject = self.shared.subproject
+
+ def __repr__(self) -> str:
+ return f'<BothLibraries: static={repr(self.static)}; shared={repr(self.shared)}>'
def get_preferred_library(self) -> BuildTarget:
if self._preferred_library == 'shared':
@@ -2167,6 +2174,8 @@ class CommandBase:
cmd = listify(cmd)
final_cmd = []
for c in cmd:
+ if isinstance(c, BothLibraries):
+ c = c.get_preferred_library()
if isinstance(c, str):
final_cmd.append(c)
elif isinstance(c, File):
@@ -2265,6 +2274,7 @@ class CustomTarget(Target, CommandBase):
def process_kwargs(self, kwargs, backend):
self.process_kwargs_base(kwargs)
self.sources = extract_as_list(kwargs, 'input')
+ self.sources = [x.get_preferred_library() if isinstance(x, BothLibraries) else x for x in self.sources]
if 'output' not in kwargs:
raise InvalidArguments('Missing keyword argument "output".')
self.outputs = listify(kwargs['output'])
@@ -2641,6 +2651,8 @@ def get_sources_string_names(sources, backend):
'''
names = []
for s in sources:
+ if isinstance(s, BothLibraries):
+ s = s.get_preferred_library()
if isinstance(s, str):
names.append(s)
elif isinstance(s, (BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList)):
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index e12c697..7240a81 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -29,7 +29,7 @@ from ..interpreterbase import FeatureDeprecated
if T.TYPE_CHECKING:
from ..compilers.compilers import Compiler
from ..environment import Environment
- from ..build import BuildTarget
+ from ..build import BuildTarget, BothLibraries
from ..mesonlib import FileOrString
@@ -222,8 +222,8 @@ class Dependency(HoldableObject):
class InternalDependency(Dependency):
def __init__(self, version: str, incdirs: T.List[str], compile_args: T.List[str],
- link_args: T.List[str], libraries: T.List['BuildTarget'],
- whole_libraries: T.List['BuildTarget'], sources: T.List['FileOrString'],
+ link_args: T.List[str], libraries: T.List[T.Union['BuildTarget', 'BothLibraries']],
+ whole_libraries: T.List[T.Union['BuildTarget', 'BothLibraries']], sources: T.List['FileOrString'],
ext_deps: T.List[Dependency], variables: T.Dict[str, T.Any]):
super().__init__(DependencyTypeName('internal'), {})
self.version = version
@@ -237,6 +237,11 @@ class InternalDependency(Dependency):
self.ext_deps = ext_deps
self.variables = variables
+ # Deal with BothLibraries
+ from ..build import BothLibraries
+ self.libraries = [x.get_preferred_library() if isinstance(x, BothLibraries) else x for x in self.libraries]
+ self.whole_libraries = [x.static if isinstance(x, BothLibraries) else x for x in self.whole_libraries]
+
def __deepcopy__(self, memo: T.Dict[int, 'InternalDependency']) -> 'InternalDependency':
result = self.__class__.__new__(self.__class__)
assert isinstance(result, InternalDependency)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 5be99b4..f1869e3 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -28,7 +28,7 @@ from ..depfile import DepFile
from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typed_kwargs, typed_pos_args
from ..interpreterbase import noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening, unholder_return
from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
-from ..interpreterbase import InterpreterObject, Disabler, disablerIfNotFound
+from ..interpreterbase import Disabler, disablerIfNotFound
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import ObjectHolder, RangeHolder
from ..interpreterbase import TYPE_nkwargs, TYPE_nvar, TYPE_var
@@ -66,7 +66,7 @@ if T.TYPE_CHECKING:
from . import kwargs
# Input source types passed to Targets
- SourceInputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget,
+ SourceInputs = T.Union[mesonlib.File, build.GeneratedList, build.BuildTarget, build.BothLibraries,
build.CustomTargetIndex, build.CustomTarget, build.GeneratedList, str]
# Input source types passed to the build.Target5 classes
SourceOutputs = T.Union[mesonlib.File, build.GeneratedList,
@@ -1407,6 +1407,8 @@ external dependencies (including libraries) must go to "dependencies".''')
# Only store successful lookups
self.store_name_lookups(args)
mlog.log('Program', mlog.bold(progobj.name), 'found:', mlog.green('YES'), *extra_info)
+ if isinstance(progobj, build.Executable):
+ progobj.was_returned_by_find_program = True
return progobj
def program_lookup(self, args, for_machine, required, search_dirs, extra_info):
@@ -2493,6 +2495,8 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey
sources = [sources]
results: T.List['SourceOutputs'] = []
for s in sources:
+ if isinstance(s, build.BothLibraries):
+ s = s.get_preferred_library()
if isinstance(s, str):
self.validate_within_subproject(self.subdir, s)
results.append(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s))
@@ -2658,7 +2662,7 @@ This will become a hard error in the future.''', location=self.current_node)
raise InterpreterException('Tried to add non-existing source file %s.' % s)
# Only permit object extraction from the same subproject
- def validate_extraction(self, buildtarget: InterpreterObject) -> None:
+ def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None:
if self.subproject != buildtarget.subproject:
raise InterpreterException('Tried to extract objects from a different subproject.')
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index 744f69c..261d781 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -807,8 +807,9 @@ class BuildTargetHolder(ObjectHolder[_BuildTarget]):
@noPosargs
@noKwargs
- @FeatureNew('BuildTarget.found', '0.59.0')
def found_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool:
+ if not (isinstance(self.held_object, build.Executable) and self.held_object.was_returned_by_find_program):
+ FeatureNew.single_use('BuildTarget.found', '0.59.0', subproject=self.held_object.subproject)
return True
@noPosargs
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 0ae1c70..51f2e6e 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -480,9 +480,11 @@ class GnomeModule(ExtensionModule):
return cflags, internal_ldflags, external_ldflags, external_ldflags_nodedup, gi_includes
def _unwrap_gir_target(self, girtarget, state):
+ if isinstance(girtarget, build.BothLibraries):
+ girtarget = girtarget.get_preferred_library()
if not isinstance(girtarget, (build.Executable, build.SharedLibrary,
build.StaticLibrary)):
- raise MesonException('Gir target must be an executable or library')
+ raise MesonException(f'Gir target must be an executable or library but is "{girtarget}" of type {type(girtarget).__name__}')
STATIC_BUILD_REQUIRED_VERSION = ">=1.58.1"
if isinstance(girtarget, (build.StaticLibrary)) and \