~vcs-imports/kupfer/master-new

« back to all changes in this revision

Viewing changes to waflib/extras/compat15.py

  • Committer: Ulrik Sverdrup
  • Date: 2012-02-26 17:50:05 UTC
  • mfrom: (2916.1.5)
  • Revision ID: git-v1:a1d52c4a74cd48e1b673e68977eba58b48928b7f
Merge branch 'full-waf'

* full-waf:
  Update NEWS
  wscript: Use .xz for distribution tarball
  wscript: Clean all .pyc files on distclean
  Update README for Waf being included in the repository and tarball
  Add waf-light and waflib from waf-1.6.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
# Thomas Nagy, 2010 (ita)
 
4
 
 
5
"""
 
6
This file is provided to enable compatibility with waf 1.5, it will be removed in waf 1.7
 
7
"""
 
8
 
 
9
import sys
 
10
from waflib import ConfigSet, Logs, Options, Scripting, Task, Build, Configure, Node, Runner, TaskGen, Utils, Errors, Context
 
11
 
 
12
# the following is to bring some compatibility with waf 1.5 "import waflib.Configure → import Configure"
 
13
sys.modules['Environment'] = ConfigSet
 
14
ConfigSet.Environment = ConfigSet.ConfigSet
 
15
 
 
16
sys.modules['Logs'] = Logs
 
17
sys.modules['Options'] = Options
 
18
sys.modules['Scripting'] = Scripting
 
19
sys.modules['Task'] = Task
 
20
sys.modules['Build'] = Build
 
21
sys.modules['Configure'] = Configure
 
22
sys.modules['Node'] = Node
 
23
sys.modules['Runner'] = Runner
 
24
sys.modules['TaskGen'] = TaskGen
 
25
sys.modules['Utils'] = Utils
 
26
 
 
27
from waflib.Tools import c_preproc
 
28
sys.modules['preproc'] = c_preproc
 
29
 
 
30
from waflib.Tools import c_config
 
31
sys.modules['config_c'] = c_config
 
32
 
 
33
ConfigSet.ConfigSet.copy = ConfigSet.ConfigSet.derive
 
34
ConfigSet.ConfigSet.set_variant = Utils.nada
 
35
 
 
36
Build.BuildContext.add_subdirs = Build.BuildContext.recurse
 
37
Build.BuildContext.new_task_gen = Build.BuildContext.__call__
 
38
Build.BuildContext.is_install = 0
 
39
Node.Node.relpath_gen = Node.Node.path_from
 
40
 
 
41
def name_to_obj(self, s, env=None):
 
42
        Logs.warn('compat: change "name_to_obj(name, env)" by "get_tgen_by_name(name)"')
 
43
        return self.get_tgen_by_name(s)
 
44
Build.BuildContext.name_to_obj = name_to_obj
 
45
 
 
46
def env_of_name(self, name):
 
47
        try:
 
48
                return self.all_envs[name]
 
49
        except KeyError:
 
50
                Logs.error('no such environment: '+name)
 
51
                return None
 
52
Build.BuildContext.env_of_name = env_of_name
 
53
 
 
54
 
 
55
def set_env_name(self, name, env):
 
56
        self.all_envs[name] = env
 
57
        return env
 
58
Configure.ConfigurationContext.set_env_name = set_env_name
 
59
 
 
60
def retrieve(self, name, fromenv=None):
 
61
        try:
 
62
                env = self.all_envs[name]
 
63
        except KeyError:
 
64
                env = ConfigSet.ConfigSet()
 
65
                self.prepare_env(env)
 
66
                self.all_envs[name] = env
 
67
        else:
 
68
                if fromenv: Logs.warn("The environment %s may have been configured already" % name)
 
69
        return env
 
70
Configure.ConfigurationContext.retrieve = retrieve
 
71
 
 
72
Configure.ConfigurationContext.sub_config = Configure.ConfigurationContext.recurse
 
73
Configure.ConfigurationContext.check_tool = Configure.ConfigurationContext.load
 
74
Configure.conftest = Configure.conf
 
75
Configure.ConfigurationError = Errors.ConfigurationError
 
76
 
 
77
Options.OptionsContext.sub_options = Options.OptionsContext.recurse
 
78
Options.OptionsContext.tool_options = Context.Context.load
 
79
Options.Handler = Options.OptionsContext
 
80
 
 
81
Task.simple_task_type = Task.task_type_from_func = Task.task_factory
 
82
Task.TaskBase.classes = Task.classes
 
83
 
 
84
def setitem(self, key, value):
 
85
        if key.startswith('CCFLAGS'):
 
86
                key = key[1:]
 
87
        self.table[key] = value
 
88
ConfigSet.ConfigSet.__setitem__ = setitem
 
