Skip to content

Commit

Permalink
build: Run tools with available python version
Browse files Browse the repository at this point in the history
tap-{gtester,driver} can be run with Python 2 or 3. Call them with
whichever is available, as this differs between Fedora and RHEL.
This avoids having to build-depend on both python 2 and 3.

Make the remaining tools bilingual and switch them to Python 3 by
default.

Drop the python3 runtime hack from test-bots, as it is now always
invoked with Python 3.

Closes cockpit-project#9525
  • Loading branch information
martinpitt committed Jul 4, 2018
1 parent d75f0e9 commit cf1bdfb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ AM_CPPFLAGS = \

AM_LDFLAGS = -Wl,--as-needed

LOG_DRIVER = $(top_srcdir)/tools/tap-driver
LOG_COMPILER = $(top_srcdir)/tools/tap-gtester
LOG_DRIVER = $(PYTHON) $(top_srcdir)/tools/tap-driver
LOG_COMPILER = $(PYTHON) $(top_srcdir)/tools/tap-gtester

TEST_EXTENSIONS = .html .sh
SH_LOG_DRIVER = $(top_srcdir)/tools/tap-driver
HTML_LOG_DRIVER = $(top_srcdir)/tools/tap-driver
SH_LOG_DRIVER = $(LOG_DRIVER)
HTML_LOG_DRIVER = $(LOG_DRIVER)
HTML_TEST_SERVER = $(builddir)/test-server

HTML_LOG_COMPILER = $(top_srcdir)/test/common/tap-cdp --strip=$(top_srcdir)/ -- $(HTML_TEST_SERVER)
HTML_LOG_COMPILER = $(PYTHON) $(top_srcdir)/test/common/tap-cdp --strip=$(top_srcdir)/ -- $(HTML_TEST_SERVER)

VALGRIND_ARGS = --trace-children=yes --quiet --error-exitcode=33 \
--suppressions=valgrind-suppressions --gen-suppressions=all \
Expand Down
18 changes: 2 additions & 16 deletions bots/test-bots
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/python3

# This file is part of Cockpit.
#
Expand All @@ -18,10 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import errno
import glob
import imp
import platform
import os
import sys
import unittest
Expand All @@ -47,16 +44,5 @@ def main():
return 0
return 1

# Because these tests are invoked on systems without python3 but the bots
# are written in python3, we skip the tests on systems without python3 available
if __name__ == '__main__':
if platform.python_version()[0] == '2':
try:
args = [ "python3", __file__ ] + sys.argv
os.execvp(args[0], args)
except OSError as ex:
if ex.errno == errno.ENOENT:
sys.stdout.write("1..1\nok 1 bots tests # SKIP no python3\n")
sys.exit(0)
else:
sys.exit(main())
sys.exit(main())
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ else
fi
AC_MSG_RESULT($enable_strict)

# Python version; prefer python3
m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python3 python2 python])
AM_PATH_PYTHON([2.7])

# Generate
#

Expand Down
7 changes: 4 additions & 3 deletions test/common/tap-cdp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

#
# Copyright (C) 2017 Red Hat, Inc.
Expand Down Expand Up @@ -63,6 +63,7 @@ if not cdp.get_browser_path():
server = subprocess.Popen(opts.server,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True,
close_fds=True)

address = server.stdout.readline()
Expand Down Expand Up @@ -95,9 +96,9 @@ for t, message in cdp.read_log():

# TAP lines go to stdout, everything else to stderr
if tap_line_re.match(message):
print(message.encode('utf-8'))
print(message)
else:
print(message.encode('utf-8'), file=sys.stderr)
print(message, file=sys.stderr)


server.terminate()
Expand Down
4 changes: 2 additions & 2 deletions tools/tap-driver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2
# This can also be run with Python 3.
#!/usr/bin/python3
# This can also be run with Python 2.

# Copyright (C) 2013 Red Hat, Inc.
#
Expand Down
4 changes: 2 additions & 2 deletions tools/tap-gtester
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2
# This can also be run with Python 3.
#!/usr/bin/python3
# This can also be run with Python 2.

# Copyright (C) 2014 Red Hat, Inc.
#
Expand Down

0 comments on commit cf1bdfb

Please sign in to comment.