Skip to content

Commit 18f05c7

Browse files
committed
build: python 3 compatibility
Ubuntu 16.04 "xenial xerus" does not come with Python 2.x by default. It is possible to install a python-2.7 package, but this has its own problem: no `python` or `python2` symlink (see bitcoin#7717). This fixes the following scripts to work with python 3: - `make check` (bctest,py, bitcoin-util-test.py) - `make translate` (extract_strings_qt.py) - `make symbols-check` (symbol-check.py) - `make security-check` (security-check.py) Explicitly call the python commands using $(PYTHON) instead of relying on the interpreter line at the top of the scripts.
1 parent 29e1131 commit 18f05c7

File tree

11 files changed

+135
-129
lines changed

11 files changed

+135
-129
lines changed

Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ osx_volname:
110110

111111
if BUILD_DARWIN
112112
$(OSX_DMG): $(OSX_APP_BUILT) $(OSX_PACKAGING)
113-
$(OSX_DEPLOY_SCRIPT) $(OSX_APP) -add-qt-tr $(OSX_QT_TRANSLATIONS) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
113+
$(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -add-qt-tr $(OSX_QT_TRANSLATIONS) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
114114

115115
deploydir: $(OSX_DMG)
116116
else
@@ -134,10 +134,10 @@ $(APP_DIST_DIR)/.background/$(OSX_BACKGROUND_IMAGE): $(OSX_BACKGROUND_IMAGE_DPIF
134134
$(TIFFCP) -c none $(OSX_BACKGROUND_IMAGE_DPIFILES) $@
135135

136136
$(APP_DIST_DIR)/.DS_Store: $(OSX_DSSTORE_GEN)
137-
$< "$@" "$(OSX_VOLNAME)"
137+
$(PYTHON) $< "$@" "$(OSX_VOLNAME)"
138138

139139
$(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING)
140-
INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -add-qt-tr $(OSX_QT_TRANSLATIONS) -verbose 2
140+
INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -add-qt-tr $(OSX_QT_TRANSLATIONS) -verbose 2
141141

142142
deploydir: $(APP_DIST_EXTRAS)
143143
endif

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ AC_PATH_TOOL(STRIP, strip)
6060
AC_PATH_TOOL(GCOV, gcov)
6161
AC_PATH_PROG(LCOV, lcov)
6262
AC_PATH_PROG(JAVA, java)
63-
AC_PATH_PROG(PYTHON, python)
63+
AC_PATH_PROGS([PYTHON], [python3 python2.7 python2 python])
6464
AC_PATH_PROG(GENHTML, genhtml)
6565
AC_PATH_PROG([GIT], [git])
6666
AC_PATH_PROG(CCACHE,ccache)

contrib/devtools/security-check.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Otherwise the exit status will be 1 and it will log which executables failed which checks.
66
Needs `readelf` (for ELF) and `objdump` (for PE).
77
'''
8-
from __future__ import division,print_function
8+
from __future__ import division,print_function,unicode_literals
99
import subprocess
1010
import sys
1111
import os
@@ -23,9 +23,9 @@ def check_ELF_PIE(executable):
2323
raise IOError('Error opening file')
2424

2525
ok = False
26-
for line in stdout.split('\n'):
26+
for line in stdout.split(b'\n'):
2727
line = line.split()
28-
if len(line)>=2 and line[0] == 'Type:' and line[1] == 'DYN':
28+
if len(line)>=2 and line[0] == b'Type:' and line[1] == b'DYN':
2929
ok = True
3030
return ok
3131

@@ -38,17 +38,17 @@ def get_ELF_program_headers(executable):
3838
in_headers = False
3939
count = 0
4040
headers = []
41-
for line in stdout.split('\n'):
42-
if line.startswith('Program Headers:'):
41+
for line in stdout.split(b'\n'):
42+
if line.startswith(b'Program Headers:'):
4343
in_headers = True
44-
if line == '':
44+
if line == b'':
4545
in_headers = False
4646
if in_headers:
4747
if count == 1: # header line
48-
ofs_typ = line.find('Type')
49-
ofs_offset = line.find('Offset')
50-
ofs_flags = line.find('Flg')
51-
ofs_align = line.find('Align')
48+
ofs_typ = line.find(b'Type')
49+
ofs_offset = line.find(b'Offset')
50+
ofs_flags = line.find(b'Flg')
51+
ofs_align = line.find(b'Align')
5252
if ofs_typ == -1 or ofs_offset == -1 or ofs_flags == -1 or ofs_align == -1:
5353
raise ValueError('Cannot parse elfread -lW output')
5454
elif count > 1:
@@ -65,9 +65,9 @@ def check_ELF_NX(executable):
6565
have_wx = False
6666
have_gnu_stack = False
6767
for (typ, flags) in get_ELF_program_headers(executable):
68-
if typ == 'GNU_STACK':
68+
if typ == b'GNU_STACK':
6969
have_gnu_stack = True
70-
if 'W' in flags and 'E' in flags: # section is both writable and executable
70+
if b'W' in flags and b'E' in flags: # section is both writable and executable
7171
have_wx = True
7272
return have_gnu_stack and not have_wx
7373

@@ -84,17 +84,17 @@ def check_ELF_RELRO(executable):
8484
# However, the dynamic linker need to write to this area so these are RW.
8585
# Glibc itself takes care of mprotecting this area R after relocations are finished.
8686
# See also http://permalink.gmane.org/gmane.comp.gnu.binutils/71347
87-
if typ == 'GNU_RELRO':
87+
if typ == b'GNU_RELRO':
8888
have_gnu_relro = True
8989

9090
have_bindnow = False
9191
p = subprocess.Popen([READELF_CMD, '-d', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
9292
(stdout, stderr) = p.communicate()
9393
if p.returncode:
9494
raise IOError('Error opening file')
95-
for line in stdout.split('\n'):
95+
for line in stdout.split(b'\n'):
9696
tokens = line.split()
97-
if len(tokens)>1 and tokens[1] == '(BIND_NOW)' or (len(tokens)>2 and tokens[1] == '(FLAGS)' and 'BIND_NOW' in tokens[2]):
97+
if len(tokens)>1 and tokens[1] == b'(BIND_NOW)' or (len(tokens)>2 and tokens[1] == b'(FLAGS)' and b'BIND_NOW' in tokens[2]):
9898
have_bindnow = True
9999
return have_gnu_relro and have_bindnow
100100

@@ -107,8 +107,8 @@ def check_ELF_Canary(executable):
107107
if p.returncode:
108108
raise IOError('Error opening file')
109109
ok = False
110-
for line in stdout.split('\n'):
111-
if '__stack_chk_fail' in line:
110+
for line in stdout.split(b'\n'):
111+
if b'__stack_chk_fail' in line:
112112
ok = True
113113
return ok
114114

contrib/devtools/symbol-check.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
find ../gitian-builder/build -type f -executable | xargs python contrib/devtools/symbol-check.py
1313
'''
14-
from __future__ import division, print_function
14+
from __future__ import division, print_function, unicode_literals
1515
import subprocess
1616
import re
1717
import sys
@@ -47,28 +47,28 @@
4747

4848
# Ignore symbols that are exported as part of every executable
4949
IGNORE_EXPORTS = {
50-
'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used'
50+
b'_edata', b'_end', b'_init', b'__bss_start', b'_fini', b'_IO_stdin_used'
5151
}
5252
READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
5353
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
5454
# Allowed NEEDED libraries
5555
ALLOWED_LIBRARIES = {
5656
# bitcoind and bitcoin-qt
57-
'libgcc_s.so.1', # GCC base support
58-
'libc.so.6', # C library
59-
'libpthread.so.0', # threading
60-
'libanl.so.1', # DNS resolve
61-
'libm.so.6', # math library
62-
'librt.so.1', # real-time (clock)
63-
'ld-linux-x86-64.so.2', # 64-bit dynamic linker
64-
'ld-linux.so.2', # 32-bit dynamic linker
57+
b'libgcc_s.so.1', # GCC base support
58+
b'libc.so.6', # C library
59+
b'libpthread.so.0', # threading
60+
b'libanl.so.1', # DNS resolve
61+
b'libm.so.6', # math library
62+
b'librt.so.1', # real-time (clock)
63+
b'ld-linux-x86-64.so.2', # 64-bit dynamic linker
64+
b'ld-linux.so.2', # 32-bit dynamic linker
6565
# bitcoin-qt only
66-
'libX11-xcb.so.1', # part of X11
67-
'libX11.so.6', # part of X11
68-
'libxcb.so.1', # part of X11
69-
'libfontconfig.so.1', # font support
70-
'libfreetype.so.6', # font parsing
71-
'libdl.so.2' # programming interface to dynamic linker
66+
b'libX11-xcb.so.1', # part of X11
67+
b'libX11.so.6', # part of X11
68+
b'libxcb.so.1', # part of X11
69+
b'libfontconfig.so.1', # font support
70+
b'libfreetype.so.6', # font parsing
71+
b'libdl.so.2' # programming interface to dynamic linker
7272
}
7373

7474
class CPPFilt(object):
@@ -81,7 +81,8 @@ def __init__(self):
8181
self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
8282

8383
def __call__(self, mangled):
84-
self.proc.stdin.write(mangled + '\n')
84+
self.proc.stdin.write(mangled + b'\n')
85+
self.proc.stdin.flush()
8586
return self.proc.stdout.readline().rstrip()
8687

8788
def close(self):
@@ -99,24 +100,24 @@ def read_symbols(executable, imports=True):
99100
if p.returncode:
100101
raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
101102
syms = []
102-
for line in stdout.split('\n'):
103+
for line in stdout.split(b'\n'):
103104
line = line.split()
104-
if len(line)>7 and re.match('[0-9]+:$', line[0]):
105-
(sym, _, version) = line[7].partition('@')
106-
is_import = line[6] == 'UND'
107-
if version.startswith('@'):
105+
if len(line)>7 and re.match(b'[0-9]+:$', line[0]):
106+
(sym, _, version) = line[7].partition(b'@')
107+
is_import = line[6] == b'UND'
108+
if version.startswith(b'@'):
108109
version = version[1:]
109110
if is_import == imports:
110111
syms.append((sym, version))
111112
return syms
112113

113114
def check_version(max_versions, version):
114-
if '_' in version:
115-
(lib, _, ver) = version.rpartition('_')
115+
if b'_' in version:
116+
(lib, _, ver) = version.rpartition(b'_')
116117
else:
117118
lib = version
118119
ver = '0'
119-
ver = tuple([int(x) for x in ver.split('.')])
120+
ver = tuple([int(x) for x in ver.split(b'.')])
120121
if not lib in max_versions:
121122
return False
122123
return ver <= max_versions[lib]
@@ -127,10 +128,10 @@ def read_libraries(filename):
127128
if p.returncode:
128129
raise IOError('Error opening file')
129130
libraries = []
130-
for line in stdout.split('\n'):
131+
for line in stdout.split(b'\n'):
131132
tokens = line.split()
132-
if len(tokens)>2 and tokens[1] == '(NEEDED)':
133-
match = re.match('^Shared library: \[(.*)\]$', ' '.join(tokens[2:]))
133+
if len(tokens)>2 and tokens[1] == b'(NEEDED)':
134+
match = re.match(b'^Shared library: \[(.*)\]$', b' '.join(tokens[2:]))
134135
if match:
135136
libraries.append(match.group(1))
136137
else:
@@ -144,18 +145,18 @@ def read_libraries(filename):
144145
# Check imported symbols
145146
for sym,version in read_symbols(filename, True):
146147
if version and not check_version(MAX_VERSIONS, version):
147-
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
148+
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym).decode('utf-8'), version.decode('utf-8')))
148149
retval = 1
149150
# Check exported symbols
150151
for sym,version in read_symbols(filename, False):
151152
if sym in IGNORE_EXPORTS:
152153
continue
153-
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
154+
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym).decode('utf-8')))
154155
retval = 1
155156
# Check dependency libraries
156157
for library_name in read_libraries(filename):
157158
if library_name not in ALLOWED_LIBRARIES:
158-
print('%s: NEEDED library %s is not allowed' % (filename, library_name))
159+
print('%s: NEEDED library %s is not allowed' % (filename, library_name.decode('utf-8')))
159160
retval = 1
160161