89
 
 
90
@TaskGen.feature('d')
 
91
@TaskGen.before('apply_incpaths')
 
92
def old_importpaths(self):
 
93
        if getattr(self, 'importpaths', []):
 
94
                self.includes = self.importpaths
 
95
 
 
96
from waflib import Context
 
97
eld = Context.load_tool
 
98
def load_tool(*k, **kw):
 
99
        ret = eld(*k, **kw)
 
100
        if 'set_options' in ret.__dict__:
 
101
                Logs.warn('compat: rename "set_options" to options')
 
102
                ret.options = ret.set_options
 
103
        if 'detect' in ret.__dict__:
 
104
                Logs.warn('compat: rename "detect" to "configure"')
 
105
                ret.configure = ret.detect
 
106
        return ret
 
107
Context.load_tool = load_tool
 
108
 
 
109
rev = Context.load_module
 
110
def load_module(path):
 
111
        ret = rev(path)
 
112
        if 'set_options' in ret.__dict__:
 
113
                Logs.warn('compat: rename "set_options" to "options" (%r)' % path)
 
114
                ret.options = ret.set_options
 
115
        if 'srcdir' in ret.__dict__:
 
116
                Logs.warn('compat: rename "srcdir" to "top" (%r)' % path)
 
117
                ret.top = ret.srcdir
 
118
        if 'blddir' in ret.__dict__:
 
119
                Logs.warn('compat: rename "blddir" to "out" (%r)' % path)
 
120
                ret.out = ret.blddir
 
121
        return ret
 
122
Context.load_module = load_module
 
123
 
 
124
old_post = TaskGen.task_gen.post
 
125
def post(self):
 
126
        self.features = self.to_list(self.features)
 
127
        if 'cc' in self.features:
 
128
                Logs.warn('compat: the feature cc does not exist anymore (use "c")')
 
129
                self.features.remove('cc')
 
130
                self.features.append('c')
 
131
        if 'cstaticlib' in self.features:
 
132
                Logs.warn('compat: the feature cstaticlib does not exist anymore (use "cstlib" or "cxxstlib")')
 
133
                self.features.remove('cstaticlib')
 
134
                self.features.append(('cxx' in self.features) and 'cxxstlib' or 'cstlib')
 
135
        if getattr(self, 'ccflags', None):
 
136
                Logs.warn('compat: "ccflags" was renamed to "cflags"')
 
137
                self.cflags = self.ccflags
 
138
        return old_post(self)
 
139
TaskGen.task_gen.post = post
 
140
 
 
141
def waf_version(*k, **kw):
 
142
        Logs.warn('wrong version (waf_version was removed in waf 1.6)')
 
143
Utils.waf_version = waf_version
 
144
 
 
145
 
 
146
import os
 
147
@TaskGen.feature('c', 'cxx', 'd')
 
148
@TaskGen.before('apply_incpaths', 'propagate_uselib_vars')
 
149
@TaskGen.after('apply_link', 'process_source')
 
150
def apply_uselib_local(self):
 
151
        """
 
152
        process the uselib_local attribute
 
153
        execute after apply_link because of the execution order set on 'link_task'
 
154
        """
 
155
        env = self.env
 
156
        from waflib.Tools.ccroot import stlink_task
 
157
 
 
158
        # 1. the case of the libs defined in the project (visit ancestors first)
 
159
        # the ancestors external libraries (uselib) will be prepended
 
160
        self.uselib = self.to_list(getattr(self, 'uselib', []))
 
161
        self.includes = self.to_list(getattr(self, 'includes', []))
 
162
        names = self.to_list(getattr(self, 'uselib_local', []))
 
163
        get = self.bld.get_tgen_by_name
 
164
        seen = set([])
 
165
        tmp = Utils.deque(names) # consume a copy of the list of names
 
166
        if tmp:
 
167
                Logs.warn('compat: "uselib_local" is deprecated, replace by "use"')
 
168
        while tmp:
 
169
                lib_name = tmp.popleft()
 
170
                # visit dependencies only once
 
171
                if lib_name in seen:
 
172
                        continue
 
173
 
 
174
                y = get(lib_name)
 
175
                y.post()
 
176
                seen.add(lib_name)
 
177
 
 
178
                # object has ancestors to process (shared libraries): add them to the end of the list
 
179
                if getattr(y, 'uselib_local', None):
 
180
                        for x in self.to_list(getattr(y, 'uselib_local', [])):
 
181
                                obj = get(x)
 
182
                                obj.post()
 
183
                                if getattr(obj, 'link_task', None):
 
184
                                        if not isinstance(obj.link_task, stlink_task):
 
185
                                                tmp.append(x)
 
186
 
 
187
                # link task and flags
 
188
                if getattr(y, 'link_task', None):
 
