From cf1bdfb6546d2a334e1b67968db6a0f6dcaa70ef Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 27 Jun 2018 14:15:40 +0200 Subject: [PATCH] build: Run tools with available python version 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 #9525 --- Makefile.am | 10 +++++----- bots/test-bots | 18 ++---------------- configure.ac | 4 ++++ test/common/tap-cdp | 7 ++++--- tools/tap-driver | 4 ++-- tools/tap-gtester | 4 ++-- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1119212b5cd0..2f0ee4060aa7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/bots/test-bots b/bots/test-bots index 2240fceb21ac..2834e56ac41f 100755 --- a/bots/test-bots +++ b/bots/test-bots @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/python3 # This file is part of Cockpit. # @@ -18,10 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Cockpit; If not, see . -import errno import glob import imp -import platform import os import sys import unittest @@ -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()) diff --git a/configure.ac b/configure.ac index bd71bcbf8558..e26c5f35b13c 100644 --- a/configure.ac +++ b/configure.ac @@ -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 # diff --git a/test/common/tap-cdp b/test/common/tap-cdp index f41e2cd945a0..d1c00ba55657 100755 --- a/test/common/tap-cdp +++ b/test/common/tap-cdp @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright (C) 2017 Red Hat, Inc. @@ -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() @@ -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() diff --git a/tools/tap-driver b/tools/tap-driver index b6f1b60ea778..241fd5068651 100755 --- a/tools/tap-driver +++ b/tools/tap-driver @@ -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. # diff --git a/tools/tap-gtester b/tools/tap-gtester index 8da0d2a9ad9c..bbda2669c82c 100755 --- a/tools/tap-gtester +++ b/tools/tap-gtester @@ -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. #