build: more optimisations from Thomas
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_includes.py
blob8174bfffe55b77fce8648717a5497aaf67752994
1 # a includes processing tool to speed up include path calculations
3 from TaskGen import feature, before, after
4 import preproc
5 import os
7 kak = {}
8 @feature('cc', 'cxx')
9 @after('apply_type_vars', 'apply_lib_vars', 'apply_core')
10 def apply_incpaths(self):
11 lst = []
12 # TODO move the uselib processing out of here
13 for lib in self.to_list(self.uselib):
14 for path in self.env['CPPPATH_' + lib]:
15 if not path in lst:
16 lst.append(path)
17 if preproc.go_absolute:
18 for path in preproc.standard_includes:
19 if not path in lst:
20 lst.append(path)
22 for path in self.to_list(self.includes):
23 if not path in lst:
24 if preproc.go_absolute or path[0] != '/': #os.path.isabs(path):
25 lst.append(path)
26 else:
27 self.env.prepend_value('CPPPATH', path)
29 for path in lst:
30 node = None
31 if path[0] == '/': # os.path.isabs(path):
32 if preproc.go_absolute:
33 node = self.bld.root.find_dir(path)
34 elif path[0] == '#':
35 node = self.bld.srcnode
36 if len(path) > 1:
37 try:
38 node = kak[path]
39 except KeyError:
40 kak[path] = node = node.find_dir(path[1:])
41 else:
42 try:
43 node = kak[(self.path.id, path)]
44 except KeyError:
45 kak[(self.path.id, path)] = node = self.path.find_dir(path)
47 if node:
48 self.env.append_value('INC_PATHS', node)
50 cac = {}
51 @feature('cc')
52 @after('apply_incpaths')
53 def apply_obj_vars_cc(self):
54 """after apply_incpaths for INC_PATHS"""
55 env = self.env
56 app = env.append_unique
57 cpppath_st = env['CPPPATH_ST']
59 lss = env['_CCINCFLAGS']
61 global cac
63 # local flags come first
64 # set the user-defined includes paths
65 for i in env['INC_PATHS']:
67 try:
68 lss.extend(cac[i.id])
69 except KeyError:
71 cac[i.id] = [cpppath_st % i.bldpath(env), cpppath_st % i.srcpath(env)]
72 lss.extend(cac[i.id])
74 env['_CCINCFLAGS'] = lss
75 # set the library include paths
76 for i in env['CPPPATH']:
77 app('_CCINCFLAGS', cpppath_st % i)
79 import Node, Environment
81 def vari(self):
82 return "default"
83 Environment.Environment.variant = vari
85 def variant(self, env):
86 if not env: return 0
87 elif self.id & 3 == Node.FILE: return 0
88 else: return "default"
89 Node.Node.variant = variant
92 import TaskGen, Task
94 def create_task(self, name, src=None, tgt=None):
95 task = Task.TaskBase.classes[name](self.env, generator=self)
96 if src:
97 task.set_inputs(src)
98 if tgt:
99 task.set_outputs(tgt)
100 return task
101 TaskGen.task_gen.create_task = create_task
103 def hash_constraints(self):
104 a = self.attr
105 sum = hash((str(a('before', '')),
106 str(a('after', '')),
107 str(a('ext_in', '')),
108 str(a('ext_out', '')),
109 self.__class__.maxjobs))
110 return sum
111 Task.TaskBase.hash_constraints = hash_constraints
114 # import cc
115 # from TaskGen import extension
116 # import Utils
118 # @extension(cc.EXT_CC)
119 # def c_hook(self, node):
120 # task = self.create_task('cc', node, node.change_ext('.o'))
121 # try:
122 # self.compiled_tasks.append(task)
123 # except AttributeError:
124 # raise Utils.WafError('Have you forgotten to set the feature "cc" on %s?' % str(self))
126 # bld = self.bld
127 # try:
128 # dc = bld.dc
129 # except AttributeError:
130 # dc = bld.dc = {}
132 # if task.outputs[0].id in dc:
133 # raise Utils.WafError('Samba, you are doing it wrong %r %s %s' % (task.outputs, task.generator, dc[task.outputs[0].id].generator))
134 # else:
135 # dc[task.outputs[0].id] = task
137 # return task