Skip to content

Commit

Permalink
gnome: Added 'executable' method for GTK Android
Browse files Browse the repository at this point in the history
gnome.executable takes in the same arguments as mesons own executable,
but it automatically builds a shared library on android and links it
with gtk4-android-glue.
  • Loading branch information
sp1ritCS committed Nov 25, 2024
1 parent 9f3f88f commit 9f54498
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/markdown/Gnome-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,11 @@ It takes the following keyword arguments:
MIME types handled by desktop files in `<prefix>/<datadir>/applications`.
- `update_mime_database`: *Since 0.64.0* If set to `true`, update cache of
MIME types in `<prefix>/<datadir>/mime`.

### gnome.executable()

*Since 1.7.0*

Wrapper for executable explicitly targeting applications utilizing GTK. It
takes the same arguments as
[executable](Reference-manual_functions.md#executable).
2 changes: 1 addition & 1 deletion mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,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:
Expand Down
6 changes: 6 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3362,6 +3362,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]]
Expand Down
24 changes: 24 additions & 0 deletions mesonbuild/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand Down
25 changes: 23 additions & 2 deletions mesonbuild/modules/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9f54498

Please sign in to comment.