Modularize the tools 'glib2' and 'intltool'.

In some scenarios only some components of the glib2 tool are
necessary; for example, if intltool-merge is only used for
creating localized desktop files, it's not useful on Windows.

Rewrite the configuration function of the tools into several methods,
so that the 'funs' parameter can be used to only configure
specific programs from the tools.
This commit is contained in:
Krzysztof Kosiński 2014-01-27 02:32:09 +01:00
parent d4b2f086a1
commit 47bd581246
2 changed files with 50 additions and 28 deletions

View File

@ -13,6 +13,7 @@ Support for GLib2 tools:
import os
from waflib import Task, Utils, Options, Errors, Logs
from waflib.TaskGen import taskgen_method, before_method, after_method, feature
from waflib.Configure import conf
################## marshal files
@ -339,23 +340,21 @@ class glib_validate_schema(Task.Task):
run_str = 'rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}'
color = 'PINK'
def configure(conf):
"""
Find the following programs:
* *glib-genmarshal* and set *GLIB_GENMARSHAL*
* *glib-mkenums* and set *GLIB_MKENUMS*
* *glib-compile-schemas* and set *GLIB_COMPILE_SCHEMAS* (not mandatory)
And set the variable *GSETTINGSSCHEMADIR*
"""
@conf
def find_glib_genmarshal(conf):
conf.find_program('glib-genmarshal', var='GLIB_GENMARSHAL')
conf.find_program('perl', var='PERL')
@conf
def find_glib_mkenums(conf):
if not conf.env.PERL:
conf.find_program('perl', var='PERL')
conf.find_program('glib-mkenums', interpreter='PERL', var='GLIB_MKENUMS')
@conf
def find_glib_compile_schemas(conf):
# when cross-compiling, gsettings.m4 locates the program with the following:
# pkg-config --variable glib_compile_schemas gio-2.0
conf.find_program('glib-compile-schemas', var='GLIB_COMPILE_SCHEMAS', mandatory=False)
conf.find_program('glib-compile-schemas', var='GLIB_COMPILE_SCHEMAS')
def getstr(varname):
return getattr(Options.options, varname, getattr(conf.env,varname, ''))
@ -371,6 +370,20 @@ def configure(conf):
conf.env['GSETTINGSSCHEMADIR'] = gsettingsschemadir
def configure(conf):
"""
Find the following programs:
* *glib-genmarshal* and set *GLIB_GENMARSHAL*
* *glib-mkenums* and set *GLIB_MKENUMS*
* *glib-compile-schemas* and set *GLIB_COMPILE_SCHEMAS* (not mandatory)
And set the variable *GSETTINGSSCHEMADIR*
"""
conf.find_glib_genmarshal()
conf.find_glib_mkenums()
conf.find_glib_compile_schemas(mandatory=False)
def options(opt):
"""
Add the ``--gsettingsschemadir`` command-line option

View File

@ -29,8 +29,18 @@ Usage of the :py:mod:`waflib.Tools.gnu_dirs` is recommended, but not obligatory.
import os, re
from waflib import Configure, TaskGen, Task, Utils, Runner, Options, Build, Logs
import waflib.Tools.ccroot
from waflib.TaskGen import feature, before_method
from waflib.TaskGen import feature, before_method, taskgen_method
from waflib.Logs import error
from waflib.Configure import conf
@taskgen_method
def ensure_localedir(self):
# use the tool gnu_dirs to provide options to define this
if not self.env.LOCALEDIR:
if self.env.DATAROOTDIR:
self.env.LOCALEDIR = os.path.join(self.env.DATAROOTDIR, 'locale')
else:
self.env.LOCALEDIR = os.path.join(self.env.PREFIX, 'share', 'locale')
@before_method('process_source')
@feature('intltool_in')
@ -59,8 +69,7 @@ def apply_intltool_in_f(self):
try: self.meths.remove('process_source')
except ValueError: pass
if not self.env.LOCALEDIR:
self.env.LOCALEDIR = self.env.PREFIX + '/share/locale'
self.ensure_localedir()
for i in self.to_list(self.source):
node = self.path.find_resource(i)
@ -103,8 +112,7 @@ def apply_intltool_po(self):
try: self.meths.remove('process_source')
except ValueError: pass
if not self.env.LOCALEDIR:
self.env.LOCALEDIR = self.env.PREFIX + '/share/locale'
self.ensure_localedir()
appname = getattr(self, 'appname', 'set_your_app_name')
podir = getattr(self, 'podir', '')
@ -150,6 +158,16 @@ class intltool(Task.Task):
run_str = '${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}'
color = 'BLUE'
@conf
def find_msgfmt(conf):
conf.find_program('msgfmt', var='MSGFMT')
@conf
def find_intltool_merge(conf):
if not conf.env.PERL:
conf.find_program('perl', var='PERL')
conf.find_program('intltool-merge', interpreter='PERL', var='INTLTOOL')
def configure(conf):
"""
Detect the program *msgfmt* and set *conf.env.MSGFMT*.
@ -160,17 +178,8 @@ def configure(conf):
If a C/C++ compiler is present, execute a compilation test to find the header *locale.h*.
"""
conf.find_program('msgfmt', var='MSGFMT')
conf.find_program('perl', var='PERL')
conf.find_program('intltool-merge', interpreter='PERL', var='INTLTOOL')
prefix = conf.env.PREFIX
datadir = conf.env.DATADIR
if not datadir:
datadir = os.path.join(prefix,'share')
conf.define('LOCALEDIR', os.path.join(datadir, 'locale').replace('\\', '\\\\'))
conf.define('DATADIR', datadir.replace('\\', '\\\\'))
conf.find_msgfmt()
conf.find_intltool_merge()
if conf.env.CC or conf.env.CXX:
conf.check(header_name='locale.h')