waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

valadoc.py (4445B)


      1 #! /usr/bin/env python
      2 # encoding: UTF-8
      3 # Nicolas Joseph 2009
      4 
      5 """
      6 ported from waf 1.5:
      7 TODO: tabs vs spaces
      8 """
      9 
     10 from waflib import Task, Utils, Errors, Logs
     11 from waflib.TaskGen import feature
     12 
     13 VALADOC_STR = '${VALADOC}'
     14 
     15 class valadoc(Task.Task):
     16 	vars  = ['VALADOC', 'VALADOCFLAGS']
     17 	color = 'BLUE'
     18 	after = ['cprogram', 'cstlib', 'cshlib', 'cxxprogram', 'cxxstlib', 'cxxshlib']
     19 	quiet = True # no outputs .. this is weird
     20 
     21 	def __init__(self, *k, **kw):
     22 		Task.Task.__init__(self, *k, **kw)
     23 		self.output_dir = ''
     24 		self.doclet = ''
     25 		self.package_name = ''
     26 		self.package_version = ''
     27 		self.files = []
     28 		self.vapi_dirs = []
     29 		self.protected = True
     30 		self.private = False
     31 		self.inherit = False
     32 		self.deps = False
     33 		self.vala_defines = []
     34 		self.vala_target_glib = None
     35 		self.enable_non_null_experimental = False
     36 		self.force = False
     37 
     38 	def run(self):
     39 		if not self.env['VALADOCFLAGS']:
     40 			self.env['VALADOCFLAGS'] = ''
     41 		cmd = [Utils.subst_vars(VALADOC_STR, self.env)]
     42 		cmd.append ('-o %s' % self.output_dir)
     43 		if getattr(self, 'doclet', None):
     44 			cmd.append ('--doclet %s' % self.doclet)
     45 		cmd.append ('--package-name %s' % self.package_name)
     46 		if getattr(self, 'package_version', None):
     47 			cmd.append ('--package-version %s' % self.package_version)
     48 		if getattr(self, 'packages', None):
     49 			for package in self.packages:
     50 				cmd.append ('--pkg %s' % package)
     51 		if getattr(self, 'vapi_dirs', None):
     52 			for vapi_dir in self.vapi_dirs:
     53 				cmd.append ('--vapidir %s' % vapi_dir)
     54 		if not getattr(self, 'protected', None):
     55 			cmd.append ('--no-protected')
     56 		if getattr(self, 'private', None):
     57 			cmd.append ('--private')
     58 		if getattr(self, 'inherit', None):
     59 			cmd.append ('--inherit')
     60 		if getattr(self, 'deps', None):
     61 			cmd.append ('--deps')
     62 		if getattr(self, 'vala_defines', None):
     63 			for define in self.vala_defines:
     64 				cmd.append ('--define %s' % define)
     65 		if getattr(self, 'vala_target_glib', None):
     66 			cmd.append ('--target-glib=%s' % self.vala_target_glib)
     67 		if getattr(self, 'enable_non_null_experimental', None):
     68 			cmd.append ('--enable-non-null-experimental')
     69 		if getattr(self, 'force', None):
     70 			cmd.append ('--force')
     71 		cmd.append (' '.join ([x.abspath() for x in self.files]))
     72 		return self.generator.bld.exec_command(' '.join(cmd))
     73 
     74 @feature('valadoc')
     75 def process_valadoc(self):
     76 	"""
     77 	Generate API documentation from Vala source code with valadoc
     78 
     79 	doc = bld(
     80 		features = 'valadoc',
     81 		output_dir = '../doc/html',
     82 		package_name = 'vala-gtk-example',
     83 		package_version = '1.0.0',
     84 		packages = 'gtk+-2.0',
     85 		vapi_dirs = '../vapi',
     86 		force = True
     87 	)
     88 
     89 	path = bld.path.find_dir ('../src')
     90 	doc.files = path.ant_glob (incl='**/*.vala')
     91 	"""
     92 
     93 	task = self.create_task('valadoc')
     94 	if getattr(self, 'output_dir', None):
     95 		task.output_dir = self.path.find_or_declare(self.output_dir).abspath()
     96 	else:
     97 		Errors.WafError('no output directory')
     98 	if getattr(self, 'doclet', None):
     99 		task.doclet = self.doclet
    100 	else:
    101 		Errors.WafError('no doclet directory')
    102 	if getattr(self, 'package_name', None):
    103 		task.package_name = self.package_name
    104 	else:
    105 		Errors.WafError('no package name')
    106 	if getattr(self, 'package_version', None):
    107 		task.package_version = self.package_version
    108 	if getattr(self, 'packages', None):
    109 		task.packages = Utils.to_list(self.packages)
    110 	if getattr(self, 'vapi_dirs', None):
    111 		vapi_dirs = Utils.to_list(self.vapi_dirs)
    112 		for vapi_dir in vapi_dirs:
    113 			try:
    114 				task.vapi_dirs.append(self.path.find_dir(vapi_dir).abspath())
    115 			except AttributeError:
    116 				Logs.warn('Unable to locate Vala API directory: %r', vapi_dir)
    117 	if getattr(self, 'files', None):
    118 		task.files = self.files
    119 	else:
    120 		Errors.WafError('no input file')
    121 	if getattr(self, 'protected', None):
    122 		task.protected = self.protected
    123 	if getattr(self, 'private', None):
    124 		task.private = self.private
    125 	if getattr(self, 'inherit', None):
    126 		task.inherit = self.inherit
    127 	if getattr(self, 'deps', None):
    128 		task.deps = self.deps
    129 	if getattr(self, 'vala_defines', None):
    130 		task.vala_defines = Utils.to_list(self.vala_defines)
    131 	if getattr(self, 'vala_target_glib', None):
    132 		task.vala_target_glib = self.vala_target_glib
    133 	if getattr(self, 'enable_non_null_experimental', None):
    134 		task.enable_non_null_experimental = self.enable_non_null_experimental
    135 	if getattr(self, 'force', None):
    136 		task.force = self.force
    137 
    138 def configure(conf):
    139 	conf.find_program('valadoc', errmsg='You must install valadoc <http://live.gnome.org/Valadoc> for generate the API documentation')
    140