mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
buildtools/wafsamba: Avoid decode when using python2
To avoid problematic type checking for 'str' types which fail when result from str.decode is used. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13777 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
584dfc15fd
commit
244e2a0279
@ -85,7 +85,7 @@ def abi_check_task(self):
|
|||||||
libpath = self.inputs[0].abspath(self.env)
|
libpath = self.inputs[0].abspath(self.env)
|
||||||
libname = os.path.basename(libpath)
|
libname = os.path.basename(libpath)
|
||||||
|
|
||||||
sigs = Utils.cmd_output([abi_gen, libpath]).decode('utf8')
|
sigs = samba_utils.get_string(Utils.cmd_output([abi_gen, libpath]))
|
||||||
parsed_sigs = parse_sigs(sigs, self.ABI_MATCH)
|
parsed_sigs = parse_sigs(sigs, self.ABI_MATCH)
|
||||||
|
|
||||||
sig_file = self.ABI_FILE
|
sig_file = self.ABI_FILE
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import os, shutil, re
|
import os, shutil, re
|
||||||
from waflib import Build, Configure, Utils, Options, Logs, Errors
|
from waflib import Build, Configure, Utils, Options, Logs, Errors
|
||||||
from waflib.Configure import conf
|
from waflib.Configure import conf
|
||||||
from samba_utils import TO_LIST, ADD_LD_LIBRARY_PATH
|
from samba_utils import TO_LIST, ADD_LD_LIBRARY_PATH, get_string
|
||||||
|
|
||||||
|
|
||||||
def add_option(self, *k, **kw):
|
def add_option(self, *k, **kw):
|
||||||
@ -418,7 +418,7 @@ def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=Fals
|
|||||||
if on_target:
|
if on_target:
|
||||||
cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
|
cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
|
||||||
try:
|
try:
|
||||||
ret = Utils.cmd_output(cmd).decode('utf8')
|
ret = get_string(Utils.cmd_output(cmd))
|
||||||
except:
|
except:
|
||||||
conf.COMPOUND_END(False)
|
conf.COMPOUND_END(False)
|
||||||
return False
|
return False
|
||||||
@ -508,7 +508,7 @@ def CHECK_STANDARD_LIBPATH(conf):
|
|||||||
# at least gcc and clang support this:
|
# at least gcc and clang support this:
|
||||||
try:
|
try:
|
||||||
cmd = conf.env.CC + ['-print-search-dirs']
|
cmd = conf.env.CC + ['-print-search-dirs']
|
||||||
out = Utils.cmd_output(cmd).decode('utf8').split('\n')
|
out = get_string(Utils.cmd_output(cmd)).split('\n')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# option not supported by compiler - use a standard list of directories
|
# option not supported by compiler - use a standard list of directories
|
||||||
dirlist = [ '/usr/lib', '/usr/lib64' ]
|
dirlist = [ '/usr/lib', '/usr/lib64' ]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import os, sys, re, shlex
|
import os, sys, re, shlex
|
||||||
from waflib import Utils, Logs, Options, Errors, Context
|
from waflib import Utils, Logs, Options, Errors, Context
|
||||||
from waflib.Configure import conf
|
from waflib.Configure import conf
|
||||||
|
from wafsamba import samba_utils
|
||||||
|
|
||||||
real_Popen = None
|
real_Popen = None
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ class cross_Popen(Utils.subprocess.Popen):
|
|||||||
stdout=Utils.subprocess.PIPE,
|
stdout=Utils.subprocess.PIPE,
|
||||||
stderr=Utils.subprocess.PIPE)
|
stderr=Utils.subprocess.PIPE)
|
||||||
ce_out, ce_err = p.communicate()
|
ce_out, ce_err = p.communicate()
|
||||||
ans = (p.returncode, ce_out.decode('utf8'))
|
ans = (p.returncode, samba_utils.get_string(ce_out))
|
||||||
add_answer(ca_file, msg, ans)
|
add_answer(ca_file, msg, ans)
|
||||||
else:
|
else:
|
||||||
args = newargs
|
args = newargs
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import os, sys, tarfile
|
import os, sys, tarfile
|
||||||
from waflib import Utils, Scripting, Logs, Options
|
from waflib import Utils, Scripting, Logs, Options
|
||||||
from waflib.Configure import conf
|
from waflib.Configure import conf
|
||||||
from samba_utils import os_path_relpath
|
from samba_utils import os_path_relpath, get_string
|
||||||
from waflib import Context
|
from waflib import Context
|
||||||
|
|
||||||
dist_dirs = None
|
dist_dirs = None
|
||||||
@ -119,7 +119,7 @@ def vcs_dir_contents(path):
|
|||||||
repo = os.path.dirname(repo)
|
repo = os.path.dirname(repo)
|
||||||
if repo == "/":
|
if repo == "/":
|
||||||
raise Exception("unsupported or no vcs for %s" % path)
|
raise Exception("unsupported or no vcs for %s" % path)
|
||||||
return Utils.cmd_output(ls_files_cmd, cwd=cwd, env=env).decode('utf8').split('\n')
|
return get_string(Utils.cmd_output(ls_files_cmd, cwd=cwd, env=env)).split('\n')
|
||||||
|
|
||||||
|
|
||||||
def dist(appname='', version=''):
|
def dist(appname='', version=''):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from waflib import Utils
|
from waflib import Utils
|
||||||
from waflib.Configure import conf
|
from waflib.Configure import conf
|
||||||
|
from samba_utils import get_string
|
||||||
done = {}
|
done = {}
|
||||||
|
|
||||||
@conf
|
@conf
|
||||||
@ -17,7 +17,7 @@ def SAMBA_CHECK_PERL(conf, mandatory=True, version=(5,0,0)):
|
|||||||
def read_perl_config_var(cmd):
|
def read_perl_config_var(cmd):
|
||||||
output = Utils.cmd_output([conf.env.get_flat('PERL'), '-MConfig', '-e', cmd])
|
output = Utils.cmd_output([conf.env.get_flat('PERL'), '-MConfig', '-e', cmd])
|
||||||
if not isinstance(output, str):
|
if not isinstance(output, str):
|
||||||
output = output.decode('utf8')
|
output = get_string(output)
|
||||||
return Utils.to_list(output)
|
return Utils.to_list(output)
|
||||||
|
|
||||||
def check_perl_config_var(var):
|
def check_perl_config_var(var):
|
||||||
|
@ -15,6 +15,38 @@ from waflib.Build import CACHE_SUFFIX
|
|||||||
LIB_PATH="shared"
|
LIB_PATH="shared"
|
||||||
|
|
||||||
|
|
||||||
|
PY3 = sys.version_info[0] == 3
|
||||||
|
|
||||||
|
if PY3:
|
||||||
|
|
||||||
|
# helper function to get a string from a variable that maybe 'str' or
|
||||||
|
# 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
|
||||||
|
# it is returned unchanged
|
||||||
|
# Using this function is PY2/PY3 code should ensure in most cases
|
||||||
|
# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
|
||||||
|
# decodes the variable (see PY2 implementation of this function below)
|
||||||
|
def get_string(bytesorstring):
|
||||||
|
tmp = bytesorstring
|
||||||
|
if isinstance(bytesorstring, bytes):
|
||||||
|
tmp = bytesorstring.decode('utf8')
|
||||||
|
elif not isinstance(bytesorstring, str):
|
||||||
|
raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
|
||||||
|
return tmp
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
# Helper function to return string.
|
||||||
|
# if 'str' or 'unicode' passed in they are returned unchanged
|
||||||
|
# otherwise an exception is generated
|
||||||
|
# Using this function is PY2/PY3 code should ensure in most cases
|
||||||
|
# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
|
||||||
|
# decodes the variable (see PY3 implementation of this function above)
|
||||||
|
def get_string(bytesorstring):
|
||||||
|
tmp = bytesorstring
|
||||||
|
if not(isinstance(bytesorstring, str) or isinstance(bytesorstring, unicode)):
|
||||||
|
raise ValueError('Expected str or unicode for %s:%s' % (type(bytesorstring), bytesorstring))
|
||||||
|
return tmp
|
||||||
|
|
||||||
# sigh, python octal constants are a mess
|
# sigh, python octal constants are a mess
|
||||||
MODE_644 = int('644', 8)
|
MODE_644 = int('644', 8)
|
||||||
MODE_744 = int('744', 8)
|
MODE_744 = int('744', 8)
|
||||||
|
@ -14,7 +14,7 @@ def git_version_summary(path, env=None):
|
|||||||
environ = dict(os.environ)
|
environ = dict(os.environ)
|
||||||
environ["GIT_DIR"] = '%s/.git' % path
|
environ["GIT_DIR"] = '%s/.git' % path
|
||||||
environ["GIT_WORK_TREE"] = path
|
environ["GIT_WORK_TREE"] = path
|
||||||
git = Utils.cmd_output(env.GIT + ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True, env=environ).decode('utf8')
|
git = samba_utils.get_string(Utils.cmd_output(env.GIT + ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True, env=environ))
|
||||||
|
|
||||||
lines = git.splitlines()
|
lines = git.splitlines()
|
||||||
if not lines or len(lines) < 4:
|
if not lines or len(lines) < 4:
|
||||||
|
Loading…
Reference in New Issue
Block a user