Merge pull request #381 from dnohales/gresource_multi_sourcedir

Allow multiple source_dir in GResource
pull/386/head
Jussi Pakkanen 9 years ago
commit 72a94c13f2
  1. 1
      authors.txt
  2. 81
      mesonbuild/modules/gnome.py

@ -27,3 +27,4 @@ Wink Saville
Yoav Alon Yoav Alon
Martin Ejdestig Martin Ejdestig
Rémi Nicole Rémi Nicole
Damián Nohales

@ -20,63 +20,52 @@ import os, sys
import subprocess import subprocess
from ..coredata import MesonException from ..coredata import MesonException
from .. import mlog from .. import mlog
import xml.etree.ElementTree as ET
from ..mesonlib import File
girwarning_printed = False girwarning_printed = False
class GnomeModule: class GnomeModule:
def compile_resources(self, state, args, kwargs): def compile_resources(self, state, args, kwargs):
cmd = ['glib-compile-resources', '@INPUT@', '--generate'] cmd = ['glib-compile-resources', '@INPUT@']
if 'source_dir' in kwargs:
resource_loc = os.path.join(state.subdir, kwargs.pop('source_dir')) source_dirs = kwargs.pop('source_dir', [])
d = os.path.join(state.build_to_src, resource_loc) if not isinstance(source_dirs, list):
cmd += ['--sourcedir', d] source_dirs = [source_dirs]
else:
resource_loc = state.subdir kwargs['depend_files'] = self.get_gresource_dependencies(state, args[1], source_dirs)
for source_dir in source_dirs:
sourcedir = os.path.join(state.build_to_src, state.subdir, source_dir)
cmd += ['--sourcedir', sourcedir]
if 'c_name' in kwargs: if 'c_name' in kwargs:
cmd += ['--c-name', kwargs.pop('c_name')] cmd += ['--c-name', kwargs.pop('c_name')]
cmd += ['--target', '@OUTPUT@'] cmd += ['--generate', '--target', '@OUTPUT@']
kwargs['command'] = cmd kwargs['command'] = cmd
output_c = args[0] + '.c' kwargs['input'] = args[1]
output_h = args[0] + '.h' kwargs['output'] = args[0] + '.c'
resfile = args[1] target_c = build.CustomTarget(args[0] + '_c', state.subdir, kwargs)
kwargs['depend_files'] = self.parse_gresource_xml(state, resfile, resource_loc) kwargs['output'] = args[0] + '.h'
kwargs['input'] = resfile
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) target_h = build.CustomTarget(args[0] + '_h', state.subdir, kwargs)
return [target_c, target_h] return [target_c, target_h]
def parse_gresource_xml(self, state, fobj, resource_loc): def get_gresource_dependencies(self, state, input_file, source_dirs):
if isinstance(fobj, File): cmd = ['glib-compile-resources',
fname = fobj.fname os.path.join(state.subdir, input_file),
subdir = fobj.subdir '--generate-dependencies']
else:
fname = fobj for source_dir in source_dirs:
subdir = state.subdir cmd += ['--sourcedir', os.path.join(state.subdir, source_dir)]
abspath = os.path.join(state.environment.source_dir, state.subdir, fname)
relative_part = os.path.split(fname)[0] pc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True,
try: cwd=state.environment.get_source_dir())
tree = ET.parse(abspath) (stdout, _) = pc.communicate()
root = tree.getroot() if pc.returncode != 0:
result = [] mlog.log(mlog.bold('Warning:'), 'glib-compile-resources has failed to get the dependencies for {}'.format(cmd[1]))
for child in root[0]: raise subprocess.CalledProcessError(pc.returncode, cmd)
if child.tag != 'file':
mlog.log("Warning, malformed rcc file: ", os.path.join(state.subdir, fname)) return stdout.split('\n')[:-1]
break
else:
relfname = os.path.join(resource_loc, child.text)
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 []
def generate_gir(self, state, args, kwargs): def generate_gir(self, state, args, kwargs):
if len(args) != 1: if len(args) != 1:
@ -203,7 +192,7 @@ class GnomeModule:
scankwargs['install'] = kwargs['install'] scankwargs['install'] = kwargs['install']
scankwargs['install_dir'] = os.path.join(state.environment.get_datadir(), 'gir-1.0') scankwargs['install_dir'] = os.path.join(state.environment.get_datadir(), 'gir-1.0')
scan_target = GirTarget(girfile, state.subdir, scankwargs) scan_target = GirTarget(girfile, state.subdir, scankwargs)
typelib_output = '%s-%s.typelib' % (ns, nsversion) typelib_output = '%s-%s.typelib' % (ns, nsversion)
typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@'] typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@']
if inc_dirs: if inc_dirs:

Loading…
Cancel
Save