3
# Thomas Nagy, 2010 (ita)
6
This file is provided to enable compatibility with waf 1.5, it will be removed in waf 1.7
10
from waflib import ConfigSet, Logs, Options, Scripting, Task, Build, Configure, Node, Runner, TaskGen, Utils, Errors, Context
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
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
27
from waflib.Tools import c_preproc
28
sys.modules['preproc'] = c_preproc
30
from waflib.Tools import c_config
31
sys.modules['config_c'] = c_config
33
ConfigSet.ConfigSet.copy = ConfigSet.ConfigSet.derive
34
ConfigSet.ConfigSet.set_variant = Utils.nada
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
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
46
def env_of_name(self, name):
48
return self.all_envs[name]
50
Logs.error('no such environment: '+name)
52
Build.BuildContext.env_of_name = env_of_name
55
def set_env_name(self, name, env):
56
self.all_envs[name] = env
58
Configure.ConfigurationContext.set_env_name = set_env_name
60
def retrieve(self, name, fromenv=None):
62
env = self.all_envs[name]
64
env = ConfigSet.ConfigSet()
66
self.all_envs[name] = env
68
if fromenv: Logs.warn("The environment %s may have been configured already" % name)
70
Configure.ConfigurationContext.retrieve = retrieve
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
77
Options.OptionsContext.sub_options = Options.OptionsContext.recurse
78
Options.OptionsContext.tool_options = Context.Context.load
79
Options.Handler = Options.OptionsContext
81
Task.simple_task_type = Task.task_type_from_func = Task.task_factory
82
Task.TaskBase.classes = Task.classes
84
def setitem(self, key, value):
85
if key.startswith('CCFLAGS'):
87
self.table[key] = value
88
ConfigSet.ConfigSet.__setitem__ = setitem
91
@TaskGen.before('apply_incpaths')
92
def old_importpaths(self):
93
if getattr(self, 'importpaths', []):
94
self.includes = self.importpaths
96
from waflib import Context
97
eld = Context.load_tool
98
def load_tool(*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
107
Context.load_tool = load_tool
109
rev = Context.load_module
110
def load_module(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)
118
if 'blddir' in ret.__dict__:
119
Logs.warn('compat: rename "blddir" to "out" (%r)' % path)
122
Context.load_module = load_module
124
old_post = TaskGen.task_gen.post
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
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
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):
152
process the uselib_local attribute
153
execute after apply_link because of the execution order set on 'link_task'
156
from waflib.Tools.ccroot import stlink_task
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
165
tmp = Utils.deque(names) # consume a copy of the list of names
167
Logs.warn('compat: "uselib_local" is deprecated, replace by "use"')
169
lib_name = tmp.popleft()
170
# visit dependencies only once
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', [])):
183
if getattr(obj, 'link_task', None):
184
if not isinstance(obj.link_task, stlink_task):
187
# link task and flags
188
if getattr(y, 'link_task', None):
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])
194
# some linkers can link against programs
195
env.append_value('LIB', [link_name])
198
self.link_task.set_run_after(y.link_task)
200
# for the recompilation
201
self.link_task.dep_nodes += y.link_task.outputs
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])
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)
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))
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', [])
226
names = self.to_list(names)
228
get = self.bld.get_tgen_by_name
233
# visit dependencies only once
238
# object does not exist ?
241
# object has ancestors to process first ? update the list of names
242
if getattr(y, 'add_objects', None):
244
lst = y.to_list(y.add_objects)
247
if u in seen: continue
250
if added: continue # list of names modified, loop
252
# safe to process the current object
256
for t in getattr(y, 'compiled_tasks', []):
257
self.link_task.inputs.extend(t.outputs)
259
@TaskGen.after('apply_link')
260
def process_obj_files(self):
261
if not hasattr(self, 'obj_files'):
263
for x in self.obj_files:
264
node = self.path.find_resource(x)
265
self.link_task.inputs.append(node)
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)
277
old_define = Configure.ConfigurationContext.__dict__['define']
280
def define(self, key, val, quote=True):
281
old_define(self, key, val, quote)
282
if key.startswith('HAVE_'):
285
old_undefine = Configure.ConfigurationContext.__dict__['undefine']
288
def undefine(self, key):
289
old_undefine(self, key)
290
if key.startswith('HAVE_'):
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)