gnome: Run gtkdoc-scanobjs and add a way to get assets working

Allowing the object tree to be generated.

We need to add options to allow copying the ncesseary sources and
assets so the HTML generator can work with them (everything is
relative so we need to copy them in the build directory).

Until now the documentation was not generated from the user provided
main sgml file but it was using a generated one, which lead to a broken
documentation. Starting using it revealed the other bugs fixed in that
commit.
pull/808/head
Thibault Saunier 8 years ago
parent 68ae8e1ad0
commit f86fbf6ebf
  1. 54
      mesonbuild/modules/gnome.py
  2. 68
      mesonbuild/scripts/gtkdochelper.py

@ -16,7 +16,7 @@
functionality such as gobject-introspection and gresources.''' functionality such as gobject-introspection and gresources.'''
from .. import build from .. import build
import os, sys import os
import subprocess import subprocess
from ..mesonlib import MesonException from ..mesonlib import MesonException
from .. import dependencies from .. import dependencies
@ -94,12 +94,13 @@ class GnomeModule:
return stdout.split('\n')[:-1] return stdout.split('\n')[:-1]
def get_link_args(self, state, lib, depends): def get_link_args(self, state, lib, depends=None):
link_command = ['-l%s' % lib.name] link_command = ['-l%s' % lib.name]
if isinstance(lib, build.SharedLibrary): if isinstance(lib, build.SharedLibrary):
link_command += ['-L%s' % link_command += ['-L%s' %
os.path.join(state.environment.get_build_dir(), os.path.join(state.environment.get_build_dir(),
lib.subdir)] lib.subdir)]
if depends:
depends.append(lib) depends.append(lib)
return link_command return link_command
@ -391,12 +392,39 @@ class GnomeModule:
'--modulename=' + modulename] '--modulename=' + modulename]
args += self.unpack_args('--htmlargs=', 'html_args', kwargs) args += self.unpack_args('--htmlargs=', 'html_args', kwargs)
args += self.unpack_args('--scanargs=', 'scan_args', kwargs) args += self.unpack_args('--scanargs=', 'scan_args', kwargs)
args += self.unpack_args('--scanobjsargs=', 'scanobjs_args', kwargs)
args += self.unpack_args('--gobjects-types-file=', 'gobject_typesfile', kwargs, state)
args += self.unpack_args('--fixxrefargs=', 'fixxref_args', kwargs) args += self.unpack_args('--fixxrefargs=', 'fixxref_args', kwargs)
args += self.unpack_args('--html-assets=', 'html_assets', kwargs, state)
args += self.unpack_args('--content-files=', 'content_files', kwargs, state)
args += self.get_build_args(kwargs, state)
res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)] res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)]
if kwargs.get('install', True): if kwargs.get('install', True):
res.append(build.InstallScript(command + args)) res.append(build.InstallScript(command + args))
return res return res
def get_build_args(self, kwargs, state):
args = []
cflags, ldflags, gi_includes = self.get_dependencies_flags(kwargs.get('dependencies', []), state)
inc_dirs = kwargs.get('include_directories', [])
if not isinstance(inc_dirs, list):
inc_dirs = [inc_dirs]
for incd in inc_dirs:
if not isinstance(incd.held_object, (str, build.IncludeDirs)):
raise MesonException(
'Gir include dirs should be include_directories().')
cflags.update(self.get_include_args(state, inc_dirs))
if cflags:
args += ['--cflags=%s' % ' '.join(cflags)]
if ldflags:
args += ['--ldflags=%s' % ' '.join(ldflags)]
compiler = state.environment.coredata.compilers.get('c')
if compiler:
args += ['--cc=%s' % ' '.join(compiler.get_exelist())]
args += ['--ld=%s' % ' '.join(compiler.get_linker_exelist())]
return args
def gtkdoc_html_dir(self, state, args, kwarga): def gtkdoc_html_dir(self, state, args, kwarga):
if len(args) != 1: if len(args) != 1:
raise MesonException('Must have exactly one argument.') raise MesonException('Must have exactly one argument.')
@ -406,18 +434,24 @@ class GnomeModule:
return os.path.join('share/gtkdoc/html', modulename) return os.path.join('share/gtkdoc/html', modulename)
def unpack_args(self, arg, kwarg_name, kwargs): def unpack_args(self, arg, kwarg_name, kwargs, expend_file_state=None):
try: if kwarg_name not in kwargs:
return []
new_args = kwargs[kwarg_name] new_args = kwargs[kwarg_name]
if not isinstance(new_args, list): if not isinstance(new_args, list):
new_args = [new_args] new_args = [new_args]
args = []
for i in new_args: for i in new_args:
if not isinstance(i, str): if expend_file_state and isinstance(i, mesonlib.File):
raise MesonException('html_args values must be strings.') i = os.path.join(expend_file_state.environment.get_build_dir(), i.subdir, i.fname)
except KeyError: elif not isinstance(i, str):
return[] raise MesonException(kwarg_name + ' values must be strings.')
if len(new_args) > 0: args.append(i)
return [arg + '@@'.join(new_args)]
if args:
return [arg + '@@'.join(args)]
return [] return []
def gdbus_codegen(self, state, args, kwargs): def gdbus_codegen(self, state, args, kwargs):

