Allow building with debug symbols

Also allow running individual tests
This commit is contained in:
Kovid Goyal 2016-11-07 13:23:03 +05:30
parent f63a4e7015
commit 8c0b908222
2 changed files with 35 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import sys
import sysconfig
import shlex
import subprocess
import argparse
base = os.path.dirname(os.path.abspath(__file__))
build_dir = os.path.join(base, 'build')
@ -25,12 +26,12 @@ def pkg_config(pkg, *args):
return shlex.split(subprocess.check_output(['pkg-config', pkg] + list(args)).decode('utf-8'))
def init_env():
def init_env(debug=False):
global cflags, ldflags, cc, ldpaths
cc = os.environ.get('CC', 'gcc')
cflags = os.environ.get('OVERRIDE_CFLAGS',
'-Wextra -Wno-missing-field-initializers -Wall -std=c99 -D_XOPEN_SOURCE=700'
' -pedantic-errors -Werror -O3 -DNDEBUG -fwrapv -fstack-protector-strong -pipe')
cflags = os.environ.get('OVERRIDE_CFLAGS', (
'-Wextra -Wno-missing-field-initializers -Wall -std=c99 -D_XOPEN_SOURCE=700'
' -pedantic-errors -Werror {} -DNDEBUG -fwrapv -fstack-protector-strong -pipe').format('-ggdb' if debug else '-O3'))
cflags = shlex.split(cflags) + shlex.split(sysconfig.get_config_var('CCSHARED'))
ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall -O3')
ldflags = shlex.split(ldflags)
@ -69,8 +70,23 @@ def compile_c_extension(module, *sources):
run_tool([cc] + cflags + ['-c', src] + ['-o', dest])
run_tool([cc] + ldflags + objects + ldpaths + ['-o', os.path.join(base, module + '.so')])
if __name__ == '__main__':
def option_parser():
p = argparse.ArgumentParser()
p.add_argument('action', nargs='?', default='build', choices='build test'.split(), help='Action to perform (default is build)')
p.add_argument('--debug', default=False, action='store_true',
help='Build extension modules with debugging symbols')
return p
def main():
if sys.version_info < (3, 5):
raise SystemExit('python >= 3.5 required')
init_env()
compile_c_extension('kitty/fast_data_types', 'kitty/line.c', 'kitty/data-types.c', 'kitty/line-buf.c', 'kitty/cursor.c')
args = option_parser().parse_args()
init_env(args.debug)
if args.action == 'build':
compile_c_extension('kitty/fast_data_types', 'kitty/line.c', 'kitty/data-types.c', 'kitty/line-buf.c', 'kitty/cursor.c')
elif args.action == 'test':
os.execlp(sys.executable, sys.executable, os.path.join(base, 'test.py'))
if __name__ == '__main__':
main()

22
test.py
View File

@ -65,21 +65,20 @@ def filter_tests_by_module(suite, *names):
return filter_tests(suite, q)
def run_tests(find_tests, verbosity=4):
def run_tests():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('name', nargs='?', default=None,
help='The name of the test to run, for e.g. writing.WritingTest.many_many_basic or .many_many_basic for a shortcut')
parser.add_argument(
'name', nargs='*', default=[],
help='The name of the test to run, for e.g. linebuf corresponds to test_linebuf. Can be specified multiple times')
parser.add_argument('--verbosity', default=4, type=int, help='Test verbosity')
args = parser.parse_args()
tests = find_tests()
tests = find_tests_in_dir(os.path.join(base, 'kitty_tests'))
if args.name:
if args.name.startswith('.'):
tests = filter_tests_by_name(tests, args.name[1:])
else:
tests = filter_tests_by_module(tests, args.name)
tests = filter_tests_by_name(tests, *args.name)
if not tests._tests:
raise SystemExit('No test named %s found' % args.name)
run_cli(tests, verbosity)
run_cli(tests, args.verbosity)
def run_cli(suite, verbosity=4):
@ -92,5 +91,8 @@ def run_cli(suite, verbosity=4):
if not result.wasSuccessful():
raise SystemExit(1)
def main():
run_tests()
if __name__ == '__main__':
run_cli(find_tests_in_dir(os.path.join(base, 'kitty_tests')))
main()