Skip to content

Commit

Permalink
More work on test_all.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Feb 4, 2020
1 parent 39c9b9c commit 647272c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
4 changes: 2 additions & 2 deletions tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ pylint() {
local PYFILES="tools/*.py tools/splitconfig"
if which pocketlint >/dev/null
then
pocketlint $PYFILES
pocketlint $PYFILES
fi

if which flake8 >/dev/null
then
flake8 $PYFILES
flake8 $PYFILES
fi
}

Expand Down
101 changes: 65 additions & 36 deletions tools/test_all.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#! /usr/bin/env python3
"""Brute-force test script: test libpqxx against many compilers etc."""

# Without this, pocketlint does not understand the print function.
from __future__ import print_function

from argparse import ArgumentParser
import os.path
from shutil import rmtree
from subprocess import (
CalledProcessError,
check_call,
DEVNULL,
)
from sys import (
stderr,
stdout,
)
from sys import stderr
from tempfile import mkdtemp
from textwrap import dedent

Expand Down Expand Up @@ -68,21 +75,6 @@ def build(configure, output):
output.write("\n\nOK\n")


def check_compiler(work_dir, cxx, stdlib):
"""Is the given compiler combo available?"""
try:
source = os.path.join(work_dir, 'check.cxx')
command = [cxx, source]
if stdlib != '':
command += stdlib
check_call([cxx, source, stdlib])
except (FileNotFoundError, CalledProcessError):
print("Can't build with '%s %s'. Skipping." % (cxx, stdlib))
return False
else:
return True


def make_work_dir():
"""Set up a scratch directory where we can test for compiler support."""
work_dir = mkdtemp()
Expand All @@ -102,32 +94,68 @@ def make_work_dir():
raise


def try_build(logs_dir, cxx, opt, link, link_opts, debug, debug_opts):
log = os.path.join(
logs_dir, 'build-%s.out' % '_'.join([cxx, opt, link, debug]))
print("%s... " % log, end='', flush=True)
configure = [
'./configure',
'CXX=%s' % cxx,
'CXXFLAGS=%s' % opt,
'--disable-documentation',
] + link_opts + debug_opts
with open(log, 'w') as output:
build(configure, output)
def check_compiler(work_dir, cxx, stdlib, verbose=False):
"""Is the given compiler combo available?"""
err_file = os.path.join(work_dir, 'stderr.log')
if verbose:
err_output = open(err_file, 'w')
else:
err_output = DEVNULL
try:
command = [cxx, 'check.cxx']
if stdlib != '':
command.append(stdlib)
check_call(command, cwd=work_dir, stderr=err_output)
except (OSError, CalledProcessError):
if verbose:
with open(err_file) as errors:
stdout.write(errors.read())
print("Can't build with '%s %s'. Skipping." % (cxx, stdlib))
return False
else:
return True


def check_compilers(compilers, stdlibs):
def check_compilers(compilers, stdlibs, verbose=False):
work_dir = make_work_dir()
return [
(cxx, stdlib)
for stdlib in stdlibs
for cxx in compilers
if check_compiler(work_dir, cxx, stdlib)
if check_compiler(work_dir, cxx, stdlib, verbose=verbose)
]


def try_build(logs_dir, cxx, opt, stdlib, link, link_opts, debug, debug_opts):
log = os.path.join(
logs_dir, 'build-%s.out' % '_'.join([cxx, opt, stdlib, link, debug]))
print("%s... " % log, end='', flush=True)
configure = [
"./configure",
"CXX=%s" % cxx,
]

if stdlib == '':
configure += [
"CXXFLAGS=%s" % opt,
]
else:
configure += [
"CXXFLAGS=%s %s" % (opt, stdlib),
"LDFLAGS=%s" % stdlib,
]

configure += [
"--disable-documentation",
] + link_opts + debug_opts

with open(log, 'w') as output:
build(configure, output)


def parse_args():
parser = ArgumentParser(description=__doc__)
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument(
'--compilers', '-c', default=','.join(CXX),
help="Compilers to use, separated by commas. Default is %(default)s.")
Expand All @@ -151,14 +179,15 @@ def main(args):
if not os.path.isdir(args.logs):
raise Fail("Logs location '%s' is not a directory." % args.logs)
compilers = check_compilers(
args.compilers.split(','), args.stdlibs.split(','))
args.compilers.split(','), args.stdlibs.split(','),
verbose=args.verbose)
for opt in sorted(args.optimize.split(',')):
for cxx, stdlib in compilers:
for link, link_opts in sorted(LINK.items()):
for debug, debug_opts in sorted(DEBUG.items()):
for link, link_opts in sorted(LINK.items()):
for debug, debug_opts in sorted(DEBUG.items()):
for cxx, stdlib in compilers:
try_build(
logs_dir=args.logs, cxx=cxx, opt=opt, link=link,
link_opts=link_opts, debug=debug,
logs_dir=args.logs, cxx=cxx, opt=opt, stdlib=stdlib,
link=link, link_opts=link_opts, debug=debug,
debug_opts=debug_opts)


Expand Down

0 comments on commit 647272c

Please sign in to comment.