third_party:waf: Backport parts of the waf 1.8 API
authorThomas Nagy <tnagy@waf.io>
Fri, 26 Jun 2015 18:13:09 +0000 (20:13 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 1 Sep 2015 22:47:18 +0000 (00:47 +0200)
This modifies our waf 1.5 wafadmin copy to resemble the waf 1.8
waflib API.  It is a preparation to change to waf 1.8, decoupling
this change from changes in wafsamba.

Signed-off-by: Thomas Nagy <tnagy@waf.io>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
third_party/waf/wafadmin/Build.py
third_party/waf/wafadmin/Node.py
third_party/waf/wafadmin/TaskGen.py
third_party/waf/wafadmin/Tools/cc.py
third_party/waf/wafadmin/Tools/ccroot.py
third_party/waf/wafadmin/Tools/msvc.py
third_party/waf/wafadmin/Tools/osx.py
third_party/waf/wafadmin/Utils.py

index 50f4d7f6c69e949ddb7a89b4760063d90aea4b0e..d36d3df8eca0fdfa6d9187bcb50365ebdfa27116 100644 (file)
@@ -645,6 +645,10 @@ class BuildContext(Utils.Context):
                                                cache[v] = x
                return cache.get(env.variant() + '_' + name, None)
 
+       def get_tgen_by_name(self, name):
+               """waf 1.8 api"""
+               return self.name_to_obj(name, self.env)
+
        def flush(self, all=1):
                """tell the task generators to create the tasks"""
 
index 158a4a4d47010d3e2f32fe759d678c028f4234df..6b037263678037333d92c021b3ba43aefa50357a 100644 (file)
@@ -689,6 +689,13 @@ class Node(object):
                                        child = self.ensure_dir_node_from_path(k)
                                child.update_build_dir(env)
 
+       def read(self, flags='r', encoding='ISO8859-1'):
+               """backported from waf 1.8"""
+               return Utils.readf(self.abspath(), flags, encoding)
+
+       def write(self, data, flags='w', encoding='ISO8859-1'):
+               """backported from waf 1.8"""
+               Utils.writef(self.abspath(self.bld.env), data, flags, encoding)
 
 class Nodu(Node):
        pass
index 5900809ddfed4692fd8e61bb7b9df03ec7a665c9..386798f424c4f470622e358731bdcffc3a3294c7 100644 (file)
@@ -242,6 +242,9 @@ class task_gen(object):
        def name_to_obj(self, name):
                return self.bld.name_to_obj(name, self.env)
 
+       def get_tgen_by_name(self, name):
+               return self.bld.get_tgen_by_name(name)
+
        def find_sources_in_dirs(self, dirnames, excludes=[], exts=[]):
                """
                The attributes "excludes" and "exts" must be lists to avoid the confusion
index e54df4715e5d80d0600887b08ae52c6f94898b96..7eb5272d69a8fef44b94192f79a540e0a6a7ca3c 100644 (file)
@@ -23,7 +23,7 @@ g_cc_type_vars = ['CCFLAGS', 'LINKFLAGS']
 class cc_taskgen(ccroot.ccroot_abstract):
        pass
 
-@feature('cc')
+@feature('c', 'cc')
 @before('apply_type_vars')
 @after('default_cc')
 def init_cc(self):
@@ -33,7 +33,7 @@ def init_cc(self):
        if not self.env['CC_NAME']:
                raise Utils.WafError("At least one compiler (gcc, ..) must be selected")
 
-@feature('cc')
+@feature('c', 'cc')
 @after('apply_incpaths')
 def apply_obj_vars_cc(self):
        """after apply_incpaths for INC_PATHS"""
@@ -51,7 +51,7 @@ def apply_obj_vars_cc(self):
        for i in env['CPPPATH']:
                app('_CCINCFLAGS', cpppath_st % i)
 
-@feature('cc')
+@feature('c', 'cc')
 @after('apply_lib_vars')
 def apply_defines_cc(self):
        """after uselib is set for CCDEFINES"""
index c130b40a21dc52b6c3a8063f3f3f0e3f7aef11f9..2240b2f3ae2c699b849687511977d44ae2ff2942 100644 (file)
@@ -190,7 +190,7 @@ def get_target_name(self):
 
        return os.path.join(dir, pattern % name)
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @before('apply_core')
 def default_cc(self):
        """compiled_tasks attribute must be set before the '.c->.o' tasks can be created"""
@@ -253,7 +253,7 @@ def default_link_install(self):
        if self.install_path:
                self.bld.install_files(self.install_path, self.link_task.outputs[0], env=self.env, chmod=self.chmod)
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @after('apply_type_vars', 'apply_lib_vars', 'apply_core')
 def apply_incpaths(self):
        """used by the scanner
@@ -297,7 +297,7 @@ def apply_incpaths(self):
        if USE_TOP_LEVEL:
                self.env.append_value('INC_PATHS', self.bld.srcnode)
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @after('init_cc', 'init_cxx')
 @before('apply_lib_vars')
 def apply_type_vars(self):
@@ -339,7 +339,7 @@ def apply_link(self):
 
        self.link_task = tsk
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @after('apply_link', 'init_cc', 'init_cxx', 'apply_core')
 def apply_lib_vars(self):
        """after apply_link because of 'link_task'
@@ -523,7 +523,7 @@ c_attrs = {
 'frameworkpath' : 'FRAMEWORKPATH'
 }
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @before('init_cxx', 'init_cc')
 @before('apply_lib_vars', 'apply_obj_vars', 'apply_incpaths', 'init_cc')
 def add_extra_flags(self):
index 2a97d19a7ebca93a9529575594470f29db677c29..72e7376c129f152f4116519917de0f8f4f59264d 100644 (file)
@@ -638,7 +638,7 @@ def msvc_common_flags(conf):
 ##### conf above, build below
 
 @after('apply_link')
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 def apply_flags_msvc(self):
        if self.env.CC_NAME != 'msvc' or not self.link_task:
                return
index 88ca0d950aa9d672c53864cdefad81516076e048..95184eec015cca6b770795b80bc452f54b1103e3 100644 (file)
@@ -38,7 +38,7 @@ app_info = '''
 
 # see WAF issue 285
 # and also http://trac.macports.org/ticket/17059
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @before('apply_lib_vars')
 def set_macosx_deployment_target(self):
        if self.env['MACOSX_DEPLOYMENT_TARGET']:
@@ -47,7 +47,7 @@ def set_macosx_deployment_target(self):
                if sys.platform == 'darwin':
                        os.environ['MACOSX_DEPLOYMENT_TARGET'] = '.'.join(platform.mac_ver()[0].split('.')[:2])
 
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 @after('apply_lib_vars')
 def apply_framework(self):
        for x in self.to_list(self.env['FRAMEWORKPATH']):
@@ -145,7 +145,7 @@ def apply_link_osx(self):
                self.env.append_value('LINKFLAGS', path)
 
 @before('apply_link', 'apply_lib_vars')
-@feature('cc', 'cxx')
+@feature('c', 'cc', 'cxx')
 def apply_bundle(self):
        """use env['MACBUNDLE'] to force all shlibs into mac bundles
        or use obj.mac_bundle = True for specific targets only"""
index 5a59a4c30a360951ef99924317f28a0a5ded86d6..03b4229f02c49e51bf53d7b4afcf081f2ee34193 100644 (file)
@@ -147,6 +147,38 @@ except ImportError:
                # portability fixes may be added elsewhere (although, md5 should be everywhere by now)
                md5 = None
 
+def readf(fname, m='r', encoding='ISO8859-1'):
+       """backported from waf 1.8"""
+       if sys.hexversion > 0x3000000 and not 'b' in m:
+               m += 'b'
+               f = open(fname, m)
+               try:
+                       txt = f.read()
+               finally:
+                       f.close()
+               if encoding:
+                       txt = txt.decode(encoding)
+               else:
+                       txt = txt.decode()
+       else:
+               f = open(fname, m)
+               try:
+                       txt = f.read()
+               finally:
+                       f.close()
+       return txt
+
+def writef(fname, data, m='w', encoding='ISO8859-1'):
+       """backported from waf 1.8"""
+       if sys.hexversion > 0x3000000 and not 'b' in m:
+               data = data.encode(encoding)
+               m += 'b'
+       f = open(fname, m)
+       try:
+               f.write(data)
+       finally:
+               f.close()
+
 class ordered_dict(UserDict):
        def __init__(self, dict = None):
                self.allkeys = []
@@ -557,15 +589,6 @@ def load_tool(tool, tooldir=None):
                for dt in tooldir:
                        sys.path.remove(dt)
 
-def readf(fname, m='r'):
-       "get the contents of a file, it is not used anywhere for the moment"
-       f = open(fname, m)
-       try:
-               txt = f.read()
-       finally:
-               f.close()
-       return txt
-
 def nada(*k, **kw):
        """A function that does nothing"""
        pass