Commits

Anonymous committed bc6cd15

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.

Comments (0)

Files changed (2)

waflib/Tools/glib2.py

 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
 
 	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:
+@conf
+def find_glib_genmarshal(conf):
+	conf.find_program('glib-genmarshal', var='GLIB_GENMARSHAL')
 
-	* *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_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, ''))
 
 	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

waflib/Tools/intltool.py

 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')
 	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)
 	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', '')
 	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*.
 
 	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')