Allow multiple source_dir in GResource

There are use case where one may want to specify --sourcedir option
multiple times to glib-compile-resources, which will look for
resources in every specified directory.

By doing this, we also need to get rid of the manual GResource XML
parsing and we opted to use the glib-compile-resources command with
the --generate-dependencies option. This command will solve the
multiple source_dir case for us.
pull/381/head
Damián Nohales 9 years ago
parent 6a3e29ccd4
commit b91662a903
  1. 73
      mesonbuild/modules/gnome.py

@ -20,63 +20,54 @@ 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
kwargs['input'] = args[1]
output_c = args[0] + '.c' output_c = args[0] + '.c'
output_h = args[0] + '.h' output_h = args[0] + '.h'
resfile = args[1]
kwargs['depend_files'] = self.parse_gresource_xml(state, resfile, resource_loc)
kwargs['input'] = resfile
kwargs['output'] = output_c kwargs['output'] = output_c
target_c = build.CustomTarget(args[0]+'_c', state.subdir, kwargs) target_c = build.CustomTarget(args[0]+'_c', state.subdir, kwargs)
kwargs['output'] = output_h 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 +194,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