@ -30,7 +30,15 @@ parser.add_argument('--mainfile', dest='mainfile')
parser.add_argument('--modulename', dest='modulename') parser.add_argument('--modulename', dest='modulename')
parser.add_argument('--htmlargs', dest='htmlargs', default='') parser.add_argument('--htmlargs', dest='htmlargs', default='')
parser.add_argument('--scanargs', dest='scanargs', default='') parser.add_argument('--scanargs', dest='scanargs', default='')
parser.add_argument('--scanobjsargs', dest='scanobjsargs', default='')
parser.add_argument('--gobjects-types-file', dest='gobject_typesfile', default='')
parser.add_argument('--fixxrefargs', dest='fixxrefargs', default='') parser.add_argument('--fixxrefargs', dest='fixxrefargs', default='')
parser.add_argument('--ld', dest='ld', default='')
parser.add_argument('--cc', dest='cc', default='')
parser.add_argument('--ldflags', dest='ldflags', default='')
parser.add_argument('--cflags', dest='cflags', default='')
parser.add_argument('--content-files', dest='content_files', default='')
parser.add_argument('--html-assets', dest='html_assets', default='')
def gtkdoc_run_check(cmd, cwd): def gtkdoc_run_check(cmd, cwd):
p = subprocess.Popen(cmd, cwd=cwd, p = subprocess.Popen(cmd, cwd=cwd,
@ -45,15 +53,49 @@ def gtkdoc_run_check(cmd, cwd):
raise MesonException('\n'.join(err_msg)) raise MesonException('\n'.join(err_msg))
def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir, def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir,
main_file, module, html_args, scan_args, fixxref_args): main_file, module, html_args, scan_args, fixxref_args,
gobject_typesfile, scanobjs_args, ld, cc, ldflags, cflags,
html_assets, content_files):
print("Building documentation for %s" % module)
abs_src = os.path.join(source_root, src_subdir) abs_src = os.path.join(source_root, src_subdir)
doc_src = os.path.join(source_root, doc_subdir)
abs_out = os.path.join(build_root, doc_subdir) abs_out = os.path.join(build_root, doc_subdir)
htmldir = os.path.join(abs_out, 'html') htmldir = os.path.join(abs_out, 'html')
content_files += [main_file]
sections = os.path.join(doc_src, module + "-sections.txt")
if os.path.exists(sections):
content_files.append(sections)
# Copy files to build directory
for f in content_files:
f_abs = os.path.join(doc_src, f)
shutil.copyfile(f_abs, os.path.join(
abs_out, os.path.basename(f_abs)))
shutil.rmtree(htmldir, ignore_errors=True)
try:
os.mkdir(htmldir)
except Exception:
pass
for f in html_assets:
f_abs = os.path.join(doc_src, f)
shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs)))
scan_cmd = ['gtkdoc-scan', scan_cmd = ['gtkdoc-scan',
'--module=' + module, '--module=' + module,
'--source-dir=' + abs_src] + scan_args '--source-dir=' + abs_src] + scan_args
gtkdoc_run_check(scan_cmd, abs_out) gtkdoc_run_check(scan_cmd, abs_out)
if gobject_typesfile:
scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + [gobject_typesfile,
'--module=' + module, '--cflags=' + cflags, '--ldflags=' + ldflags]
gtkdoc_run_check(scanobjs_cmd, abs_out)
# Make docbook files # Make docbook files
if main_file.endswith('sgml'): if main_file.endswith('sgml'):
modeflag = '--sgml-mode' modeflag = '--sgml-mode'
@ -62,20 +104,15 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir,
mkdb_cmd = ['gtkdoc-mkdb', mkdb_cmd = ['gtkdoc-mkdb',
'--module=' + module, '--module=' + module,
'--output-format=xml', '--output-format=xml',
'--expand-content-files=',
modeflag, modeflag,
'--source-dir=' + abs_src] '--source-dir=' + abs_src]
main_abs = os.path.join(source_root, doc_subdir, main_file)
if len(main_file) > 0: if len(main_file) > 0:
# Yes, this is the flag even if the file is in xml. # Yes, this is the flag even if the file is in xml.
mkdb_cmd.append('--main-sgml-file=' + main_file) mkdb_cmd.append('--main-sgml-file=' + main_file)
gtkdoc_run_check(mkdb_cmd, abs_out) gtkdoc_run_check(mkdb_cmd, abs_out)
# Make HTML documentation # Make HTML documentation
shutil.rmtree(htmldir, ignore_errors=True)
try:
os.mkdir(htmldir)
except Exception:
pass
mkhtml_cmd = ['gtkdoc-mkhtml', mkhtml_cmd = ['gtkdoc-mkhtml',
'--path=' + abs_src, '--path=' + abs_src,
module, module,
@ -109,11 +146,16 @@ def run(args):
scanargs = options.scanargs.split('@@') scanargs = options.scanargs.split('@@')
else: else:
scanargs = [] scanargs = []
if len(options.scanobjsargs) > 0:
scanobjsargs = options.scanobjsargs.split('@@')
else:
scanobjsargs = []
if len(options.fixxrefargs) > 0: if len(options.fixxrefargs) > 0:
fixxrefargs = options.fixxrefargs.split('@@') fixxrefargs = options.fixxrefargs.split('@@')
else: else:
fixxrefargs = [] fixxrefargs = []
build_gtkdoc(options.sourcedir, build_gtkdoc(
options.sourcedir,
options.builddir, options.builddir,
options.subdir, options.subdir,
options.headerdir, options.headerdir,
@ -121,7 +163,15 @@ def run(args):
options.modulename, options.modulename,
htmlargs, htmlargs,
scanargs, scanargs,
fixxrefargs) fixxrefargs,
options.gobject_typesfile,
scanobjsargs,
options.ld,
options.cc,
options.ldflags,
options.cflags,
options.html_assets.split('@@') if options.html_assets else [],
options.content_files.split('@@') if options.content_files else [])
if 'MESON_INSTALL_PREFIX' in os.environ: if 'MESON_INSTALL_PREFIX' in os.environ:
destdir = os.environ.get('DESTDIR', '') destdir = os.environ.get('DESTDIR', '')

Loading…
Cancel
Save