189
 
 
190
                        link_name = y.target[y.target.rfind(os.sep) + 1:]
 
191
                        if isinstance(y.link_task, stlink_task):
 
192
                                env.append_value('STLIB', [link_name])
 
193
                        else:
 
194
                                # some linkers can link against programs
 
195
                                env.append_value('LIB', [link_name])
 
196
 
 
197
                        # the order
 
198
                        self.link_task.set_run_after(y.link_task)
 
199
 
 
200
                        # for the recompilation
 
201
                        self.link_task.dep_nodes += y.link_task.outputs
 
202
 
 
203
                        # add the link path too
 
204
                        tmp_path = y.link_task.outputs[0].parent.bldpath()
 
205
                        if not tmp_path in env['LIBPATH']:
 
206
                                env.prepend_value('LIBPATH', [tmp_path])
 
207
 
 
208
                # add ancestors uselib too - but only propagate those that have no staticlib defined
 
209
                for v in self.to_list(getattr(y, 'uselib', [])):
 
210
                        if not env['STLIB_' + v]:
 
211
                                if not v in self.uselib:
 
212
                                        self.uselib.insert(0, v)
 
213
 
 
214
                # if the library task generator provides 'export_includes', add to the include path
 
215
                # the export_includes must be a list of paths relative to the other library
 
216
                if getattr(y, 'export_includes', None):
 
217
                        self.includes.extend(y.to_incnodes(y.export_includes))
 
218
 
 
219
@TaskGen.feature('cprogram', 'cxxprogram', 'cstlib', 'cxxstlib', 'cshlib', 'cxxshlib', 'dprogram', 'dstlib', 'dshlib')
 
220
@TaskGen.after('apply_link')
 
221
def apply_objdeps(self):
 
222
        "add the .o files produced by some other object files in the same manner as uselib_local"
 
223
        names = getattr(self, 'add_objects', [])
 
224
        if not names:
 
225
                return
 
226
        names = self.to_list(names)
 
227
 
 
228
        get = self.bld.get_tgen_by_name
 
229
        seen = []
 
230
        while names:
 
231
                x = names[0]
 
232
 
 
233
                # visit dependencies only once
 
234
                if x in seen:
 
235
                        names = names[1:]
 
236
                        continue
 
237
 
 
238
                # object does not exist ?
 
239
                y = get(x)
 
240
 
 
241
                # object has ancestors to process first ? update the list of names
 
242
                if getattr(y, 'add_objects', None):
 
243
                        added = 0
 
244
                        lst = y.to_list(y.add_objects)
 
245
                        lst.reverse()
 
246
                        for u in lst:
 
247
                                if u in seen: continue
 
248
                                added = 1
 
249
                                names = [u]+names
 
250
                        if added: continue # list of names modified, loop
 
251
 
 
252
                # safe to process the current object
 
253
                y.post()
 
254
                seen.append(x)
 
255
 
 
256
                for t in getattr(y, 'compiled_tasks', []):
 
257
                        self.link_task.inputs.extend(t.outputs)
 
258
 
 
259
@TaskGen.after('apply_link')
 
260
def process_obj_files(self):
 
261
        if not hasattr(self, 'obj_files'):
 
262
                return
 
263
        for x in self.obj_files:
 
264
                node = self.path.find_resource(x)
 
265
                self.link_task.inputs.append(node)
 
266
 
 
267
@TaskGen.taskgen_method
 
268
def add_obj_file(self, file):
 
269
        """Small example on how to link object files as if they were source
 
270
        obj = bld.create_obj('cc')
 
271
        obj.add_obj_file('foo.o')"""
 
272
        if not hasattr(self, 'obj_files'): self.obj_files = []
 
273
        if not 'process_obj_files' in self.meths: self.meths.append('process_obj_files')
 
274
        self.obj_files.append(file)
 
275
 
 
276
 
 
277
old_define = Configure.ConfigurationContext.__dict__['define']
 
278
 
 
279
@Configure.conf
 
280
def define(self, key, val, quote=True):
 
281
        old_define(self, key, val, quote)
 
282
        if key.startswith('HAVE_'):
 
283
                self.env[key] = 1
 
284
 
 
285
old_undefine = Configure.ConfigurationContext.__dict__['undefine']
 
286
 
 
287
@Configure.conf
 
288
def undefine(self, key):
 
289
        old_undefine(self, key)
 
290
        if key.startswith('HAVE_'):
 
291
                self.env[key] = 0
 
292
 
 
293
# some people might want to use export_incdirs, but it was renamed
 
294
def set_incdirs(self, val):
 
295
        Logs.warn('compat: change "export_incdirs" by "export_includes"')
 
296
        self.export_includes = val
 
297
TaskGen.task_gen.export_incdirs = property(None, set_incdirs)
 
298