diff options
author | Alexander Bokovoy <ab@samba.org> | 2018-01-31 11:48:43 +0200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-09-05 06:37:22 +0200 |
commit | 4e65b33c1d40bb2c243f775f388056aed31d8671 (patch) | |
tree | 5a41b6ddef7ce1c0b6a93bcc16ef89da10f080e8 /buildtools | |
parent | faef27506977db01cc4619140a71652463914378 (diff) | |
download | samba-4e65b33c1d40bb2c243f775f388056aed31d8671.tar.gz |
third_party:waf: update to upstream 2.0.4 release
Update third_party/waf/ to 2.0.4 to bring us closer to Python 3
This change requires a number of changes in buildtools/ too.
Signed-off-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'buildtools')
33 files changed, 470 insertions, 277 deletions
diff --git a/buildtools/bin/waf b/buildtools/bin/waf index a83a2430ed3..cbb5f2f1485 100755 --- a/buildtools/bin/waf +++ b/buildtools/bin/waf @@ -1,7 +1,7 @@ #!/usr/bin/env python -# encoding: ISO8859-1 -# Thomas Nagy, 2005-2015 - +# encoding: latin-1 +# Thomas Nagy, 2005-2018 +# """ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -32,16 +32,18 @@ POSSIBILITY OF SUCH DAMAGE. import os, sys, inspect -VERSION="1.9.10" +VERSION="2.0.4" REVISION="x" GIT="x" -INSTALL='' -C1='#>' -C2='#6' -C3='#4' +INSTALL="x" +C1='x' +C2='x' +C3='x' cwd = os.getcwd() join = os.path.join +if sys.hexversion<0x206000f: + raise ImportError('Python >= 2.6 is required to create the waf file') WAF='waf' def b(x): @@ -129,15 +131,16 @@ def test(dir): pass def find_lib(): - return os.path.abspath(os.path.join(os.path.dirname(__file__), '../../third_party/waf')) + path = '../../third_party/waf' + paths = [path, path+'/waflib'] + return [os.path.abspath(os.path.join(os.path.dirname(__file__), x)) for x in paths] wafdir = find_lib() -sys.path.insert(0, wafdir) +for p in wafdir: + sys.path.insert(0, p) if __name__ == '__main__': - - # TODO: remove these when possible - from waflib.extras import compat15 + #import extras.compat15#PRELUDE import sys from waflib.Tools import ccroot, c, ar, compiler_c, gcc @@ -147,7 +150,7 @@ if __name__ == '__main__': sys.modules['compiler_cc'] = compiler_c sys.modules['gcc'] = gcc - from waflib import Options + from waflib import Options Options.lockfile = os.environ.get('WAFLOCK', '.lock-wscript') if os.path.isfile(Options.lockfile) and os.stat(Options.lockfile).st_size == 0: os.environ['NOCLIMB'] = "1" @@ -160,5 +163,5 @@ if __name__ == '__main__': Task.classes['cc_link'] = o from waflib import Scripting - Scripting.waf_entry_point(cwd, VERSION, wafdir) + Scripting.waf_entry_point(cwd, VERSION, wafdir[0]) diff --git a/buildtools/bin/waf-1.9 b/buildtools/bin/waf-1.9 new file mode 100755 index 00000000000..a83a2430ed3 --- /dev/null +++ b/buildtools/bin/waf-1.9 @@ -0,0 +1,164 @@ +#!/usr/bin/env python +# encoding: ISO8859-1 +# Thomas Nagy, 2005-2015 + +""" +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +""" + +import os, sys, inspect + +VERSION="1.9.10" +REVISION="x" +GIT="x" +INSTALL='' +C1='#>' +C2='#6' +C3='#4' +cwd = os.getcwd() +join = os.path.join + + +WAF='waf' +def b(x): + return x +if sys.hexversion>0x300000f: + WAF='waf3' + def b(x): + return x.encode() + +def err(m): + print(('\033[91mError: %s\033[0m' % m)) + sys.exit(1) + +def unpack_wafdir(dir, src): + f = open(src,'rb') + c = 'corrupt archive (%d)' + while 1: + line = f.readline() + if not line: err('run waf-light from a folder containing waflib') + if line == b('#==>\n'): + txt = f.readline() + if not txt: err(c % 1) + if f.readline() != b('#<==\n'): err(c % 2) + break + if not txt: err(c % 3) + txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')).replace(b(C3), b('\x00')) + + import shutil, tarfile + try: shutil.rmtree(dir) + except OSError: pass + try: + for x in ('Tools', 'extras'): + os.makedirs(join(dir, 'waflib', x)) + except OSError: + err("Cannot unpack waf lib into %s\nMove waf in a writable directory" % dir) + + os.chdir(dir) + tmp = 't.bz2' + t = open(tmp,'wb') + try: t.write(txt) + finally: t.close() + + try: + t = tarfile.open(tmp) + except: + try: + os.system('bunzip2 t.bz2') + t = tarfile.open('t') + tmp = 't' + except: + os.chdir(cwd) + try: shutil.rmtree(dir) + except OSError: pass + err("Waf cannot be unpacked, check that bzip2 support is present") + + try: + for x in t: t.extract(x) + finally: + t.close() + + for x in ('Tools', 'extras'): + os.chmod(join('waflib',x), 493) + + if sys.hexversion<0x300000f: + sys.path = [join(dir, 'waflib')] + sys.path + import fixpy2 + fixpy2.fixdir(dir) + + os.remove(tmp) + os.chdir(cwd) + + try: dir = unicode(dir, 'mbcs') + except: pass + try: + from ctypes import windll + windll.kernel32.SetFileAttributesW(dir, 2) + except: + pass + +def test(dir): + try: + os.stat(join(dir, 'waflib')) + return os.path.abspath(dir) + except OSError: + pass + +def find_lib(): + return os.path.abspath(os.path.join(os.path.dirname(__file__), '../../third_party/waf')) + +wafdir = find_lib() +sys.path.insert(0, wafdir) + +if __name__ == '__main__': + + # TODO: remove these when possible + from waflib.extras import compat15 + import sys + + from waflib.Tools import ccroot, c, ar, compiler_c, gcc + sys.modules['cc'] = c + sys.modules['ccroot'] = ccroot + sys.modules['ar'] = ar + sys.modules['compiler_cc'] = compiler_c + sys.modules['gcc'] = gcc + + from waflib import Options + Options.lockfile = os.environ.get('WAFLOCK', '.lock-wscript') + if os.path.isfile(Options.lockfile) and os.stat(Options.lockfile).st_size == 0: + os.environ['NOCLIMB'] = "1" + # there is a single top-level, but libraries must build independently + os.environ['NO_LOCK_IN_TOP'] = "1" + + from waflib import Task + class o(object): + display = None + Task.classes['cc_link'] = o + + from waflib import Scripting + Scripting.waf_entry_point(cwd, VERSION, wafdir) + diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py index e28282be3d5..6ad43546249 100644 --- a/buildtools/wafsamba/configure_file.py +++ b/buildtools/wafsamba/configure_file.py @@ -1,7 +1,9 @@ # handle substitution of variables in .in files -import re, os -import Build, sys, Logs +import sys +import re +import os +from waflib import Build, Logs from samba_utils import SUBST_VARS_RECURSIVE def subst_at_vars(task): diff --git a/buildtools/wafsamba/generic_cc.py b/buildtools/wafsamba/generic_cc.py index 504e902c2a6..93a43ea3301 100644 --- a/buildtools/wafsamba/generic_cc.py +++ b/buildtools/wafsamba/generic_cc.py @@ -3,11 +3,11 @@ # based on suncc.py from waf import os, optparse -import Utils, Options, Configure -import ccroot, ar -from Configure import conftest +from waflib import Utils, Options, Configure +from waflib.Tools import ccroot, ar +from waflib.Configure import conftest -from compiler_cc import c_compiler +from waflib.Tools.compiler_c import c_compiler c_compiler['default'] = ['gcc', 'generic_cc'] c_compiler['hpux'] = ['gcc', 'generic_cc'] diff --git a/buildtools/wafsamba/hpuxcc.py b/buildtools/wafsamba/hpuxcc.py index c263556cd8f..593881179f8 100644 --- a/buildtools/wafsamba/hpuxcc.py +++ b/buildtools/wafsamba/hpuxcc.py @@ -2,10 +2,10 @@ # based on suncc.py from waf import os, optparse, sys -import Utils, Options, Configure -import ccroot, ar -from Configure import conftest -import gcc +from waflib import Utils, Options, Configure +from waflib.Tools import ccroot, ar +from waflib.Configure import conftest +from waflib.Tools import gcc @conftest @@ -38,7 +38,7 @@ def gcc_modifier_hpux(conf): gcc.gcc_modifier_hpux = gcc_modifier_hpux -from TaskGen import feature, after +from waflib.TaskGen import feature, after @feature('cprogram', 'cshlib') @after('apply_link', 'apply_lib_vars', 'apply_obj_vars') def hpux_addfullpath(self): diff --git a/buildtools/wafsamba/irixcc.py b/buildtools/wafsamba/irixcc.py index f3cb451fb0f..c33c96bd8f6 100644 --- a/buildtools/wafsamba/irixcc.py +++ b/buildtools/wafsamba/irixcc.py @@ -3,11 +3,11 @@ # based on suncc.py from waf import os, optparse -import Utils, Options, Configure -import ccroot, ar -from Configure import conftest +from waflib import Utils, Options, Configure +from waflib.Tools import ccroot, ar +from waflib.Configure import conftest -from compiler_cc import c_compiler +from waflib.Tools.compiler_c import c_compiler c_compiler['irix'] = ['gcc', 'irixcc'] diff --git a/buildtools/wafsamba/nothreads.py b/buildtools/wafsamba/nothreads.py index 9bd33e89f8d..f873d7d5de1 100644 --- a/buildtools/wafsamba/nothreads.py +++ b/buildtools/wafsamba/nothreads.py @@ -13,8 +13,8 @@ import sys, random, threading try: from Queue import Queue except ImportError: from queue import Queue -import Utils, Options -from Constants import EXCEPTION, CRASHED, MAXJOBS, ASK_LATER, SKIPPED, SKIP_ME, SUCCESS +from waflib import Utils, Options, Errors +from waflib.TaskGen import EXCEPTION, CRASHED, MAXJOBS, ASK_LATER, SKIPPED, SKIP_ME, SUCCESS GAP = 15 @@ -58,7 +58,7 @@ def process(tsk): else: try: tsk.post_run() - except Utils.WafError: + except Errors.WafError: pass except Exception: tsk.err_msg = Utils.ex_stack() diff --git a/buildtools/wafsamba/pkgconfig.py b/buildtools/wafsamba/pkgconfig.py index 999bad474a3..6094114c5ff 100644 --- a/buildtools/wafsamba/pkgconfig.py +++ b/buildtools/wafsamba/pkgconfig.py @@ -1,7 +1,7 @@ # handle substitution of variables in pc files import os, re, sys -import Build, Logs +from waflib import Build, Logs from samba_utils import SUBST_VARS_RECURSIVE, TO_LIST def subst_at_vars(task): diff --git a/buildtools/wafsamba/samba3.py b/buildtools/wafsamba/samba3.py index 44daff9de2c..786d6a65c7c 100644 --- a/buildtools/wafsamba/samba3.py +++ b/buildtools/wafsamba/samba3.py @@ -1,11 +1,12 @@ # a waf tool to add autoconf-like macros to the configure section # and for SAMBA_ macros for building libraries, binaries etc -import Options, Build, os +import os +from waflib import Options, Build from samba_utils import os_path_relpath, TO_LIST, samba_add_onoff_option from samba_autoconf import library_flags -Options.Handler.SAMBA3_ADD_OPTION = samba_add_onoff_option +Options.OptionsContext.SAMBA3_ADD_OPTION = samba_add_onoff_option def SAMBA3_IS_STATIC_MODULE(bld, module): '''Check whether module is in static list''' @@ -32,7 +33,7 @@ def s3_fix_kwargs(bld, kwargs): '''fix the build arguments for s3 build rules to include the necessary includes, subdir and cflags options ''' s3dir = os.path.join(bld.env.srcdir, 'source3') - s3reldir = os_path_relpath(s3dir, bld.curdir) + s3reldir = os_path_relpath(s3dir, bld.path.abspath()) # the extra_includes list is relative to the source3 directory extra_includes = [ '.', 'include', 'lib' ] diff --git a/buildtools/wafsamba/samba_abi.py b/buildtools/wafsamba/samba_abi.py index 4603e764fea..be46a9e6286 100644 --- a/buildtools/wafsamba/samba_abi.py +++ b/buildtools/wafsamba/samba_abi.py @@ -1,7 +1,13 @@ # functions for handling ABI checking of libraries -import Options, Utils, os, Logs, samba_utils, sys, Task, fnmatch, re, Build -from TaskGen import feature, before, after +import os +import sys +import re +import fnmatch + +from waflib import Options, Utils, Logs, Task, Build, Errors +from waflib.TaskGen import feature, before, after +import samba_utils # these type maps cope with platform specific names for common types # please add new type mappings into the list below @@ -87,7 +93,7 @@ def abi_check_task(self): old_sigs = samba_utils.load_file(sig_file) if old_sigs is None or Options.options.ABI_UPDATE: if not save_sigs(sig_file, parsed_sigs): - raise Utils.WafError('Failed to save ABI file "%s"' % sig_file) + raise Errors.WafError('Failed to save ABI file "%s"' % sig_file) Logs.warn('Generated ABI signatures %s' % sig_file) return @@ -112,10 +118,10 @@ def abi_check_task(self): got_error = True if got_error: - raise Utils.WafError('ABI for %s has changed - please fix library version then build with --abi-update\nSee http://wiki.samba.org/index.php/Waf#ABI_Checking for more information\nIf you have not changed any ABI, and your platform always gives this error, please configure with --abi-check-disable to skip this check' % libname) + raise Errors.WafError('ABI for %s has changed - please fix library version then build with --abi-update\nSee http://wiki.samba.org/index.php/Waf#ABI_Checking for more information\nIf you have not changed any ABI, and your platform always gives this error, please configure with --abi-check-disable to skip this check' % libname) -t = Task.task_type_from_func('abi_check', abi_check_task, color='BLUE', ext_in='.bin') +t = Task.task_factory('abi_check', abi_check_task, color='BLUE', ext_in='.bin') t.quiet = True # allow "waf --abi-check" to force re-checking the ABI if '--abi-check' in sys.argv: diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py index 521febcb530..97d50123256 100644 --- a/buildtools/wafsamba/samba_autoconf.py +++ b/buildtools/wafsamba/samba_autoconf.py @@ -1,9 +1,10 @@ # a waf tool to add autoconf-like macros to the configure section import os, sys -import Build, Options, preproc, Logs -from Configure import conf -from TaskGen import feature +from waflib import Build, Options, Logs, Context +from waflib.Configure import conf +from waflib.TaskGen import feature +from waflib.Tools import c_preproc as preproc from samba_utils import TO_LIST, GET_TARGET_TYPE, SET_TARGET_TYPE, unique_list, mkdir_p missing_headers = set() @@ -44,11 +45,11 @@ def COMPOUND_START(conf, msg): if v != [] and v != 0: conf.env.in_compound = v + 1 return - conf.check_message_1(msg) - conf.saved_check_message_1 = conf.check_message_1 - conf.check_message_1 = null_check_message_1 - conf.saved_check_message_2 = conf.check_message_2 - conf.check_message_2 = null_check_message_2 + conf.start_msg(msg) + conf.saved_check_message_1 = conf.start_msg + conf.start_msg = null_check_message_1 + conf.saved_check_message_2 = conf.end_msg + conf.end_msg = null_check_message_2 conf.env.in_compound = 1 @@ -58,9 +59,9 @@ def COMPOUND_END(conf, result): conf.env.in_compound -= 1 if conf.env.in_compound != 0: return - conf.check_message_1 = conf.saved_check_message_1 - conf.check_message_2 = conf.saved_check_message_2 - p = conf.check_message_2 + conf.start_msg = conf.saved_check_message_1 + conf.end_msg = conf.saved_check_message_2 + p = conf.end_msg if result is True: p('ok') elif not result: @@ -404,7 +405,7 @@ def CHECK_CODE(conf, code, define, cflags.append(extra_cflags) if local_include: - cflags.append('-I%s' % conf.curdir) + cflags.append('-I%s' % conf.path.abspath()) if not link: type='nolink' @@ -663,8 +664,8 @@ def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, @conf def IN_LAUNCH_DIR(conf): '''return True if this rule is being run from the launch directory''' - return os.path.realpath(conf.curdir) == os.path.realpath(Options.launch_dir) -Options.Handler.IN_LAUNCH_DIR = IN_LAUNCH_DIR + return os.path.realpath(conf.path.abspath()) == os.path.realpath(Context.launch_dir) +Options.OptionsContext.IN_LAUNCH_DIR = IN_LAUNCH_DIR @conf @@ -899,7 +900,7 @@ def SETUP_CONFIGURE_CACHE(conf, enable): # when -C is chosen, we will use a private cache and will # not look into system includes. This roughtly matches what # autoconf does with -C - cache_path = os.path.join(conf.blddir, '.confcache') + cache_path = os.path.join(conf.bldnode.abspath(), '.confcache') mkdir_p(cache_path) Options.cache_global = os.environ['WAFCACHE'] = cache_path else: diff --git a/buildtools/wafsamba/samba_autoproto.py b/buildtools/wafsamba/samba_autoproto.py index 52b2d7ecc30..ace434f3c6b 100644 --- a/buildtools/wafsamba/samba_autoproto.py +++ b/buildtools/wafsamba/samba_autoproto.py @@ -1,13 +1,13 @@ # waf build tool for building automatic prototypes from C source import os -import Build +from waflib import Build from samba_utils import SET_TARGET_TYPE, os_path_relpath def SAMBA_AUTOPROTO(bld, header, source): '''rule for samba prototype generation''' bld.SET_BUILD_GROUP('prototypes') - relpath = os_path_relpath(bld.curdir, bld.srcnode.abspath()) + relpath = os_path_relpath(bld.path.abspath(), bld.srcnode.abspath()) name = os.path.join(relpath, header) SET_TARGET_TYPE(bld, name, 'PROTOTYPE') t = bld( diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py index 253d604fd97..fea4cb2bc3c 100644 --- a/buildtools/wafsamba/samba_bundled.py +++ b/buildtools/wafsamba/samba_bundled.py @@ -1,8 +1,8 @@ # functions to support bundled libraries import sys -import Build, Options, Logs -from Configure import conf +from waflib import Build, Options, Logs +from waflib.Configure import conf from samba_utils import TO_LIST def PRIVATE_NAME(bld, name, private_extension, private_library): @@ -51,19 +51,19 @@ Build.BuildContext.BUILTIN_LIBRARY = BUILTIN_LIBRARY def BUILTIN_DEFAULT(opt, builtins): '''set a comma separated default list of builtin libraries for this package''' - if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options: + if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options.__dict__: return - Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins -Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT + Options.options.__dict__['BUILTIN_LIBRARIES_DEFAULT'] = builtins +Options.OptionsContext.BUILTIN_DEFAULT = BUILTIN_DEFAULT def PRIVATE_EXTENSION_DEFAULT(opt, extension, noextension=''): '''set a default private library extension''' - if 'PRIVATE_EXTENSION_DEFAULT' in Options.options: + if 'PRIVATE_EXTENSION_DEFAULT' in Options.options.__dict__: return - Options.options['PRIVATE_EXTENSION_DEFAULT'] = extension - Options.options['PRIVATE_EXTENSION_EXCEPTION'] = noextension -Options.Handler.PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT + Options.options.__dict__['PRIVATE_EXTENSION_DEFAULT'] = extension + Options.options.__dict__['PRIVATE_EXTENSION_EXCEPTION'] = noextension +Options.OptionsContext.PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT def minimum_library_version(conf, libname, default): diff --git a/buildtools/wafsamba/samba_conftests.py b/buildtools/wafsamba/samba_conftests.py index 74f97821c38..5af57e24e31 100644 --- a/buildtools/wafsamba/samba_conftests.py +++ b/buildtools/wafsamba/samba_conftests.py @@ -2,35 +2,35 @@ # to test for commonly needed configuration options import os, shutil, re -import Build, Configure, Utils, Options, Logs -from Configure import conf +from waflib import Build, Configure, Utils, Options, Logs, Errors +from waflib.Configure import conf from samba_utils import TO_LIST, ADD_LD_LIBRARY_PATH def add_option(self, *k, **kw): '''syntax help: provide the "match" attribute to opt.add_option() so that folders can be added to specific config tests''' - Options.parser = self + Options.OptionsContext.parser = self match = kw.get('match', []) if match: del kw['match'] opt = self.parser.add_option(*k, **kw) opt.match = match return opt -Options.Handler.add_option = add_option +Options.OptionsContext.add_option = add_option @conf def check(self, *k, **kw): '''Override the waf defaults to inject --with-directory options''' if not 'env' in kw: - kw['env'] = self.env.copy() + kw['env'] = self.env.derive() # match the configuration test with specific options, for example: # --with-libiconv -> Options.options.iconv_open -> "Checking for library iconv" additional_dirs = [] if 'msg' in kw: msg = kw['msg'] - for x in Options.Handler.parser.parser.option_list: + for x in Options.OptionsContext.parser.parser.option_list: if getattr(x, 'match', None) and msg in x.match: d = getattr(Options.options, x.dest, '') if d: @@ -47,12 +47,12 @@ def check(self, *k, **kw): add_options_dir(additional_dirs, kw['env']) self.validate_c(kw) - self.check_message_1(kw['msg']) + self.start_msg(kw['msg']) ret = None try: ret = self.run_c_code(*k, **kw) except Configure.ConfigurationError as e: - self.check_message_2(kw['errmsg'], 'YELLOW') + self.end_msg(kw['errmsg'], 'YELLOW') if 'mandatory' in kw and kw['mandatory']: if Logs.verbose > 1: raise @@ -60,7 +60,7 @@ def check(self, *k, **kw): self.fatal('the configuration failed (see %r)' % self.log.name) else: kw['success'] = ret - self.check_message_2(self.ret_msg(kw['okmsg'], kw)) + self.end_msg(self.ret_msg(kw['okmsg'], kw)) # success! keep the CPPPATH/LIBPATH add_options_dir(additional_dirs, self.env) @@ -163,7 +163,7 @@ def find_config_dir(conf): '''find a directory to run tests in''' k = 0 while k < 10000: - dir = os.path.join(conf.blddir, '.conf_check_%d' % k) + dir = os.path.join(conf.bldnode.abspath(), '.conf_check_%d' % k) try: shutil.rmtree(dir) except OSError: @@ -338,7 +338,8 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None): # we need to run the program, try to get its result args = conf.SAMBA_CROSS_ARGS(msg=msg) - proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE) + proc = Utils.subprocess.Popen([lastprog] + args, + stdout=Utils.subprocess.PIPE, stderr=Utils.subprocess.PIPE) (out, err) = proc.communicate() w = conf.log.write w(str(out)) @@ -365,7 +366,7 @@ def CHECK_PERL_MANPAGE(conf, msg=None, section=None): else: msg = "perl manpage generation" - conf.check_message_1(msg) + conf.start_msg(msg) dir = find_config_dir(conf) @@ -382,28 +383,28 @@ WriteMakefile( """) back = os.path.abspath('.') os.chdir(bdir) - proc = Utils.pproc.Popen(['perl', 'Makefile.PL'], - stdout=Utils.pproc.PIPE, - stderr=Utils.pproc.PIPE) + proc = Utils.subprocess.Popen(['perl', 'Makefile.PL'], + stdout=Utils.subprocess.PIPE, + stderr=Utils.subprocess.PIPE) (out, err) = proc.communicate() os.chdir(back) ret = (proc.returncode == 0) if not ret: - conf.check_message_2('not found', color='YELLOW') + conf.end_msg('not found', color='YELLOW') return if section: man = Utils.readf(os.path.join(bdir,'Makefile')) m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man) if not m: - conf.check_message_2('not found', color='YELLOW') + conf.end_msg('not found', color='YELLOW') return ext = m.group(1) - conf.check_message_2(ext) + conf.end_msg(ext) return ext - conf.check_message_2('ok') + conf.end_msg('ok') return True @@ -512,7 +513,7 @@ def CHECK_STANDARD_LIBPATH(conf): # option not supported by compiler - use a standard list of directories dirlist = [ '/usr/lib', '/usr/lib64' ] except: - raise Utils.WafError('Unexpected error running "%s"' % (cmd)) + raise Errors.WafError('Unexpected error running "%s"' % (cmd)) else: dirlist = [] for line in out: diff --git a/buildtools/wafsamba/samba_cross.py b/buildtools/wafsamba/samba_cross.py index b8f2000659f..5191acb7c04 100644 --- a/buildtools/wafsamba/samba_cross.py +++ b/buildtools/wafsamba/samba_cross.py @@ -1,8 +1,8 @@ # functions for handling cross-compilation import os, sys, re, shlex -import Utils, Logs, Options -from Configure import conf +from waflib import Utils, Logs, Options, Errors +from waflib.Configure import conf real_Popen = None @@ -81,12 +81,12 @@ def cross_answer(ca_file, msg): f.close() return (int(m.group(1)), m.group(2)) else: - raise Utils.WafError("Bad answer format '%s' in %s" % (line, ca_file)) + raise Errors.WafError("Bad answer format '%s' in %s" % (line, ca_file)) f.close() return ANSWER_UNKNOWN -class cross_Popen(Utils.pproc.Popen): +class cross_Popen(Utils.subprocess.Popen): '''cross-compilation wrapper for Popen''' def __init__(*k, **kw): (obj, args) = k @@ -154,11 +154,11 @@ def SAMBA_CROSS_ARGS(conf, msg=None): if conf.env.CROSS_ANSWERS: if msg is None: - raise Utils.WafError("Cannot have NULL msg in cross-answers") + raise Errors.WafError("Cannot have NULL msg in cross-answers") ret.extend(['--cross-answers', os.path.join(Options.launch_dir, conf.env.CROSS_ANSWERS), msg]) if ret == []: - raise Utils.WafError("Cannot cross-compile without either --cross-execute or --cross-answers") + raise Errors.WafError("Cannot cross-compile without either --cross-execute or --cross-answers") return ret @@ -167,5 +167,5 @@ def SAMBA_CROSS_CHECK_COMPLETE(conf): '''check if we have some unanswered questions''' global cross_answers_incomplete if conf.env.CROSS_COMPILE and cross_answers_incomplete: - raise Utils.WafError("Cross answers file %s is incomplete" % conf.env.CROSS_ANSWERS) + raise Errors.WafError("Cross answers file %s is incomplete" % conf.env.CROSS_ANSWERS) return True diff --git a/buildtools/wafsamba/samba_deps.py b/buildtools/wafsamba/samba_deps.py index 72892be03e6..542e682619c 100644 --- a/buildtools/wafsamba/samba_deps.py +++ b/buildtools/wafsamba/samba_deps.py @@ -2,9 +2,10 @@ import os, sys, re, time -import Build, Environment, Options, Logs, Utils -from Logs import debug -from Configure import conf +from waflib import Build, Options, Logs, Utils, Errors +from waflib.Logs import debug +from waflib.Configure import conf +from waflib import ConfigSet from samba_bundled import BUILTIN_LIBRARY from samba_utils import LOCAL_CACHE, TO_LIST, get_tgt_list, unique_list, os_path_relpath @@ -302,7 +303,7 @@ def check_duplicate_sources(bld, tgt_list): Logs.warn("WARNING: source %s is in more than one target: %s" % (s, subsystems[s].keys())) for tname in subsystems[s]: if len(subsystems[s][tname]) > 1: - raise Utils.WafError("ERROR: source %s is in more than one subsystem of target '%s': %s" % (s, tname, subsystems[s][tname])) + raise Errors.WafError("ERROR: source %s is in more than one subsystem of target '%s': %s" % (s, tname, subsystems[s][tname])) return True @@ -963,7 +964,7 @@ savedeps_files = ['buildtools/wafsamba/samba_deps.py'] def save_samba_deps(bld, tgt_list): '''save the dependency calculations between builds, to make further builds faster''' - denv = Environment.Environment() + denv = ConfigSet.ConfigSet() denv.version = savedeps_version denv.savedeps_inputs = savedeps_inputs @@ -1017,8 +1018,8 @@ def save_samba_deps(bld, tgt_list): def load_samba_deps(bld, tgt_list): '''load a previous set of build dependencies if possible''' - depsfile = os.path.join(bld.bdir, "sambadeps") - denv = Environment.Environment() + depsfile = os.path.join(bld.bldnode.abspath(), "sambadeps") + denv = ConfigSet.ConfigSet() try: debug('deps: checking saved dependencies') denv.load_fast(depsfile) diff --git a/buildtools/wafsamba/samba_dist.py b/buildtools/wafsamba/samba_dist.py index 06c973a72a1..29c5fd14e6d 100644 --- a/buildtools/wafsamba/samba_dist.py +++ b/buildtools/wafsamba/samba_dist.py @@ -2,8 +2,8 @@ # uses git ls-files to get file lists import os, sys, tarfile -import Utils, Scripting, Logs, Options -from Configure import conf +from waflib import Utils, Scripting, Logs, Options +from waflib.Configure import conf from samba_utils import os_path_relpath from waflib import Context @@ -164,12 +164,12 @@ def dist(appname='', version=''): if not isinstance(appname, str) or not appname: # this copes with a mismatch in the calling arguments for dist() - appname = Utils.g_module.APPNAME - version = Utils.g_module.VERSION + appname = Context.g_module.APPNAME + version = Context.g_module.VERSION if not version: - version = Utils.g_module.VERSION + version = Context.g_module.VERSION - srcdir = os.path.normpath(os.path.join(os.path.dirname(Utils.g_module.root_path), Utils.g_module.srcdir)) + srcdir = os.path.normpath(os.path.join(os.path.dirname(Context.g_module.root_path), Context.g_module.srcdir)) if not dist_dirs: Logs.error('You must use samba_dist.DIST_DIRS() to set which directories to package') diff --git a/buildtools/wafsamba/samba_headers.py b/buildtools/wafsamba/samba_headers.py index 0a800826196..a268c011c5d 100644 --- a/buildtools/wafsamba/samba_headers.py +++ b/buildtools/wafsamba/samba_headers.py @@ -1,7 +1,7 @@ # specialist handling of header files for Samba import os, re, sys, fnmatch -import Build, Logs, Utils +from waflib import Build, Logs, Utils, Errors from samba_utils import TO_LIST, os_path_relpath @@ -99,7 +99,7 @@ def create_public_header(task): os.unlink(tgt) sys.stderr.write("%s:%u:Error: unable to resolve public header %s (maybe try one of %s)\n" % ( os.path.relpath(src, os.getcwd()), linenumber, hpath, suggested)) - raise Utils.WafError("Unable to resolve header path '%s' in public header '%s' in directory %s" % ( + raise Errors.WafError("Unable to resolve header path '%s' in public header '%s' in directory %s" % ( hpath, relsrc, task.env.RELPATH)) infile.close() outfile.close() @@ -148,11 +148,12 @@ def PUBLIC_HEADERS(bld, public_headers, header_path=None, public_headers_install else: h_name = h inst_name = os.path.basename(h) - relpath1 = os_path_relpath(bld.srcnode.abspath(), bld.curdir) - relpath2 = os_path_relpath(bld.curdir, bld.srcnode.abspath()) + curdir = bld.path.abspath() + relpath1 = os_path_relpath(bld.srcnode.abspath(), curdir) + relpath2 = os_path_relpath(curdir, bld.srcnode.abspath()) targetdir = os.path.normpath(os.path.join(relpath1, bld.env.build_public_headers, inst_path)) - if not os.path.exists(os.path.join(bld.curdir, targetdir)): - raise Utils.WafError("missing source directory %s for public header %s" % (targetdir, inst_name)) + if not os.path.exists(os.path.join(curdir, targetdir)): + raise Errors.WafError("missing source directory %s for public header %s" % (targetdir, inst_name)) target = os.path.join(targetdir, inst_name) # the source path of the header, relative to the top of the source tree diff --git a/buildtools/wafsamba/samba_install.py b/buildtools/wafsamba/samba_install.py index e967a320217..47bc0cbf90c 100644 --- a/buildtools/wafsamba/samba_install.py +++ b/buildtools/wafsamba/samba_install.py @@ -4,8 +4,8 @@ # library use import os -import Utils -from TaskGen import feature, before, after +from waflib import Utils, Errors +from waflib.TaskGen import feature, before, after from samba_utils import LIB_PATH, MODE_755, install_rpath, build_rpath @feature('install_bin') @@ -228,7 +228,7 @@ def symlink_bin(self): return if not self.link_task.outputs or not self.link_task.outputs[0]: - raise Utils.WafError('no outputs found for %s in symlink_bin' % self.name) + raise Errors.WafError('no outputs found for %s in symlink_bin' % self.name) binpath = self.link_task.outputs[0].abspath(self.env) bldpath = os.path.join(self.bld.env.BUILD_DIRECTORY, self.link_task.outputs[0].name) diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py index 2b939372fa4..00bedcda9c3 100644 --- a/buildtools/wafsamba/samba_patterns.py +++ b/buildtools/wafsamba/samba_patterns.py @@ -1,6 +1,6 @@ # a waf tool to add extension based build patterns for Samba -import Build +from waflib import Build from wafsamba import samba_version_file def write_version_header(task): diff --git a/buildtools/wafsamba/samba_perl.py b/buildtools/wafsamba/samba_perl.py index 48d9a96a6b3..eca72d65790 100644 --- a/buildtools/wafsamba/samba_perl.py +++ b/buildtools/wafsamba/samba_perl.py @@ -1,5 +1,5 @@ -import Utils -from Configure import conf +from waflib import Utils +from waflib.Configure import conf done = {} @@ -9,7 +9,7 @@ def SAMBA_CHECK_PERL(conf, mandatory=True, version=(5,0,0)): return done["done"] = True conf.find_program('perl', var='PERL', mandatory=mandatory) - conf.check_tool('perl') + conf.load('perl') path_perl = conf.find_program('perl') conf.env.PERL_SPECIFIED = (conf.env.PERL != path_perl) conf.check_perl_version(version) diff --git a/buildtools/wafsamba/samba_pidl.py b/buildtools/wafsamba/samba_pidl.py index 79f081d3338..2ff2c0dc64d 100644 --- a/buildtools/wafsamba/samba_pidl.py +++ b/buildtools/wafsamba/samba_pidl.py @@ -1,8 +1,8 @@ # waf build tool for building IDL files with pidl import os -import Build, Utils -from TaskGen import feature, before +from waflib import Build, Utils +from waflib.TaskGen import feature, before from samba_utils import SET_TARGET_TYPE, TO_LIST, LOCAL_CACHE def SAMBA_PIDL(bld, pname, source, @@ -97,7 +97,7 @@ def SAMBA_PIDL(bld, pname, source, pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS') pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])] - t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode) + t.more_includes = '#' + bld.path.path_from(bld.srcnode) Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index a7ffb7afaec..aecaf7d4de7 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -1,8 +1,8 @@ # waf build tool for building IDL files with pidl import os -import Build, Logs, Utils, Configure -from Configure import conf +from waflib import Build, Logs, Utils, Configure, Errors +from waflib.Configure import conf @conf def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)): @@ -14,12 +14,12 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)): interpreters = [] if conf.env['EXTRA_PYTHON']: - conf.all_envs['extrapython'] = conf.env.copy() + conf.all_envs['extrapython'] = conf.env.derive() conf.setenv('extrapython') conf.env['PYTHON'] = conf.env['EXTRA_PYTHON'] conf.env['IS_EXTRA_PYTHON'] = 'yes' conf.find_program('python', var='PYTHON', mandatory=True) - conf.check_tool('python') + conf.load('python') try: conf.check_python_version((3, 3, 0)) except Exception: @@ -29,7 +29,7 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)): conf.setenv('default') conf.find_program('python', var='PYTHON', mandatory=mandatory) - conf.check_tool('python') + conf.load('python') path_python = conf.find_program('python') conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python) conf.check_python_version(version) @@ -42,7 +42,7 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)): def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True): if conf.env.disable_python: if mandatory: - raise Utils.WafError("Cannot check for python headers when " + raise Errors.WafError("Cannot check for python headers when " "--disable-python specified") conf.msg("python headers", "Check disabled due to --disable-python") @@ -66,7 +66,7 @@ def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True): if conf.env['EXTRA_PYTHON']: extraversion = conf.all_envs['extrapython']['PYTHON_VERSION'] if extraversion == conf.env['PYTHON_VERSION']: - raise Utils.WafError("extrapython %s is same as main python %s" % ( + raise Errors.WafError("extrapython %s is same as main python %s" % ( extraversion, conf.env['PYTHON_VERSION'])) else: conf.msg("python headers", "using cache") @@ -79,9 +79,9 @@ def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True): def _check_python_headers(conf, mandatory): try: - Configure.ConfigurationError + conf.errors.ConfigurationError conf.check_python_headers() - except Configure.ConfigurationError: + except conf.errors.ConfigurationError: if mandatory: raise diff --git a/buildtools/wafsamba/samba_third_party.py b/buildtools/wafsamba/samba_third_party.py index 1144f813ab6..0ababa56065 100644 --- a/buildtools/wafsamba/samba_third_party.py +++ b/buildtools/wafsamba/samba_third_party.py @@ -1,12 +1,12 @@ # functions to support third party libraries import os -import Utils, Build -from Configure import conf +from waflib import Utils, Build, Context +from waflib.Configure import conf @conf def CHECK_FOR_THIRD_PARTY(conf): - return os.path.exists(os.path.join(Utils.g_module.srcdir, 'third_party')) + return os.path.exists(os.path.join(Context.g_module.srcdir, 'third_party')) Build.BuildContext.CHECK_FOR_THIRD_PARTY = CHECK_FOR_THIRD_PARTY diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py index 925e874f302..a2afbbf9b66 100644 --- a/buildtools/wafsamba/samba_utils.py +++ b/buildtools/wafsamba/samba_utils.py @@ -3,10 +3,11 @@ import os, sys, re, fnmatch, shlex, inspect from optparse import SUPPRESS_HELP -from waflib import Build, Options, Utils, Task, Logs, Configure, Errors -from TaskGen import feature, before, after -from Configure import ConfigurationContext -from Logs import debug +from waflib import Build, Options, Utils, Task, Logs, Configure, Errors, Context +from waflib.TaskGen import feature, before, after +from waflib.Configure import ConfigurationContext +from waflib.Logs import debug +from waflib import ConfigSet # TODO: make this a --option LIB_PATH="shared" @@ -45,10 +46,10 @@ def SET_TARGET_TYPE(ctx, target, value): '''set the target type of a target''' cache = LOCAL_CACHE(ctx, 'TARGET_TYPE') if target in cache and cache[target] != 'EMPTY': - Logs.error("ERROR: Target '%s' in directory %s re-defined as %s - was %s" % (target, ctx.curdir, value, cache[target])) + Logs.error("ERROR: Target '%s' in directory %s re-defined as %s - was %s" % (target, ctx.path.abspath(), value, cache[target])) sys.exit(1) LOCAL_CACHE_SET(ctx, 'TARGET_TYPE', target, value) - debug("task_gen: Target '%s' created of type '%s' in %s" % (target, value, ctx.curdir)) + debug("task_gen: Target '%s' created of type '%s' in %s" % (target, value, ctx.path.abspath())) return True @@ -125,7 +126,7 @@ def LOCAL_CACHE_SET(ctx, cachename, key, value): def ASSERT(ctx, expression, msg): '''a build assert call''' if not expression: - raise Utils.WafError("ERROR: %s\n" % msg) + raise Errors.WafError("ERROR: %s\n" % msg) Build.BuildContext.ASSERT = ASSERT @@ -146,9 +147,9 @@ def dict_concat(d1, d2): def ADD_COMMAND(opt, name, function): '''add a new top level command to waf''' - Utils.g_module.__dict__[name] = function + Context.g_module.__dict__[name] = function opt.name = function -Options.Handler.ADD_COMMAND = ADD_COMMAND +Options.OptionsContext.ADD_COMMAND = ADD_COMMAND @feature('c', 'cc', 'cshlib', 'cprogram') @@ -223,7 +224,7 @@ def subst_vars_error(string, env): if re.match('\$\{\w+\}', v): vname = v[2:-1] if not vname in env: - raise KeyError("Failed to find variable %s in %s" % (vname, string)) + raise KeyError("Failed to find variable %s in %s in env %s <%s>" % (vname, string, env.__class__, str(env))) v = env[vname] if isinstance(v, list): v = ' '.join(v) @@ -338,8 +339,7 @@ def EXPAND_VARIABLES(ctx, varstr, vars=None): if not isinstance(varstr, str): return varstr - import Environment - env = Environment.Environment() + env = ConfigSet.ConfigSet() ret = varstr # substitute on user supplied dict if avaiilable if vars is not None: @@ -378,7 +378,7 @@ def RUN_COMMAND(cmd, def RUN_PYTHON_TESTS(testfiles, pythonpath=None, extra_env=None): env = LOAD_ENVIRONMENT() if pythonpath is None: - pythonpath = os.path.join(Utils.g_module.blddir, 'python') + pythonpath = os.path.join(Context.g_module.blddir, 'python') result = 0 for interp in env.python_interpreters: if not isinstance(interp, str): @@ -410,8 +410,7 @@ except: # Try to use MD5 function. In FIPS mode this will cause an exception foo = md5.md5('abcd') except: - import Constants - Constants.SIG_NIL = hash('abcd') + Context.SIG_NIL = hash('abcd') class replace_md5(object): def __init__(self): self.val = None @@ -437,10 +436,10 @@ except: def LOAD_ENVIRONMENT(): '''load the configuration environment, allowing access to env vars from new commands''' - import Environment - env = Environment.Environment() + env = ConfigSet.ConfigSet() try: - env.load('bin/c4che/default_cache.py') + p = os.path.join(Context.g_module.out, 'c4che/default_cache.py') + env.load(p) except (OSError, IOError): pass return env @@ -448,8 +447,9 @@ def LOAD_ENVIRONMENT(): def IS_NEWER(bld, file1, file2): '''return True if file1 is newer than file2''' - t1 = os.stat(os.path.join(bld.curdir, file1)).st_mtime - t2 = os.stat(os.path.join(bld.curdir, file2)).st_mtime + curdir = bld.path.abspath() + t1 = os.stat(os.path.join(curdir, file1)).st_mtime + t2 = os.stat(os.path.join(curdir, file2)).st_mtime return t1 > t2 Build.BuildContext.IS_NEWER = IS_NEWER @@ -459,31 +459,27 @@ def RECURSE(ctx, directory): '''recurse into a directory, relative to the curdir or top level''' try: visited_dirs = ctx.visited_dirs - except: + except AttributeError: visited_dirs = ctx.visited_dirs = set() - d = os.path.join(ctx.curdir, directory) + d = os.path.join(ctx.path.abspath(), directory) if os.path.exists(d): abspath = os.path.abspath(d) else: - abspath = os.path.abspath(os.path.join(Utils.g_module.srcdir, directory)) + abspath = os.path.abspath(os.path.join(Context.g_module.srcdir, directory)) ctxclass = ctx.__class__.__name__ key = ctxclass + ':' + abspath if key in visited_dirs: # already done it return visited_dirs.add(key) - relpath = os_path_relpath(abspath, ctx.curdir) + relpath = os_path_relpath(abspath, ctx.path.abspath()) + if ctxclass in ['tmp', 'OptionsContext', 'ConfigurationContext', 'BuildContext']: + return ctx.recurse(relpath) if 'waflib.extras.compat15' in sys.modules: return ctx.recurse(relpath) - if ctxclass == 'Handler': - return ctx.sub_options(relpath) - if ctxclass == 'ConfigurationContext': - return ctx.sub_config(relpath) - if ctxclass == 'BuildContext': - return ctx.add_subdirs(relpath) - Logs.error('Unknown RECURSE context class', ctxclass) + Logs.error('Unknown RECURSE context class: {}'.format(ctxclass)) raise -Options.Handler.RECURSE = RECURSE +Options.OptionsContext.RECURSE = RECURSE Build.BuildContext.RECURSE = RECURSE @@ -542,7 +538,7 @@ def option_group(opt, name): gr = opt.add_option_group(name) option_groups[name] = gr return gr -Options.Handler.option_group = option_group +Options.OptionsContext.option_group = option_group def save_file(filename, contents, create_dir=False): @@ -571,9 +567,9 @@ def load_file(filename): def reconfigure(ctx): '''rerun configure if necessary''' - import Configure, samba_wildcard, Scripting if not os.path.exists(".lock-wscript"): - raise Utils.WafError('configure has not been run') + raise Errors.WafError('configure has not been run') + import samba_wildcard bld = samba_wildcard.fake_build_environment() Configure.autoconfig = True Scripting.check_configured(bld) @@ -646,7 +642,7 @@ def get_tgt_list(bld): tgt_list.append(t) return tgt_list -from Constants import WSCRIPT_FILE +from waflib.Context import WSCRIPT_FILE def PROCESS_SEPARATE_RULE(self, rule): ''' cause waf to process additional script based on `rule'. You should have file named wscript_<stage>_rule in the current directory @@ -657,15 +653,21 @@ def PROCESS_SEPARATE_RULE(self, rule): stage = 'configure' elif isinstance(self, Build.BuildContext): stage = 'build' - file_path = os.path.join(self.curdir, WSCRIPT_FILE+'_'+stage+'_'+rule) - txt = load_file(file_path) - if txt: - dc = {'ctx': self} - if getattr(self.__class__, 'pre_recurse', None): - dc = self.pre_recurse(txt, file_path, self.curdir) - exec(compile(txt, file_path, 'exec'), dc) - if getattr(self.__class__, 'post_recurse', None): - dc = self.post_recurse(txt, file_path, self.curdir) + file_path = os.path.join(self.path.abspath(), WSCRIPT_FILE+'_'+stage+'_'+rule) + node = self.root.find_node(file_path) + if node: + try: + cache = self.recurse_cache + except AttributeError: + cache = self.recurse_cache = {} + if node not in cache: + cache[node] = True + self.pre_recurse(node) + try: + function_code = node.read('rU', None) + exec(compile(function_code, node.abspath(), 'exec'), self.exec_dict) + finally: + self.post_recurse(node) Build.BuildContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE ConfigurationContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE @@ -722,4 +724,4 @@ def samba_add_onoff_option(opt, option, help=(), dest=None, default=True, default=default) opt.add_option(without_val, help=SUPPRESS_HELP, action="store_false", dest=dest) -Options.Handler.samba_add_onoff_option = samba_add_onoff_option +Options.OptionsContext.samba_add_onoff_option = samba_add_onoff_option diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index be26439f1a6..239f2445503 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -1,5 +1,5 @@ import os -import Utils +from waflib import Utils, Context import samba_utils from samba_git import find_git @@ -260,5 +260,5 @@ def load_version(env=None, is_install=True): env = samba_utils.LOAD_ENVIRONMENT() version = samba_version_file("./VERSION", ".", env, is_install=is_install) - Utils.g_module.VERSION = version.STRING + Context.g_module.VERSION = version.STRING return version diff --git a/buildtools/wafsamba/samba_waf18.py b/buildtools/wafsamba/samba_waf18.py index 6c3523efa62..0bb9b1b1d15 100644 --- a/buildtools/wafsamba/samba_waf18.py +++ b/buildtools/wafsamba/samba_waf18.py @@ -1,10 +1,10 @@ # compatibility layer for building with more recent waf versions import os, shlex, sys -import Build, Configure, Node, Utils, Options, Logs +from waflib import Build, Configure, Node, Utils, Options, Logs from waflib import ConfigSet -from TaskGen import feature, after -from Configure import conf, ConfigurationContext +from waflib.TaskGen import feature, after +from waflib.Configure import conf, ConfigurationContext from waflib.Tools import bison, flex sys.modules['bison'] = bison @@ -119,32 +119,6 @@ def find_program_samba(self, *k, **kw): Configure.ConfigurationContext.find_program_old = Configure.ConfigurationContext.find_program Configure.ConfigurationContext.find_program = find_program_samba -def PROCESS_SEPARATE_RULE(self, rule): - ''' cause waf to process additional script based on `rule'. - You should have file named wscript_<stage>_rule in the current directory - where stage is either 'configure' or 'build' - ''' - stage = '' - if isinstance(self, Configure.ConfigurationContext): - stage = 'configure' - elif isinstance(self, Build.BuildContext): - stage = 'build' - script = self.path.find_node('wscript_'+stage+'_'+rule) - if script: - txt = script.read() - bld = self - conf = self - ctx = self - dc = {'ctx': self, 'conf': self, 'bld': self} - if getattr(self.__class__, 'pre_recurse', None): - dc = self.pre_recurse(script) - exec(compile(txt, script.abspath(), 'exec'), dc) - if getattr(self.__class__, 'post_recurse', None): - dc = self.post_recurse(script) - -Build.BuildContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE -ConfigurationContext.PROCESS_SEPARATE_RULE = PROCESS_SEPARATE_RULE - Build.BuildContext.ENFORCE_GROUP_ORDERING = Utils.nada Build.BuildContext.AUTOCLEANUP_STALE_FILES = Utils.nada @@ -159,7 +133,7 @@ def check(self, *k, **kw): additional_dirs = [] if 'msg' in kw: msg = kw['msg'] - for x in Options.parser.parser.option_list: + for x in Options.OptionsContext.parser.parser.option_list: if getattr(x, 'match', None) and msg in x.match: d = getattr(Options.options, x.dest, '') if d: @@ -265,3 +239,34 @@ def CHECK_CFG(self, *k, **kw): kw['mandatory'] = False kw['global_define'] = True return self.check_cfg(*k, **kw) + +def cmd_output(cmd, **kw): + + silent = False + if 'silent' in kw: + silent = kw['silent'] + del(kw['silent']) + + if 'e' in kw: + tmp = kw['e'] + del(kw['e']) + kw['env'] = tmp + + kw['shell'] = isinstance(cmd, str) + kw['stdout'] = Utils.subprocess.PIPE + if silent: + kw['stderr'] = Utils.subprocess.PIPE + + try: + p = Utils.subprocess.Popen(cmd, **kw) + output = p.communicate()[0] + except OSError as e: + raise ValueError(str(e)) + + if p.returncode: + if not silent: + msg = "command execution failed: %s -> %r" % (cmd, str(output)) + raise ValueError(msg) + output = '' + return output +Utils.cmd_output = cmd_output diff --git a/buildtools/wafsamba/samba_wildcard.py b/buildtools/wafsamba/samba_wildcard.py index ed3e0c26b8d..5e15eff7ba0 100644 --- a/buildtools/wafsamba/samba_wildcard.py +++ b/buildtools/wafsamba/samba_wildcard.py @@ -1,15 +1,15 @@ # based on playground/evil in the waf svn tree import os, datetime, fnmatch -import Scripting, Utils, Options, Logs, Environment -from Constants import SRCDIR, BLDDIR +from waflib import Scripting, Utils, Options, Logs, Errors +from waflib import ConfigSet from samba_utils import LOCAL_CACHE, os_path_relpath def run_task(t, k): '''run a single build task''' ret = t.run() if ret: - raise Utils.WafError("Failed to build %s: %u" % (k, ret)) + raise Errors.WafError("Failed to build %s: %u" % (k, ret)) def run_named_build_task(cmd): @@ -45,7 +45,7 @@ def run_named_build_task(cmd): if not found: - raise Utils.WafError("Unable to find build target matching %s" % cmd) + raise Errors.WafError("Unable to find build target matching %s" % cmd) def rewrite_compile_targets(): @@ -125,7 +125,7 @@ def wildcard_main(missing_cmd_fn): def fake_build_environment(info=True, flush=False): """create all the tasks for the project, but do not run the build return the build context in use""" - bld = getattr(Utils.g_module, 'build_context', Utils.Context)() + bld = getattr(Context.g_module, 'build_context', Utils.Context)() bld = Scripting.check_configured(bld) Options.commands['install'] = False @@ -134,16 +134,15 @@ def fake_build_environment(info=True, flush=False): bld.is_install = 0 # False try: - proj = Environment.Environment(Options.lockfile) + proj = ConfigSet.ConfigSet(Options.lockfile) except IOError: - raise Utils.WafError("Project not configured (run 'waf configure' first)") + raise Errors.WafError("Project not configured (run 'waf configure' first)") - bld.load_dirs(proj[SRCDIR], proj[BLDDIR]) bld.load_envs() if info: Logs.info("Waf: Entering directory `%s'" % bld.bldnode.abspath()) - bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]]) + bld.add_subdirs([os.path.split(Context.g_module.root_path)[0]]) bld.pre_build() if flush: diff --git a/buildtools/wafsamba/stale_files.py b/buildtools/wafsamba/stale_files.py index 2dd08e14974..df127eeece1 100644 --- a/buildtools/wafsamba/stale_files.py +++ b/buildtools/wafsamba/stale_files.py @@ -14,7 +14,7 @@ nodes/tasks, in which case the method will have to be modified to exclude some folders for example. """ -import Logs, Build, os, samba_utils, Options, Utils +import Logs, Build, os, samba_utils, Options, Utils, Errors from Runner import Parallel old_refill_task_list = Parallel.refill_task_list @@ -46,7 +46,7 @@ def replace_refill_task_list(self): # paranoia if bin_base[-4:] != '/bin': - raise Utils.WafError("Invalid bin base: %s" % bin_base) + raise Errors.WafError("Invalid bin base: %s" % bin_base) # obtain the expected list of files expected = [] diff --git a/buildtools/wafsamba/symbols.py b/buildtools/wafsamba/symbols.py index 7ff4bac7c49..502407c60c6 100644 --- a/buildtools/wafsamba/symbols.py +++ b/buildtools/wafsamba/symbols.py @@ -2,8 +2,8 @@ # using nm, producing a set of exposed defined/undefined symbols import os, re, subprocess -import Utils, Build, Options, Logs -from Logs import debug +from waflib import Utils, Build, Options, Logs, Errors +from waflib.Logs import debug from samba_utils import TO_LIST, LOCAL_CACHE, get_tgt_list, os_path_relpath # these are the data structures used in symbols.py: @@ -410,7 +410,7 @@ def check_library_deps(bld, t): if dep2 == name and t.in_library != t2.in_library: Logs.warn("WARNING: mutual dependency %s <=> %s" % (name, real_name(t2.sname))) Logs.warn("Libraries should match. %s != %s" % (t.in_library, t2.in_library)) - # raise Utils.WafError("illegal mutual dependency") + # raise Errors.WafError("illegal mutual dependency") def check_syslib_collisions(bld, tgt_list): @@ -430,7 +430,7 @@ def check_syslib_collisions(bld, tgt_list): Logs.error("ERROR: Target '%s' has symbols '%s' which is also in syslib '%s'" % (t.sname, common, lib)) has_error = True if has_error: - raise Utils.WafError("symbols in common with system libraries") + raise Errors.WafError("symbols in common with system libraries") def check_dependencies(bld, t): @@ -546,7 +546,7 @@ def symbols_whyneeded(task): why = Options.options.WHYNEEDED.split(":") if len(why) != 2: - raise Utils.WafError("usage: WHYNEEDED=TARGET:DEPENDENCY") + raise Errors.WafError("usage: WHYNEEDED=TARGET:DEPENDENCY") target = why[0] subsystem = why[1] @@ -579,7 +579,7 @@ def report_duplicate(bld, binname, sym, libs, fail_on_error): else: libnames.append(lib) if fail_on_error: - raise Utils.WafError("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames)) + raise Errors.WafError("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames)) else: print("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames)) diff --git a/buildtools/wafsamba/tru64cc.py b/buildtools/wafsamba/tru64cc.py index e1bbb1d8858..28b560f7697 100644 --- a/buildtools/wafsamba/tru64cc.py +++ b/buildtools/wafsamba/tru64cc.py @@ -3,11 +3,11 @@ # based on suncc.py from waf import os, optparse -import Utils, Options, Configure -import ccroot, ar -from Configure import conftest +from waflib import Utils, Options, Configure +from waflib.Tools import ccroot, ar +from waflib.Configure import conftest -from compiler_cc import c_compiler +from waflib.Tools.compiler_c import c_compiler c_compiler['osf1V'] = ['gcc', 'tru64cc'] diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index fe829b84533..6075cc7d9ee 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -1,9 +1,10 @@ # a waf tool to add autoconf-like macros to the configure section # and for SAMBA_ macros for building libraries, binaries etc -import Build, os, sys, Options, Task, Utils, cc, TaskGen, fnmatch, re, shutil, Logs, Constants -from Configure import conf -from Logs import debug +import os, sys, re, shutil, fnmatch +from waflib import Build, Options, Task, Utils, TaskGen, Logs, Context, Errors +from waflib.Configure import conf +from waflib.Logs import debug from samba_utils import SUBST_VARS_RECURSIVE TaskGen.task_gen.apply_verif = Utils.nada @@ -43,7 +44,7 @@ LIB_PATH="shared" os.environ['PYTHONUNBUFFERED'] = '1' -if Constants.HEXVERSION not in (0x105019, 0x1090a00): +if Context.HEXVERSION not in (0x2000400,): Logs.error(''' Please use the version of waf that comes with Samba, not a system installed version. See http://wiki.samba.org/index.php/Waf @@ -53,26 +54,25 @@ Alternatively, please run ./configure and make as usual. That will call the right version of waf.''') sys.exit(1) - @conf def SAMBA_BUILD_ENV(conf): '''create the samba build environment''' - conf.env.BUILD_DIRECTORY = conf.blddir - mkdir_p(os.path.join(conf.blddir, LIB_PATH)) - mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private")) - mkdir_p(os.path.join(conf.blddir, "modules")) - mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc')) + conf.env.BUILD_DIRECTORY = getattr(Context.g_module, Context.OUT) + mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, LIB_PATH)) + mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, LIB_PATH, "private")) + mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, "modules")) + mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, 'python/samba/dcerpc')) # this allows all of the bin/shared and bin/python targets # to be expressed in terms of build directory paths - mkdir_p(os.path.join(conf.blddir, 'default')) + mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, 'default')) for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python_modules')]: - link_target = os.path.join(conf.blddir, 'default/' + target) + link_target = os.path.join(conf.env.BUILD_DIRECTORY, 'default/' + target) if not os.path.lexists(link_target): os.symlink('../' + source, link_target) # get perl to put the blib files in the build directory - blib_bld = os.path.join(conf.blddir, 'default/pidl/blib') - blib_src = os.path.join(conf.srcdir, 'pidl/blib') + blib_bld = os.path.join(conf.env.BUILD_DIRECTORY, 'default/pidl/blib') + blib_src = os.path.join(conf.srcnode.abspath(), 'pidl/blib') mkdir_p(blib_bld + '/man1') mkdir_p(blib_bld + '/man3') if os.path.islink(blib_src): @@ -146,7 +146,7 @@ def SAMBA_LIBRARY(bld, libname, source, public_headers = None if private_library and public_headers: - raise Utils.WafError("private library '%s' must not have public header files" % + raise Errors.WafError("private library '%s' must not have public header files" % libname) if LIB_MUST_BE_PRIVATE(bld, libname): @@ -223,13 +223,13 @@ def SAMBA_LIBRARY(bld, libname, source, # we don't want any public libraries without version numbers if (not private_library and target_type != 'PYTHON' and not realname): if vnum is None and soname is None: - raise Utils.WafError("public library '%s' must have a vnum" % + raise Errors.WafError("public library '%s' must have a vnum" % libname) if pc_files is None: - raise Utils.WafError("public library '%s' must have pkg-config file" % + raise Errors.WafError("public library '%s' must have pkg-config file" % libname) if public_headers is None and not bld.env['IS_EXTRA_PYTHON']: - raise Utils.WafError("public library '%s' must have header files" % + raise Errors.WafError("public library '%s' must have header files" % libname) if bundled_name is not None: @@ -271,7 +271,7 @@ def SAMBA_LIBRARY(bld, libname, source, vscript = None if bld.env.HAVE_LD_VERSION_SCRIPT: if private_library: - version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION) + version = "%s_%s" % (Context.g_module.APPNAME, Context.g_module.VERSION) elif vnum: version = "%s_%s" % (libname, vnum) else: @@ -284,9 +284,9 @@ def SAMBA_LIBRARY(bld, libname, source, fullpath = bld.path.find_or_declare(fullname) vscriptpath = bld.path.find_or_declare(vscript) if not fullpath: - raise Utils.WafError("unable to find fullpath for %s" % fullname) + raise Errors.WafError("unable to find fullpath for %s" % fullname) if not vscriptpath: - raise Utils.WafError("unable to find vscript path for %s" % vscript) + raise Errors.WafError("unable to find vscript path for %s" % vscript) bld.add_manual_dependency(fullpath, vscriptpath) if bld.is_install: # also make the .inst file depend on the vscript @@ -758,7 +758,7 @@ def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None): target = os.path.join(installdir, iname) tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target)) mkdir_p(tgtdir) - link_src = os.path.normpath(os.path.join(bld.curdir, s)) + link_src = os.path.normpath(os.path.join(bld.path.abspath(), s)) link_dst = os.path.join(tgtdir, os.path.basename(iname)) if os.path.islink(link_dst) and os.readlink(link_dst) == link_src: continue @@ -900,7 +900,7 @@ def INSTALL_DIR(bld, path, chmod=0o755, env=None): if not path: return [] - destpath = bld.get_install_path(path, env) + destpath = bld.EXPAND_VARIABLES(path) if bld.is_install > 0: if not os.path.isdir(destpath): @@ -909,7 +909,7 @@ def INSTALL_DIR(bld, path, chmod=0o755, env=None): os.chmod(destpath, chmod) except OSError as e: if not os.path.isdir(destpath): - raise Utils.WafError("Cannot create the folder '%s' (error: %s)" % (path, e)) + raise Errors.WafError("Cannot create the folder '%s' (error: %s)" % (path, e)) Build.BuildContext.INSTALL_DIR = INSTALL_DIR def INSTALL_DIRS(bld, destdir, dirs, chmod=0o755, env=None): diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript index 7952e8aad42..0d9b3022251 100644 --- a/buildtools/wafsamba/wscript +++ b/buildtools/wafsamba/wscript @@ -3,7 +3,8 @@ # this is a base set of waf rules that everything else pulls in first import os, sys -import wafsamba, Configure, Logs, Options, Utils +from waflib import Configure, Logs, Options, Utils, Context, Errors +import wafsamba from samba_utils import os_path_relpath from optparse import SUPPRESS_HELP @@ -16,10 +17,15 @@ from optparse import SUPPRESS_HELP if '--enable-auto-reconfigure' in sys.argv: Configure.autoconfig = 'clobber' -def set_options(opt): - opt.tool_options('compiler_cc') +def default_value(option, default=''): + if option in Options.options.__dict__: + return Options.options.__dict__[option] + return default - opt.tool_options('gnu_dirs') +def options(opt): + opt.load('compiler_cc') + + opt.load('gnu_dirs') gr = opt.option_group('library handling options') @@ -31,17 +37,17 @@ def set_options(opt): help=("comma separated list of normally public libraries to build instead as private libraries. May include !LIBNAME to disable making a library private. Can be 'NONE' or 'ALL' [auto]"), action="store", dest='PRIVATE_LIBS', default='') - extension_default = Options.options['PRIVATE_EXTENSION_DEFAULT'] + extension_default = default_value('PRIVATE_EXTENSION_DEFAULT') gr.add_option('--private-library-extension', help=("name extension for private libraries [%s]" % extension_default), action="store", dest='PRIVATE_EXTENSION', default=extension_default) - extension_exception = Options.options['PRIVATE_EXTENSION_EXCEPTION'] + extension_exception = default_value('PRIVATE_EXTENSION_EXCEPTION') gr.add_option('--private-extension-exception', help=("comma separated list of libraries to not apply extension to [%s]" % extension_exception), action="store", dest='PRIVATE_EXTENSION_EXCEPTION', default=extension_exception) - builtin_default = Options.options['BUILTIN_LIBRARIES_DEFAULT'] + builtin_default = default_value('BUILTIN_LIBRARIES_DEFAULT') gr.add_option('--builtin-libraries', help=("command separated list of libraries to build directly into binaries [%s]" % builtin_default), action="store", dest='BUILTIN_LIBRARIES', default=builtin_default) @@ -71,7 +77,7 @@ def set_options(opt): action="store", dest='MODULESDIR', default='${PREFIX}/modules') opt.add_option('--with-privatelibdir', - help=("private library directory [PREFIX/lib/%s]" % Utils.g_module.APPNAME), + help=("private library directory [PREFIX/lib/%s]" % Context.g_module.APPNAME), action="store", dest='PRIVATELIBDIR', default=None) opt.add_option('--with-libiconv', @@ -210,7 +216,7 @@ def set_options(opt): @Utils.run_once def configure(conf): conf.env.hlist = [] - conf.env.srcdir = conf.srcdir + conf.env.srcdir = conf.srcnode.abspath() conf.define('SRCDIR', conf.env['srcdir']) @@ -220,13 +226,12 @@ def configure(conf): conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache) # load our local waf extensions - conf.check_tool('gnu_dirs') - conf.check_tool('wafsamba') - conf.check_tool('print_commands') + conf.load('gnu_dirs') + conf.load('wafsamba') conf.CHECK_CC_ENV() - conf.check_tool('compiler_cc') + conf.load('compiler_cc') conf.CHECK_STANDARD_LIBPATH() @@ -236,7 +241,7 @@ def configure(conf): # older gcc versions (< 4.4) does not work with gccdeps, so we have to see if the .d file is generated if Options.options.enable_gccdeps: # stale file removal - the configuration may pick up the old .pyc file - p = os.path.join(conf.srcdir, 'buildtools/wafsamba/gccdeps.pyc') + p = os.path.join(conf.env.srcdir, 'buildtools/wafsamba/gccdeps.pyc') if os.path.exists(p): os.remove(p) conf.load('gccdeps') @@ -480,7 +485,7 @@ struct foo bar = { .y = 'X', .x = 1 }; # see if we need special largefile flags if not conf.CHECK_LARGEFILE(): - raise Utils.WafError('Samba requires large file support support, but not available on this platform: sizeof(off_t) < 8') + raise Errors.WafError('Samba requires large file support support, but not available on this platform: sizeof(off_t) < 8') if conf.env.HAVE_STDDEF_H and conf.env.HAVE_STDLIB_H: conf.DEFINE('STDC_HEADERS', 1) @@ -586,10 +591,12 @@ struct foo bar = { .y = 'X', .x = 1 }; def build(bld): # give a more useful message if the source directory has moved - relpath = os_path_relpath(bld.curdir, bld.srcnode.abspath()) + curdir = bld.path.abspath() + srcdir = bld.srcnode.abspath() + relpath = os_path_relpath(curdir, srcdir) if relpath.find('../') != -1: - Logs.error('bld.curdir %s is not a child of %s' % (bld.curdir, bld.srcnode.abspath())) - raise Utils.WafError('''The top source directory has moved. Please run distclean and reconfigure''') + Logs.error('bld.path %s is not a child of %s' % (curdir, srcdir)) + raise Errors.WafError('''The top source directory has moved. Please run distclean and reconfigure''') bld.CHECK_MAKEFLAGS() bld.SETUP_BUILD_GROUPS() |