libpath = self.inputs[0].abspath(self.env)
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)
sig_file = self.ABI_FILE
import os, shutil, re
from waflib import Build, Configure, Utils, Options, Logs, Errors
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):
if on_target:
cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
try:
- ret = Utils.cmd_output(cmd).decode('utf8')
+ ret = get_string(Utils.cmd_output(cmd))
except:
conf.COMPOUND_END(False)
return False
# at least gcc and clang support this:
try:
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:
# option not supported by compiler - use a standard list of directories
dirlist = [ '/usr/lib', '/usr/lib64' ]
import os, sys, re, shlex
from waflib import Utils, Logs, Options, Errors, Context
from waflib.Configure import conf
+from wafsamba import samba_utils
real_Popen = None
stdout=Utils.subprocess.PIPE,
stderr=Utils.subprocess.PIPE)
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)
else:
args = newargs
import os, sys, tarfile
from waflib import Utils, Scripting, Logs, Options
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
dist_dirs = None
repo = os.path.dirname(repo)
if repo == "/":
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=''):
from waflib import Utils
from waflib.Configure import conf
-
+from samba_utils import get_string
done = {}
@conf
def read_perl_config_var(cmd):
output = Utils.cmd_output([conf.env.get_flat('PERL'), '-MConfig', '-e', cmd])
if not isinstance(output, str):
- output = output.decode('utf8')
+ output = get_string(output)
return Utils.to_list(output)
def check_perl_config_var(var):
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
MODE_644 = int('644', 8)
MODE_744 = int('744', 8)
environ = dict(os.environ)
environ["GIT_DIR"] = '%s/.git' % 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()
if not lines or len(lines) < 4: