diff --git a/docs/markdown/Gnome-module.md b/docs/markdown/Gnome-module.md index 013e8c8241ce..169d722760e9 100644 --- a/docs/markdown/Gnome-module.md +++ b/docs/markdown/Gnome-module.md @@ -429,3 +429,11 @@ It takes the following keyword arguments: MIME types handled by desktop files in `//applications`. - `update_mime_database`: *Since 0.64.0* If set to `true`, update cache of MIME types in `//mime`. + +### gnome.executable() + +*Since 1.6.0* + +Wrapper for executable explicitly targeting applications utilizing GTK. It +takes the same arguments as +[executable](Reference-manual_functions.md#executable). diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 460ed549be92..feca76ef76f3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1338,7 +1338,7 @@ def get_pch(self, language: str) -> T.List[str]: def get_include_dirs(self) -> T.List['IncludeDirs']: return self.include_dirs - def add_deps(self, deps): + def add_deps(self, deps: T.Sequence[dependencies.Dependency]): deps = listify(deps) for dep in deps: if dep in self.added_deps: diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index ecc5bfc2d7b4..ee8b5ca20471 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3357,6 +3357,12 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargsType], kwargs: kwtypes.Jar, targetclass: T.Type[build.Jar]) -> build.Jar: ... + @T.overload + def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargsType], + kwargs: T.Union[kwtypes.Executable, kwtypes.StaticLibrary, kwtypes.SharedLibrary, kwtypes.SharedModule, kwtypes.Jar], + targetclass: T.Type[T.Union[build.Executable, build.StaticLibrary, build.SharedModule, build.SharedLibrary, build.Jar]] + ) -> T.Union[build.Executable, build.StaticLibrary, build.SharedModule, build.SharedLibrary, build.Jar]: ... + def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargsType], kwargs: T.Union[kwtypes.Executable, kwtypes.StaticLibrary, kwtypes.SharedLibrary, kwtypes.SharedModule, kwtypes.Jar], targetclass: T.Type[T.Union[build.Executable, build.StaticLibrary, build.SharedModule, build.SharedLibrary, build.Jar]] diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 86dc8762e65a..59d542a130b9 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -15,8 +15,10 @@ from ..programs import ExternalProgram if T.TYPE_CHECKING: + from ..interpreter import kwargs as kwtypes from ..interpreter import Interpreter from ..interpreter.interpreter import ProgramVersionFunc + from ..interpreter.type_checking import SourcesVarargsType from ..interpreterbase import TYPE_var, TYPE_kwargs from ..programs import OverrideProgram from ..dependencies import Dependency @@ -157,6 +159,28 @@ def process_include_dirs(self, dirs: T.Iterable[T.Union[str, IncludeDirs]]) -> T def add_language(self, lang: str, for_machine: MachineChoice) -> None: self._interpreter.add_languages([lang], True, for_machine) + @T.overload + def add_target(self, args: T.Tuple[str, SourcesVarargsType], + kwargs: kwtypes.Executable, targetclass: T.Type[build.Executable]) -> build.Executable: ... + + @T.overload + def add_target(self, args: T.Tuple[str, SourcesVarargsType], + kwargs: kwtypes.StaticLibrary, targetclass: T.Type[build.StaticLibrary]) -> build.StaticLibrary: ... + + @T.overload + def add_target(self, args: T.Tuple[str, SourcesVarargsType], + kwargs: kwtypes.SharedModule, targetclass: T.Type[build.SharedModule]) -> build.SharedModule: ... + + @T.overload + def add_target(self, args: T.Tuple[str, SourcesVarargsType], + kwargs: kwtypes.SharedLibrary, targetclass: T.Type[build.SharedLibrary]) -> build.SharedLibrary: ... + + def add_target(self, args: T.Tuple[str, SourcesVarargsType], + kwargs: T.Union[kwtypes.Executable, kwtypes.StaticLibrary, kwtypes.SharedLibrary, kwtypes.SharedModule, kwtypes.Jar], + targetclass: T.Type[T.Union[build.Executable, build.StaticLibrary, build.SharedModule, build.SharedLibrary, build.Jar]] + ) -> T.Union[build.Executable, build.StaticLibrary, build.SharedModule, build.SharedLibrary, build.Jar]: + return self._interpreter.build_target(self.current_node, args, kwargs, targetclass) + class ModuleObject(HoldableObject): """Base class for all objects returned by modules """ diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e0c1214d0851..e8c432c4de52 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -24,8 +24,8 @@ from ..build import CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments from ..dependencies import Dependency, InternalDependency from ..dependencies.pkgconfig import PkgConfigDependency, PkgConfigInterface -from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, ENV_KW, INSTALL_DIR_KW, INSTALL_KW, NoneType, DEPENDENCY_SOURCES_KW, in_set_validator -from ..interpreterbase import noPosargs, noKwargs, FeatureNew, FeatureDeprecated +from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, ENV_KW, EXECUTABLE_KWS, INSTALL_DIR_KW, INSTALL_KW, SOURCES_VARARGS, NoneType, DEPENDENCY_SOURCES_KW, in_set_validator +from ..interpreterbase import noPosargs, noKwargs, permittedKwargs, FeatureNew, FeatureDeprecated from ..interpreterbase import typed_kwargs, KwargInfo, ContainerTypeInfo from ..interpreterbase.decorators import typed_pos_args from ..mesonlib import ( @@ -41,7 +41,9 @@ from . import ModuleState from ..build import BuildTarget from ..compilers import Compiler + from ..interpreter import kwargs as kwtypes from ..interpreter import Interpreter + from ..interpreter.type_checking import SourcesVarargsType from ..interpreterbase import TYPE_var, TYPE_kwargs from ..mesonlib import FileOrString from ..programs import ExternalProgram @@ -274,6 +276,7 @@ def __init__(self, interpreter: 'Interpreter') -> None: 'mkenums_simple': self.mkenums_simple, 'genmarshal': self.genmarshal, 'generate_vapi': self.generate_vapi, + 'executable': self.executable, }) def _get_native_glib_version(self, state: 'ModuleState') -> str: @@ -2205,6 +2208,24 @@ def generate_vapi(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gener created_values.append(rv) return ModuleReturnValue(rv, created_values) + @permittedKwargs(build.known_exe_kwargs) + @typed_pos_args('gnome.executable', str, varargs=SOURCES_VARARGS) + @typed_kwargs('gnome.executable', *EXECUTABLE_KWS, allow_unknown=True) + def executable(self, state: 'ModuleState', args: T.Tuple[str, SourcesVarargsType], kwargs: kwtypes.Executable) -> ModuleReturnValue: + target: T.Union[build.Executable, build.SharedLibrary] + if state.environment.machines.host.is_android(): + kwargs["gui_app"] = None + kwargs["win_subsystem"] = None + if T.TYPE_CHECKING: + target = state.add_target(args, T.cast(kwtypes.SharedLibrary, kwargs), build.SharedLibrary) + else: + target = state.add_target(args, kwargs, build.SharedLibrary) + glue = state.dependency('gtk4-android-glue') + target.add_deps([glue]) + else: + target = state.add_target(args, kwargs, build.Executable) + return ModuleReturnValue(target, []) + def initialize(interp: 'Interpreter') -> GnomeModule: mod = GnomeModule(interp) mod.interpreter.append_holder_map(GResourceTarget, interpreter.CustomTargetHolder)