glib2: Compile schemas per directory (#1881)

* glib2: Compile schemas per directory

By changing GSETTINGSSCHEMADIR during the build setup or on single tasks
or generators, the user may place schemas in various locations. Adding a
post build function for each of this location compiles all of them
instead of only one global directory.

* glib2: Notify user about failed schema compilation

* glib2: Demo schemas installed to multiple places

A new schema lacking lacking any enumerations was introduced. Installing
it isolated simplifies the generator creation to the essential
components demonstrated.
This commit is contained in:
dffischer 2016-12-22 18:31:07 +01:00 committed by Thomas Nagy
parent 2468850953
commit b521041eb4
3 changed files with 31 additions and 11 deletions

View File

@ -0,0 +1,7 @@
<schemalist>
<schema id="org.gsettings.simple">
<key name="greeting" type="s">
<default>"Hello, world"</default>
</key>
</schema>
</schemalist>

View File

@ -8,6 +8,8 @@ APPNAME='glib2_test'
top = '.' top = '.'
out = 'build' out = 'build'
import os
def options(opt): def options(opt):
opt.load ('compiler_c glib2') opt.load ('compiler_c glib2')
@ -46,3 +48,10 @@ def build(bld):
source = 'org.glib2.test.gresource.xml', source = 'org.glib2.test.gresource.xml',
install_path = 'lib/glib2_test' install_path = 'lib/glib2_test'
) )
# Install a schema to a different location.
# It will be compiled to a cache file besides it.
bld(
features = 'glib2',
settings_schema_files = ['org.gsettings.simple.gschema.xml']
).env.GSETTINGSSCHEMADIR = os.path.join('etc', 'glib-2.0', 'schemas')

View File

@ -12,6 +12,7 @@ Support for GLib2 tools:
""" """
import os import os
import functools
from waflib import Context, Task, Utils, Options, Errors, Logs from waflib import Context, Task, Utils, Options, Errors, Logs
from waflib.TaskGen import taskgen_method, before_method, feature, extension from waflib.TaskGen import taskgen_method, before_method, feature, extension
from waflib.Configure import conf from waflib.Configure import conf
@ -303,25 +304,28 @@ def process_settings(self):
def compile_schemas_callback(bld): def compile_schemas_callback(bld):
if not bld.is_install: if not bld.is_install:
return return
env = bld.env compile_schemas = Utils.to_list(bld.env.GLIB_COMPILE_SCHEMAS)
destdir = Options.options.destdir destdir = Options.options.destdir
paths = bld._compile_schemas_registered
if destdir: if destdir:
path = os.path.join(destdir, env.GSETTINGSSCHEMADIR.lstrip(os.sep)) paths = (os.path.join(destdir, path.lstrip(os.sep)) for path in paths)
else: for path in paths:
path = env.GSETTINGSSCHEMADIR Logs.pprint('YELLOW', 'Updating GSettings schema cache %r' % path)
Logs.pprint('YELLOW', 'Updating GSettings schema cache %r' % path) if self.bld.exec_command(compile_schemas + [path]):
command = Utils.to_list(env.GLIB_COMPILE_SCHEMAS) + [path] Logs.warn('Could not update GSettings schema cache %r' % path)
self.bld.exec_command(command)
if self.bld.is_install: if self.bld.is_install:
if not self.env.GSETTINGSSCHEMADIR: schemadir = self.env.GSETTINGSSCHEMADIR
if not schemadir:
raise Errors.WafError ('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)') raise Errors.WafError ('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)')
if install_files: if install_files:
self.add_install_files(install_to=self.env.GSETTINGSSCHEMADIR, install_from=install_files) self.add_install_files(install_to=schemadir, install_from=install_files)
if not hasattr(self.bld, '_compile_schemas_registered'): registered_schemas = getattr(self.bld, '_compile_schemas_registered', None)
if not registered_schemas:
registered_schemas = self.bld._compile_schemas_registered = set()
self.bld.add_post_fun(compile_schemas_callback) self.bld.add_post_fun(compile_schemas_callback)
self.bld._compile_schemas_registered = True registered_schemas.add(schemadir)
class glib_validate_schema(Task.Task): class glib_validate_schema(Task.Task):
""" """