161162
exit(retval)

contrib/macdeploy/custom_dsstore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) 2013-2015 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
5+
from __future__ import division,print_function,unicode_literals
66
import biplist
77
from ds_store import DSStore
88
from mac_alias import Alias
@@ -14,7 +14,7 @@
1414
ds = DSStore.open(output_file, 'w+')
1515
ds['.']['bwsp'] = {
1616
'ShowStatusBar': False,
17-
'WindowBounds': '{{300, 280}, {500, 343}}',
17+
'WindowBounds': b'{{300, 280}, {500, 343}}',
1818
'ContainerShowSidebar': False,
1919
'SidebarWidth': 0,
2020
'ShowTabView': False,
@@ -28,7 +28,7 @@
2828
'gridOffsetX': 0.0,
2929
'textSize': 12.0,
3030
'viewOptionsVersion': 1,
31-
'backgroundImageAlias': '\x00\x00\x00\x00\x02\x1e\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd1\x94\\\xb0H+\x00\x05\x00\x00\x00\x98\x0fbackground.tiff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x99\xd19\xb0\xf8\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\r\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b.background\x00\x00\x10\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x11\x00\x08\x00\x00\xd19\xb0\xf8\x00\x00\x00\x01\x00\x04\x00\x00\x00\x98\x00\x0e\x00 \x00\x0f\x00b\x00a\x00c\x00k\x00g\x00r\x00o\x00u\x00n\x00d\x00.\x00t\x00i\x00f\x00f\x00\x0f\x00\x02\x00\x00\x00\x12\x00\x1c/.background/background.tiff\x00\x14\x01\x06\x00\x00\x00\x00\x01\x06\x00\x02\x00\x00\x0cMacintosh HD\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xce\x97\xab\xc3H+\x00\x00\x01\x88[\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02u\xab\x8d\xd1\x94\\\xb0devrddsk\xff\xff\xff\xff\x00\x00\t \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07bitcoin\x00\x00\x10\x00\x08\x00\x00\xce\x97\xab\xc3\x00\x00\x00\x11\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x01\x00\x14\x01\x88[\x88\x00\x16\xa9\t\x00\x08\xfaR\x00\x08\xfaQ\x00\x02d\x8e\x00\x0e\x00\x02\x00\x00\x00\x0f\x00\x1a\x00\x0c\x00M\x00a\x00c\x00i\x00n\x00t\x00o\x00s\x00h\x00 \x00H\x00D\x00\x13\x00\x01/\x00\x00\x15\x00\x02\x00\x14\xff\xff\x00\x00\xff\xff\x00\x00',
31+
'backgroundImageAlias': b'\x00\x00\x00\x00\x02\x1e\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd1\x94\\\xb0H+\x00\x05\x00\x00\x00\x98\x0fbackground.tiff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x99\xd19\xb0\xf8\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\r\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b.background\x00\x00\x10\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x11\x00\x08\x00\x00\xd19\xb0\xf8\x00\x00\x00\x01\x00\x04\x00\x00\x00\x98\x00\x0e\x00 \x00\x0f\x00b\x00a\x00c\x00k\x00g\x00r\x00o\x00u\x00n\x00d\x00.\x00t\x00i\x00f\x00f\x00\x0f\x00\x02\x00\x00\x00\x12\x00\x1c/.background/background.tiff\x00\x14\x01\x06\x00\x00\x00\x00\x01\x06\x00\x02\x00\x00\x0cMacintosh HD\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xce\x97\xab\xc3H+\x00\x00\x01\x88[\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02u\xab\x8d\xd1\x94\\\xb0devrddsk\xff\xff\xff\xff\x00\x00\t \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07bitcoin\x00\x00\x10\x00\x08\x00\x00\xce\x97\xab\xc3\x00\x00\x00\x11\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x01\x00\x14\x01\x88[\x88\x00\x16\xa9\t\x00\x08\xfaR\x00\x08\xfaQ\x00\x02d\x8e\x00\x0e\x00\x02\x00\x00\x00\x0f\x00\x1a\x00\x0c\x00M\x00a\x00c\x00i\x00n\x00t\x00o\x00s\x00h\x00 \x00H\x00D\x00\x13\x00\x01/\x00\x00\x15\x00\x02\x00\x14\xff\xff\x00\x00\xff\xff\x00\x00',
3232
'backgroundColorBlue': 1.0,
3333
'iconSize': 96.0,
3434
'backgroundColorGreen': 1.0,

0 commit comments

Comments
 (0)