|
|
|
# Copyright 2015 The Meson development team
|
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
'''This module provides helper functions for Gnome/GLib related
|
|
|
|
functionality such as gobject-introspection and gresources.'''
|
|
|
|
|
|
|
|
import build
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from coredata import MesonException
|
|
|
|
import mlog
|
|
|
|
|
|
|
|
class GnomeModule:
|
|
|
|
|
|
|
|
def compile_resources(self, state, args, kwargs):
|
|
|
|
cmd = ['glib-compile-resources', '@INPUT@', '--generate']
|
|
|
|
if 'source_dir' in kwargs:
|
|
|
|
d = os.path.join(state.build_to_src, state.subdir, kwargs.pop('source_dir'))
|
|
|
|
cmd += ['--sourcedir', d]
|
|
|
|
if 'c_name' in kwargs:
|
|
|
|
cmd += ['--c-name', kwargs.pop('c_name')]
|
|
|
|
cmd += ['--target', '@OUTPUT@']
|
|
|
|
kwargs['command'] = cmd
|
|
|
|
output_c = args[0] + '.c'
|
|
|
|
output_h = args[0] + '.h'
|
|
|
|
kwargs['input'] = args[1]
|
|
|
|
kwargs['output'] = output_c
|
|
|
|
target_c = build.CustomTarget(args[0]+'_c', state.subdir, kwargs)
|
|
|
|
kwargs['output'] = output_h
|
|
|
|
target_h = build.CustomTarget(args[0] + '_h', state.subdir, kwargs)
|
|
|
|
return [target_c, target_h]
|
|
|
|
|
|
|
|
def generate_gir(self, state, args, kwargs):
|
|
|
|
if len(args) != 1:
|
|
|
|
raise MesonException('Gir takes one argument')
|
|
|
|
girtarget = args[0]
|
|
|
|
while hasattr(girtarget, 'held_object'):
|
|
|
|
girtarget = girtarget.held_object
|
|
|
|
if not (isinstance(girtarget, build.Executable) or isinstance(girtarget, build.SharedLibrary)):
|
|
|
|
raise MesonException('Gir target must be an executable or shared library')
|
|
|
|
pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0'])
|
|
|
|
pkgargs = pkgstr.decode().strip().split()
|
|
|
|
ns = kwargs.pop('namespace')
|
|
|
|
nsversion = kwargs.pop('nsversion')
|
|
|
|
libsources = kwargs.pop('sources')
|
|
|
|
girfile = '%s-%s.gir' % (ns, nsversion)
|
|
|
|
scan_command = ['g-ir-scanner', '@INPUT@']
|
|
|
|
scan_command += pkgargs
|
|
|
|
scan_command += ['--namespace='+ns, '--nsversion=' + nsversion,
|
|
|
|
'--output', '@OUTPUT@']
|
|
|
|
if 'includes' in kwargs:
|
|
|
|
includes = kwargs.pop('includes')
|
|
|
|
if isinstance(includes, str):
|
|
|
|
scan_command += ['--include=%s' % includes]
|
|
|
|
elif isinstance(includes, list):
|
|
|
|
scan_command += ['--include=%s' % inc for inc in includes]
|
|
|
|
else:
|
|
|
|
raise MesonException('Gir includes must be str or list')
|
|
|
|
if state.global_args.get('c'):
|
|
|
|
scan_command += ['--cflags-begin']
|
|
|
|
scan_command += state.global_args['c']
|
|
|
|
scan_command += ['--cflags-end']
|
|
|
|
if isinstance(girtarget, build.Executable):
|
|
|
|
scan_command += ['--program', girtarget]
|
|
|
|
elif isinstance(girtarget, build.SharedLibrary):
|
|
|
|
scan_command += ['--library', girtarget.get_basename()]
|
|
|
|
scankwargs = {'output' : girfile,
|
|
|
|
'input' : libsources,
|
|
|
|
'command' : scan_command}
|
|
|
|
if kwargs.get('install'):
|
|
|
|
scankwargs['install'] = kwargs['install']
|
|
|
|
scankwargs['install_dir'] = os.path.join(state.environment.get_datadir(), 'gir-1.0')
|
|
|
|
scan_target = GirTarget(girfile, state.subdir, scankwargs)
|
|
|
|
|
|
|
|
typelib_output = '%s-%s.typelib' % (ns, nsversion)
|
|
|
|
typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@']
|
|
|
|
kwargs['output'] = typelib_output
|
|
|
|
kwargs['command'] = typelib_cmd
|
|
|
|
# Note that this can't be libdir, because e.g. on Debian it points to
|
|
|
|
# lib/x86_64-linux-gnu but the girepo dir is always under lib.
|
|
|
|
kwargs['install_dir'] = 'lib/girepository-1.0'
|
|
|
|
typelib_target = TypelibTarget(typelib_output, state.subdir, kwargs)
|
|
|
|
return [scan_target, typelib_target]
|
|
|
|
|
|
|
|
def compile_schemas(self, state, args, kwargs):
|
|
|
|
if len(args) != 0:
|
|
|
|
raise MesonException('Compile_schemas does not take positional arguments.')
|
|
|
|
srcdir = os.path.join(state.build_to_src, state.subdir)
|
|
|
|
outdir = state.subdir
|
|
|
|
cmd = ['glib-compile-schemas', '--targetdir', outdir, srcdir]
|
|
|
|
kwargs['command'] = cmd
|
|
|
|
kwargs['input'] = []
|
|
|
|
kwargs['output'] = 'gschemas.compiled'
|
|
|
|
if state.subdir == '':
|
|
|
|
targetname = 'gsettings-compile'
|
|
|
|
else:
|
|
|
|
targetname = 'gsettings-compile-' + state.subdir
|
|
|
|
target_g = build.CustomTarget(targetname, state.subdir, kwargs)
|
|
|
|
return target_g
|
|
|
|
|
|
|
|
def gdbus_codegen(self, state, args, kwargs):
|
|
|
|
if len(args) != 2:
|
|
|
|
raise MesonException('Gdbus_codegen takes two arguments, name and xml file.')
|
|
|
|
namebase = args[0]
|
|
|
|
xml_file = args[1]
|
|
|
|
cmd = ['gdbus-codegen']
|
|
|
|
if 'interface_prefix' in kwargs:
|
|
|
|
cmd += ['--interface-prefix', kwargs.pop('interface_prefix')]
|
|
|
|
if 'namespace' in kwargs:
|
|
|
|
cmd += ['--c-namespace', kwargs.pop('namespace')]
|
|
|
|
cmd += ['--generate-c-code', os.path.join(state.subdir, namebase), '@INPUT@']
|
|
|
|
outputs = [namebase + '.c', namebase + '.h']
|
|
|
|
custom_kwargs = {'input' : xml_file,
|
|
|
|
'output' : outputs,
|
|
|
|
'command' : cmd
|
|
|
|
}
|
|
|
|
return build.CustomTarget(namebase + '-gdbus', state.subdir, custom_kwargs)
|
|
|
|
|
|
|
|
def initialize():
|
|
|
|
mlog.log('Warning, glib compiled dependencies will not work until this upstream issue is fixed:',
|
|
|
|
mlog.bold('https://bugzilla.gnome.org/show_bug.cgi?id=745754'))
|
|
|
|
return GnomeModule()
|
|
|
|
|
|
|
|
class GirTarget(build.CustomTarget):
|
|
|
|
def __init__(self, name, subdir, kwargs):
|
|
|
|
super().__init__(name, subdir, kwargs)
|
|
|
|
|
|
|
|
class TypelibTarget(build.CustomTarget):
|
|
|
|
def __init__(self, name, subdir, kwargs):
|
|
|
|
super().__init__(name, subdir, kwargs)
|