Skip to content

Commit fada0c9

Browse files
author
MarcoFalke
committed
[travis] Fail when documentation is outdated
1 parent 3cd836c commit fada0c9

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ script:
7070
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib
7171
- if [ "$RUN_TESTS" = "true" ]; then make check; fi
7272
- if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.py --coverage; fi
73+
- if [ "$RUN_TESTS" = "true" ]; then contrib/devtools/check-doc.py; fi
7374
after_script:
7475
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi

contrib/devtools/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Contents
22
========
33
This directory contains tools for developers working on this repository.
44

5+
check-doc.py
6+
============
7+
8+
Check if all command line args are documented. The return value indicates the
9+
number of undocumented args.
10+
511
clang-format.py
612
===============
713

contrib/devtools/check-doc.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2014 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
'''
7+
This checks if all command line args are documented.
8+
Return value is 0 to indicate no error.
9+
10+
Author: @MarcoFalke
11+
'''
12+
13+
from subprocess import check_output
14+
import re
15+
16+
FOLDER_GREP = 'src'
17+
FOLDER_TEST = 'src/test/'
18+
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/%s' % FOLDER_GREP
19+
CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' %s | grep -v '%s'" % (CMD_ROOT_DIR, FOLDER_TEST)
20+
CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_ROOT_DIR)
21+
REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"')
22+
REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")')
23+
# list unsupported, deprecated and duplicate args as they need no documentation
24+
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet'])
25+
26+
def main():
27+
used = check_output(CMD_GREP_ARGS, shell=True)
28+
docd = check_output(CMD_GREP_DOCS, shell=True)
29+
30+
args_used = set(re.findall(REGEX_ARG,used))
31+
args_docd = set(re.findall(REGEX_DOC,docd)).union(SET_DOC_OPTIONAL)
32+
args_need_doc = args_used.difference(args_docd)
33+
args_unknown = args_docd.difference(args_used)
34+
35+
print "Args used : %s" % len(args_used)
36+
print "Args documented : %s" % len(args_docd)
37+
print "Args undocumented: %s" % len(args_need_doc)
38+
print args_need_doc
39+
print "Args unknown : %s" % len(args_unknown)
40+
print args_unknown
41+
42+
exit(len(args_need_doc))
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)