summaryrefslogtreecommitdiff
path: root/gtkdoc-check.in
diff options
context:
space:
mode:
authorStefan Sauer <ensonic@users.sf.net>2017-03-30 19:54:25 +0200
committerStefan Sauer <ensonic@users.sf.net>2017-03-30 20:04:50 +0200
commit426ff219aae58bcf9ddcbf8d1dfc6f7ec7401270 (patch)
tree8f7d38de171eae2f08d6c22b20d374c3b4568135 /gtkdoc-check.in
parenta67eb760e8c2cec8d25fa7fcfb54d45fb7b5a2e8 (diff)
downloadgtk-doc-426ff219aae58bcf9ddcbf8d1dfc6f7ec7401270.tar.gz
python: add a gtkdoc python module
Add a config.py there which will take constants from the build such as paths and versions. Move the main code of gtkdoc-check into the module and turn the gtkdoc-check into a trivial starter loading this module.
Diffstat (limited to 'gtkdoc-check.in')
-rwxr-xr-xgtkdoc-check.in107
1 files changed, 5 insertions, 102 deletions
diff --git a/gtkdoc-check.in b/gtkdoc-check.in
index 40d1e5a..9db50fb 100755
--- a/gtkdoc-check.in
+++ b/gtkdoc-check.in
@@ -5,7 +5,7 @@
# Copyright (C) 2007 David Nečas
# 2007-2017 Stefan Sauer
#
-# This program is free scperlonoftware; you can redistribute it and/or modify
+# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@@ -20,107 +20,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-#############################################################################
-# Script : gtkdoc-check
-# Description : Runs various checks on built documentation and outputs test
-# results. Can be run druring make check, by adding this to the
-# documentations Makefile.am: TESTS = $(GTKDOC_CHECK)
-#############################################################################
-
-# Support both Python 2 and 3
-from __future__ import print_function
-
-import os, re, sys, argparse, subprocess
-from glob import glob
-
-
-def grep(regexp, filename, what):
- pattern = re.compile(regexp)
- with open(filename) as f:
- for line in f:
- for match in re.finditer(pattern, line):
- return match.group(1)
- sys.exit("Cannot find %s in %s" % (what, filename));
-
-
-def check_empty(filename, what):
- with open(filename) as f:
- count = sum(1 for line in f if line.strip())
- if count:
- print("%s:1:E: %d %st\n" % (filename, count, what))
- return count
- return 0
-
-
-def check_includes(filename):
- # Check that each XML file in the xml directory is included in doc_main_file
- with open(filename) as f:
- lines = f.read().splitlines()
- num_missing = 0;
- for include in glob('xml/*.xml'):
- try:
- next(line for line in lines if include in line)
- except StopIteration:
- num_missing += 1;
- print('% doesn\'t appear to include "%s"' % (filename, xml_file))
-
- return num_missing
-
-
-def run():
- checks = 4
-
- parser = argparse.ArgumentParser(description='gtkdoc-check version @VERSION@ - run documentation unit tests')
- parser.add_argument('--version', action='version', version='@VERSION@')
- parser.parse_args()
-
- # Get parameters from test env, if not there try to grab them from the makefile
- # We like Makefile.am more but builddir does not necessarily contain one.
- makefile = 'Makefile.am'
- if not os.path.exists(makefile):
- makefile = 'Makefile'
-
- # For historic reasons tests are launched in srcdir
- srcdir = os.environ.get('SRCDIR', None)
- builddir = os.environ.get('BUILDDIR', None)
- workdir = '.'
- if builddir:
- workdir = builddir
-
- doc_module = os.environ.get('DOC_MODULE', None)
- if not doc_module:
- doc_module = grep(r'^\s*DOC_MODULE\s*=\s*(\S+)', makefile, 'DOC_MODULE')
-
- doc_main_file = os.environ.get('DOC_MAIN_SGML_FILE', None)
- if not doc_main_file:
- doc_main_file = grep(r'^\s*DOC_MAIN_SGML_FILE\s*=\s*(\S+)', makefile, 'DOC_MAIN_SGML_FILE')
- doc_main_file = doc_main_file.replace('$(DOC_MODULE)', doc_module)
-
-
- print('Running suite(s): gtk-doc-doc_module')
-
- undocumented = int(grep(r'^(\d+)\s+not\s+documented\.\s*$',
- os.path.join(workdir, doc_module + '-undocumented.txt'),
- 'number of undocumented symbols'))
- incomplete = int(grep(r'^(\d+)\s+symbols?\s+incomplete\.\s*$',
- os.path.join(workdir, doc_module + '-undocumented.txt'),
- 'number of incomplete symbols'))
- total = undocumented + incomplete
- if total:
- print('doc_module-undocumented.txt:1:E: %d undocumented or incomplete symbols' % total)
-
- undeclared = check_empty(os.path.join(workdir, doc_module + '-undeclared.txt'),
- 'undeclared symbols')
- unused = check_empty(os.path.join(workdir, doc_module + '-unused.txt'),
- 'unused documentation entries')
-
- missing_includes = check_includes(os.path.join(workdir, doc_main_file))
-
- failed = (total > 0) + (undeclared != 0) + (unused != 0) + (missing_includes != 0)
- rate = 100.0 * (checks - failed) / checks
- print("%.1f%%: Checks %d, Failures: %d" % (rate, checks, failed))
- sys.exit(failed != 0)
+import sys
+sys.path.append('@PYTHON_PACKAGE_DIR@')
+from gtkdoc import check
if __name__== '__main__':
- run()
+ sys.exit(check.run() != 0)