mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-24 02:40:26 +01:00
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:
parent
2468850953
commit
b521041eb4
7
demos/glib2/org.gsettings.simple.gschema.xml
Normal file
7
demos/glib2/org.gsettings.simple.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<schemalist>
|
||||
<schema id="org.gsettings.simple">
|
||||
<key name="greeting" type="s">
|
||||
<default>"Hello, world"</default>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
@ -8,6 +8,8 @@ APPNAME='glib2_test'
|
||||
top = '.'
|
||||
out = 'build'
|
||||
|
||||
import os
|
||||
|
||||
def options(opt):
|
||||
opt.load ('compiler_c glib2')
|
||||
|
||||
@ -46,3 +48,10 @@ def build(bld):
|
||||
source = 'org.glib2.test.gresource.xml',
|
||||
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')
|
||||
|
@ -12,6 +12,7 @@ Support for GLib2 tools:
|
||||
"""
|
||||
|
||||
import os
|
||||
import functools
|
||||
from waflib import Context, Task, Utils, Options, Errors, Logs
|
||||
from waflib.TaskGen import taskgen_method, before_method, feature, extension
|
||||
from waflib.Configure import conf
|
||||
@ -303,25 +304,28 @@ def process_settings(self):
|
||||
def compile_schemas_callback(bld):
|
||||
if not bld.is_install:
|
||||
return
|
||||
env = bld.env
|
||||
compile_schemas = Utils.to_list(bld.env.GLIB_COMPILE_SCHEMAS)
|
||||
destdir = Options.options.destdir
|
||||
paths = bld._compile_schemas_registered
|
||||
if destdir:
|
||||
path = os.path.join(destdir, env.GSETTINGSSCHEMADIR.lstrip(os.sep))
|
||||
else:
|
||||
path = env.GSETTINGSSCHEMADIR
|
||||
Logs.pprint('YELLOW', 'Updating GSettings schema cache %r' % path)
|
||||
command = Utils.to_list(env.GLIB_COMPILE_SCHEMAS) + [path]
|
||||
self.bld.exec_command(command)
|
||||
paths = (os.path.join(destdir, path.lstrip(os.sep)) for path in paths)
|
||||
for path in paths:
|
||||
Logs.pprint('YELLOW', 'Updating GSettings schema cache %r' % path)
|
||||
if self.bld.exec_command(compile_schemas + [path]):
|
||||
Logs.warn('Could not update GSettings schema cache %r' % path)
|
||||
|
||||
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)')
|
||||
|
||||
if install_files:
|
||||
self.add_install_files(install_to=self.env.GSETTINGSSCHEMADIR, install_from=install_files)
|
||||
if not hasattr(self.bld, '_compile_schemas_registered'):
|
||||
self.add_install_files(install_to=schemadir, install_from=install_files)
|
||||
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._compile_schemas_registered = True
|
||||
registered_schemas.add(schemadir)
|
||||
|
||||
class glib_validate_schema(Task.Task):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user