The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
331 lines
14 KiB
331 lines
14 KiB
9 years ago
|
# Copyright 2015-2016 The Meson development team
|
||
10 years ago
|
|
||
|
# 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.'''
|
||
|
|
||
9 years ago
|
from .. import build
|
||
9 years ago
|
import os, sys
|
||
10 years ago
|
import subprocess
|
||
9 years ago
|
from ..coredata import MesonException
|
||
|
from .. import mlog
|
||
9 years ago
|
import xml.etree.ElementTree as ET
|
||
9 years ago
|
from ..mesonlib import File
|
||
10 years ago
|
|
||
9 years ago
|
girwarning_printed = False
|
||
|
|
||
10 years ago
|
class GnomeModule:
|
||
10 years ago
|
|
||
10 years ago
|
def compile_resources(self, state, args, kwargs):
|
||
|
cmd = ['glib-compile-resources', '@INPUT@', '--generate']
|
||
|
if 'source_dir' in kwargs:
|
||
9 years ago
|
resource_loc = os.path.join(state.subdir, kwargs.pop('source_dir'))
|
||
|
d = os.path.join(state.build_to_src, resource_loc)
|
||
10 years ago
|
cmd += ['--sourcedir', d]
|
||
9 years ago
|
else:
|
||
|
resource_loc = state.subdir
|
||
10 years ago
|
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'
|
||
9 years ago
|
resfile = args[1]
|
||
9 years ago
|
kwargs['depend_files'] = self.parse_gresource_xml(state, resfile, resource_loc)
|
||
9 years ago
|
kwargs['input'] = resfile
|
||
10 years ago
|
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]
|
||
9 years ago
|
|
||
9 years ago
|
def parse_gresource_xml(self, state, fobj, resource_loc):
|
||
9 years ago
|
if isinstance(fobj, File):
|
||
|
fname = fobj.fname
|
||
|
subdir = fobj.subdir
|
||
|
else:
|
||
|
fname = fobj
|
||
|
subdir = state.subdir
|
||
9 years ago
|
abspath = os.path.join(state.environment.source_dir, state.subdir, fname)
|
||
|
relative_part = os.path.split(fname)[0]
|
||
|
try:
|
||
|
tree = ET.parse(abspath)
|
||
|
root = tree.getroot()
|
||
|
result = []
|
||
|
for child in root[0]:
|
||
|
if child.tag != 'file':
|
||
|
mlog.log("Warning, malformed rcc file: ", os.path.join(state.subdir, fname))
|
||
|
break
|
||
|
else:
|
||
9 years ago
|
relfname = os.path.join(resource_loc, child.text)
|
||
9 years ago
|
absfname = os.path.join(state.environment.source_dir, relfname)
|
||
|
if os.path.isfile(absfname):
|
||
|
result.append(relfname)
|
||
|
else:
|
||
|
mlog.log('Warning, resource file points to nonexisting file %s.' % relfname)
|
||
|
return result
|
||
|
except Exception:
|
||
|
return []
|
||
|
|
||
10 years ago
|
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
|
||
10 years ago
|
if not isinstance(girtarget, (build.Executable, build.SharedLibrary)):
|
||
10 years ago
|
raise MesonException('Gir target must be an executable or shared library')
|
||
9 years ago
|
try:
|
||
|
pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0'])
|
||
|
except Exception:
|
||
|
global girwarning_printed
|
||
|
if not girwarning_printed:
|
||
|
mlog.log(mlog.bold('Warning:'), 'gobject-introspection dependency was not found, disabling gir generation.')
|
||
|
girwarning_printed = True
|
||
|
return []
|
||
10 years ago
|
pkgargs = pkgstr.decode().strip().split()
|
||
|
ns = kwargs.pop('namespace')
|
||
|
nsversion = kwargs.pop('nsversion')
|
||
|
libsources = kwargs.pop('sources')
|
||
|
girfile = '%s-%s.gir' % (ns, nsversion)
|
||
10 years ago
|
depends = [girtarget]
|
||
10 years ago
|
|
||
10 years ago
|
scan_command = ['g-ir-scanner', '@INPUT@']
|
||
10 years ago
|
scan_command += pkgargs
|
||
9 years ago
|
scan_command += ['--no-libtool', '--namespace='+ns, '--nsversion=' + nsversion, '--warn-all',
|
||
10 years ago
|
'--output', '@OUTPUT@']
|
||
10 years ago
|
|
||
9 years ago
|
extra_args = kwargs.pop('extra_args', [])
|
||
9 years ago
|
if not isinstance(extra_args, list):
|
||
|
extra_args = [extra_args]
|
||
|
scan_command += extra_args
|
||
|
|
||
10 years ago
|
for incdirs in girtarget.include_dirs:
|
||
|
for incdir in incdirs.get_incdirs():
|
||
|
scan_command += ['-I%s' % os.path.join(state.environment.get_source_dir(), incdir)]
|
||
|
|
||
10 years ago
|
if 'link_with' in kwargs:
|
||
|
link_with = kwargs.pop('link_with')
|
||
9 years ago
|
if not isinstance(link_with, list):
|
||
|
link_with = [link_with]
|
||
10 years ago
|
for link in link_with:
|
||
|
lib = link.held_object
|
||
|
scan_command += ['-l%s' % lib.name]
|
||
|
if isinstance(lib, build.SharedLibrary):
|
||
|
scan_command += ['-L%s' %
|
||
|
os.path.join(state.environment.get_build_dir(),
|
||
|
lib.subdir)]
|
||
|
depends.append(lib)
|
||
|
|
||
10 years ago
|
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')
|
||
10 years ago
|
if state.global_args.get('c'):
|
||
|
scan_command += ['--cflags-begin']
|
||
|
scan_command += state.global_args['c']
|
||
|
scan_command += ['--cflags-end']
|
||
10 years ago
|
if kwargs.get('symbol_prefix'):
|
||
|
sym_prefix = kwargs.pop('symbol_prefix')
|
||
|
if not isinstance(sym_prefix, str):
|
||
|
raise MesonException('Gir symbol prefix must be str')
|
||
|
scan_command += ['--symbol-prefix=%s' % sym_prefix]
|
||
|
if kwargs.get('identifier_prefix'):
|
||
|
identifier_prefix = kwargs.pop('identifier_prefix')
|
||
|
if not isinstance(identifier_prefix, str):
|
||
|
raise MesonException('Gir identifier prefix must be str')
|
||
|
scan_command += ['--identifier-prefix=%s' % identifier_prefix]
|
||
10 years ago
|
if kwargs.get('export_packages'):
|
||
|
pkgs = kwargs.pop('export_packages')
|
||
|
if isinstance(pkgs, str):
|
||
|
scan_command += ['--pkg-export=%s' % pkgs]
|
||
|
elif isinstance(pkgs, list):
|
||
|
scan_command += ['--pkg-export=%s' % pkg for pkg in pkgs]
|
||
|
else:
|
||
|
raise MesonException('Gir export packages must be str or list')
|
||
10 years ago
|
|
||
|
deps = None
|
||
|
if 'dependencies' in kwargs:
|
||
|
deps = kwargs.pop('dependencies')
|
||
|
if not isinstance (deps, list):
|
||
|
deps = [deps]
|
||
|
for dep in deps:
|
||
|
girdir = dep.held_object.get_variable ("girdir")
|
||
|
if girdir:
|
||
|
scan_command += ["--add-include-path=%s" % girdir]
|
||
9 years ago
|
for lib in dep.held_object.libs:
|
||
|
if os.path.isabs(lib) and dep.held_object.is_libtool:
|
||
|
scan_command += ["-L%s" % os.path.dirname(lib)]
|
||
|
libname = os.path.basename(lib)
|
||
|
if libname.startswith("lib"):
|
||
|
libname = libname[3:]
|
||
|
libname = libname.split(".so")[0]
|
||
|
lib = "-l%s" % libname
|
||
|
scan_command += [lib]
|
||
10 years ago
|
|
||
10 years ago
|
inc_dirs = None
|
||
|
if kwargs.get('include_directories'):
|
||
|
inc_dirs = kwargs.pop('include_directories')
|
||
9 years ago
|
if not isinstance(inc_dirs, list):
|
||
|
inc_dirs = [inc_dirs]
|
||
9 years ago
|
for ind in inc_dirs:
|
||
|
if isinstance(ind.held_object, build.IncludeDirs):
|
||
|
scan_command += ['--add-include-path=%s' % inc for inc in ind.held_object.get_incdirs()]
|
||
9 years ago
|
else:
|
||
|
raise MesonException('Gir include dirs should be include_directories()')
|
||
10 years ago
|
if isinstance(girtarget, build.Executable):
|
||
|
scan_command += ['--program', girtarget]
|
||
|
elif isinstance(girtarget, build.SharedLibrary):
|
||
9 years ago
|
scan_command += ["-L@PRIVATE_OUTDIR_ABS_%s@" % girtarget.get_id()]
|
||
10 years ago
|
libname = girtarget.get_basename()
|
||
|
scan_command += ['--library', libname]
|
||
10 years ago
|
scankwargs = {'output' : girfile,
|
||
|
'input' : libsources,
|
||
10 years ago
|
'command' : scan_command,
|
||
10 years ago
|
'depends' : depends,
|
||
10 years ago
|
}
|
||
10 years ago
|
if kwargs.get('install'):
|
||
|
scankwargs['install'] = kwargs['install']
|
||
|
scankwargs['install_dir'] = os.path.join(state.environment.get_datadir(), 'gir-1.0')
|
||
10 years ago
|
scan_target = GirTarget(girfile, state.subdir, scankwargs)
|
||
10 years ago
|
|
||
|
typelib_output = '%s-%s.typelib' % (ns, nsversion)
|
||
|
typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@']
|
||
10 years ago
|
if inc_dirs:
|
||
9 years ago
|
for incd in inc_dirs:
|
||
9 years ago
|
typelib_cmd += ['--includedir=%s' % inc for inc in
|
||
9 years ago
|
incd.held_object.get_incdirs()]
|
||
10 years ago
|
if deps:
|
||
|
for dep in deps:
|
||
|
girdir = dep.held_object.get_variable ("girdir")
|
||
|
if girdir:
|
||
|
typelib_cmd += ["--includedir=%s" % girdir]
|
||
|
|
||
10 years ago
|
kwargs['output'] = typelib_output
|
||
|
kwargs['command'] = typelib_cmd
|
||
10 years ago
|
# 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'
|
||
10 years ago
|
typelib_target = TypelibTarget(typelib_output, state.subdir, kwargs)
|
||
10 years ago
|
return [scan_target, typelib_target]
|
||
|
|
||
10 years ago
|
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
|
||
|
|
||
9 years ago
|
def gtkdoc(self, state, args, kwargs):
|
||
|
if len(args) != 1:
|
||
|
raise MesonException('Gtkdoc must have one positional argument.')
|
||
|
modulename = args[0]
|
||
|
if not isinstance(modulename, str):
|
||
|
raise MesonException('Gtkdoc arg must be string.')
|
||
|
if not 'src_dir' in kwargs:
|
||
|
raise MesonException('Keyword argument src_dir missing.')
|
||
9 years ago
|
main_file = kwargs.get('main_sgml', '')
|
||
|
if not isinstance(main_file, str):
|
||
9 years ago
|
raise MesonException('Main sgml keyword argument must be a string.')
|
||
9 years ago
|
main_xml = kwargs.get('main_xml', '')
|
||
|
if not isinstance(main_xml, str):
|
||
|
raise MesonException('Main xml keyword argument must be a string.')
|
||
|
if main_xml != '':
|
||
|
if main_file != '':
|
||
|
raise MesonException('You can only specify main_xml or main_sgml, not both.')
|
||
|
main_file = main_xml
|
||
9 years ago
|
src_dir = kwargs['src_dir']
|
||
|
targetname = modulename + '-doc'
|
||
|
command = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../gtkdochelper.py"))
|
||
9 years ago
|
if hasattr(src_dir, 'held_object'):
|
||
|
src_dir= src_dir.held_object
|
||
|
if not isinstance(src_dir, build.IncludeDirs):
|
||
|
raise MesonException('Invalidt keyword argument for src_dir.')
|
||
|
incdirs = src_dir.get_incdirs()
|
||
|
if len(incdirs) != 1:
|
||
|
raise MesonException('Argument src_dir has more than one directory specified.')
|
||
|
header_dir = os.path.join(state.environment.get_source_dir(), src_dir.get_curdir(), incdirs[0])
|
||
|
else:
|
||
|
header_dir = os.path.normpath(os.path.join(state.subdir, src_dir))
|
||
9 years ago
|
args = ['--sourcedir=' + state.environment.get_source_dir(),
|
||
|
'--builddir=' + state.environment.get_build_dir(),
|
||
|
'--subdir=' + state.subdir,
|
||
|
'--headerdir=' + header_dir,
|
||
|
'--mainfile=' + main_file,
|
||
|
'--modulename=' + modulename]
|
||
9 years ago
|
args += self.unpack_args('--htmlargs=', 'html_args', kwargs)
|
||
|
args += self.unpack_args('--scanargs=', 'scan_args', kwargs)
|
||
|
res = [build.RunTarget(targetname, command, args, state.subdir)]
|
||
|
if kwargs.get('install', True):
|
||
|
res.append(build.InstallScript([command] + args))
|
||
|
return res
|
||
|
|
||
|
def unpack_args(self, arg, kwarg_name, kwargs):
|
||
9 years ago
|
try:
|
||
9 years ago
|
new_args = kwargs[kwarg_name]
|
||
|
if not isinstance(new_args, list):
|
||
|
new_args = [new_args]
|
||
|
for i in new_args:
|
||
9 years ago
|
if not isinstance(i, str):
|
||
|
raise MesonException('html_args values must be strings.')
|
||
|
except KeyError:
|
||
9 years ago
|
return[]
|
||
9 years ago
|
if len(new_args) > 0:
|
||
|
return [arg + '@@'.join(new_args)]
|
||
9 years ago
|
return []
|
||
9 years ago
|
|
||
10 years ago
|
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')]
|
||
9 years ago
|
cmd += ['--generate-c-code', '@OUTDIR@/' + namebase, '@INPUT@']
|
||
10 years ago
|
outputs = [namebase + '.c', namebase + '.h']
|
||
|
custom_kwargs = {'input' : xml_file,
|
||
|
'output' : outputs,
|
||
|
'command' : cmd
|
||
|
}
|
||
|
return build.CustomTarget(namebase + '-gdbus', state.subdir, custom_kwargs)
|
||
|
|
||
10 years ago
|
def initialize():
|
||
10 years ago
|
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'))
|
||
10 years ago
|
return GnomeModule()
|
||
10 years ago
|
|
||
|
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)
|