Allow building with debug symbols
Also allow running individual tests
This commit is contained in:
parent
f63a4e7015
commit
8c0b908222
30
setup.py
30
setup.py
@ -8,6 +8,7 @@ import sys
|
|||||||
import sysconfig
|
import sysconfig
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
build_dir = os.path.join(base, 'build')
|
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'))
|
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
|
global cflags, ldflags, cc, ldpaths
|
||||||
cc = os.environ.get('CC', 'gcc')
|
cc = os.environ.get('CC', 'gcc')
|
||||||
cflags = os.environ.get('OVERRIDE_CFLAGS',
|
cflags = os.environ.get('OVERRIDE_CFLAGS', (
|
||||||
'-Wextra -Wno-missing-field-initializers -Wall -std=c99 -D_XOPEN_SOURCE=700'
|
'-Wextra -Wno-missing-field-initializers -Wall -std=c99 -D_XOPEN_SOURCE=700'
|
||||||
' -pedantic-errors -Werror -O3 -DNDEBUG -fwrapv -fstack-protector-strong -pipe')
|
' -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'))
|
cflags = shlex.split(cflags) + shlex.split(sysconfig.get_config_var('CCSHARED'))
|
||||||
ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall -O3')
|
ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall -O3')
|
||||||
ldflags = shlex.split(ldflags)
|
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] + cflags + ['-c', src] + ['-o', dest])
|
||||||
run_tool([cc] + ldflags + objects + ldpaths + ['-o', os.path.join(base, module + '.so')])
|
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):
|
if sys.version_info < (3, 5):
|
||||||
raise SystemExit('python >= 3.5 required')
|
raise SystemExit('python >= 3.5 required')
|
||||||
init_env()
|
args = option_parser().parse_args()
|
||||||
compile_c_extension('kitty/fast_data_types', 'kitty/line.c', 'kitty/data-types.c', 'kitty/line-buf.c', 'kitty/cursor.c')
|
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
22
test.py
@ -65,21 +65,20 @@ def filter_tests_by_module(suite, *names):
|
|||||||
return filter_tests(suite, q)
|
return filter_tests(suite, q)
|
||||||
|
|
||||||
|
|
||||||
def run_tests(find_tests, verbosity=4):
|
def run_tests():
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('name', nargs='?', default=None,
|
parser.add_argument(
|
||||||
help='The name of the test to run, for e.g. writing.WritingTest.many_many_basic or .many_many_basic for a shortcut')
|
'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()
|
args = parser.parse_args()
|
||||||
tests = find_tests()
|
tests = find_tests_in_dir(os.path.join(base, 'kitty_tests'))
|
||||||
if args.name:
|
if args.name:
|
||||||
if args.name.startswith('.'):
|
tests = filter_tests_by_name(tests, *args.name)
|
||||||
tests = filter_tests_by_name(tests, args.name[1:])
|
|
||||||
else:
|
|
||||||
tests = filter_tests_by_module(tests, args.name)
|
|
||||||
if not tests._tests:
|
if not tests._tests:
|
||||||
raise SystemExit('No test named %s found' % args.name)
|
raise SystemExit('No test named %s found' % args.name)
|
||||||
run_cli(tests, verbosity)
|
run_cli(tests, args.verbosity)
|
||||||
|
|
||||||
|
|
||||||
def run_cli(suite, verbosity=4):
|
def run_cli(suite, verbosity=4):
|
||||||
@ -92,5 +91,8 @@ def run_cli(suite, verbosity=4):
|
|||||||
if not result.wasSuccessful():
|
if not result.wasSuccessful():
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
run_tests()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run_cli(find_tests_in_dir(os.path.join(base, 'kitty_tests')))
|
main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user