From a16463972dbbc7c944dbbfbee57ade758e3077da Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 26 Oct 2015 21:12:22 +0200 Subject: [PATCH] Parse contents of gresource xml and add deps manually. A bit of a hack but necessary due to missing upstream functionality. Closes #298. --- build.py | 14 +++++++++++++- modules/gnome.py | 30 ++++++++++++++++++++++++++++-- modules/qt5.py | 2 +- ninjabackend.py | 9 +++++++-- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/build.py b/build.py index 8b372f372..4da3665e3 100644 --- a/build.py +++ b/build.py @@ -711,13 +711,16 @@ class CustomTarget: 'install' : True, 'install_dir' : True, 'build_always' : True, - 'depends' : True} + 'depends' : True, + 'depend_files' : True, + } def __init__(self, name, subdir, kwargs): self.name = name self.subdir = subdir self.dependencies = [] self.extra_depends = [] + self.depend_files = [] # Files that this target depends on but are not on the command line. self.process_kwargs(kwargs) self.extra_files = [] self.install_rpath = '' @@ -795,6 +798,15 @@ class CustomTarget: if not isinstance(ed, CustomTarget) and not isinstance(ed, BuildTarget): raise InvalidArguments('Can only depend on toplevel targets.') self.extra_depends.append(ed) + depend_files = kwargs.get('depend_files', []) + if not isinstance(depend_files, list): + depend_files = [depend_files] + for i in depend_files: + if isinstance(i, (File, str)): + self.depend_files.append(i) + else: + mlog.debug(i) + raise InvalidArguments('Unknown type in depend_files.') def get_basename(self): return self.name diff --git a/modules/gnome.py b/modules/gnome.py index f126bcf2c..f5537a4a9 100644 --- a/modules/gnome.py +++ b/modules/gnome.py @@ -20,6 +20,7 @@ import os, sys import subprocess from coredata import MesonException import mlog +import xml.etree.ElementTree as ET girwarning_printed = False @@ -36,13 +37,38 @@ class GnomeModule: kwargs['command'] = cmd output_c = args[0] + '.c' output_h = args[0] + '.h' - kwargs['input'] = args[1] + resfile = args[1] + kwargs['depend_files'] = self.parse_gresource_xml(state, resfile) + 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) return [target_c, target_h] - + + def parse_gresource_xml(self, state, fname): + abspath = os.path.join(state.environment.source_dir, state.subdir, fname) + relative_part = os.path.split(fname)[0] + resdir = os.path.join(state.subdir, 'data') + 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: + relfname = os.path.join(resdir, 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): if len(args) != 1: raise MesonException('Gir takes one argument') diff --git a/modules/qt5.py b/modules/qt5.py index d9414399e..0e732a192 100644 --- a/modules/qt5.py +++ b/modules/qt5.py @@ -19,7 +19,7 @@ from coredata import MesonException import xml.etree.ElementTree as ET class Qt5Module(): - + def __init__(self): mlog.log('Detecting Qt tools.') # The binaries have different names on different diff --git a/ninjabackend.py b/ninjabackend.py index f948328ae..2da9861f8 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -300,10 +300,15 @@ class NinjaBackend(backends.Backend): srcs.append(os.path.join(self.build_to_src, target.subdir, i)) else: srcs.append(i.rel_to_builddir(self.build_to_src)) - deps += srcs if target.build_always: deps.append('PHONY') - elem = NinjaBuildElement(ofilenames, 'CUSTOM_COMMAND', deps) + elem = NinjaBuildElement(ofilenames, 'CUSTOM_COMMAND', srcs) + for i in target.depend_files: + if isinstance(i, mesonlib.File): + deps.append(i.rel_to_builddir(self.build_to_src)) + else: + deps.append(os.path.join(self.build_to_src, i)) + elem.add_dep(deps) for d in target.extra_depends: tmp = d.get_filename() if not isinstance(tmp, list):