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 50f4d7f..d36d3df 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 158a4a4..6b03726 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 5900809..386798f 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 e54df47..7eb5272 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 c130b40..2240b2f 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 2a97d19..72e7376 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 88ca0d9..95184ee 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 5a59a4c..03b4229 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