build: rename samba_includes.py to samba_optimisation.py
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_optimisation.py
blobd95ddaaa81c83cd2dbe24e088b810daf75c5ca7f
1 # This file contains waf optimisations for Samba
3 # most of these optimisations are possible because of the restricted build environment
4 # that Samba has. For example, Samba doesn't attempt to cope with Win32 paths during the
5 # build, and Samba doesn't need build varients
7 # overall this makes some build tasks quite a bit faster
9 from TaskGen import feature, before, after
10 import preproc
11 import os
13 kak = {}
14 @feature('cc', 'cxx')
15 @after('apply_type_vars', 'apply_lib_vars', 'apply_core')
16 def apply_incpaths(self):
17 lst = []
18 # TODO move the uselib processing out of here
19 for lib in self.to_list(self.uselib):
20 for path in self.env['CPPPATH_' + lib]:
21 if not path in lst:
22 lst.append(path)
23 if preproc.go_absolute:
24 for path in preproc.standard_includes:
25 if not path in lst:
26 lst.append(path)
28 for path in self.to_list(self.includes):
29 if not path in lst:
30 if preproc.go_absolute or path[0] != '/': #os.path.isabs(path):
31 lst.append(path)
32 else:
33 self.env.prepend_value('CPPPATH', path)
35 for path in lst:
36 node = None
37 if path[0] == '/': # os.path.isabs(path):
38 if preproc.go_absolute:
39 node = self.bld.root.find_dir(path)
40 elif path[0] == '#':
41 node = self.bld.srcnode
42 if len(path) > 1:
43 try:
44 node = kak[path]
45 except KeyError:
46 kak[path] = node = node.find_dir(path[1:])
47 else:
48 try:
49 node = kak[(self.path.id, path)]
50 except KeyError:
51 kak[(self.path.id, path)] = node = self.path.find_dir(path)
53 if node:
54 self.env.append_value('INC_PATHS', node)
56 cac = {}
57 @feature('cc')
58 @after('apply_incpaths')
59 def apply_obj_vars_cc(self):
60 """after apply_incpaths for INC_PATHS"""
61 env = self.env
62 app = env.append_unique
63 cpppath_st = env['CPPPATH_ST']
65 lss = env['_CCINCFLAGS']
67 global cac
69 # local flags come first
70 # set the user-defined includes paths
71 for i in env['INC_PATHS']:
73 try:
74 lss.extend(cac[i.id])
75 except KeyError:
77 cac[i.id] = [cpppath_st % i.bldpath(env), cpppath_st % i.srcpath(env)]
78 lss.extend(cac[i.id])
80 env['_CCINCFLAGS'] = lss
81 # set the library include paths
82 for i in env['CPPPATH']:
83 app('_CCINCFLAGS', cpppath_st % i)
85 import Node, Environment
87 def vari(self):
88 return "default"
89 Environment.Environment.variant = vari
91 def variant(self, env):
92 if not env: return 0
93 elif self.id & 3 == Node.FILE: return 0
94 else: return "default"
95 Node.Node.variant = variant
98 import TaskGen, Task
100 def create_task(self, name, src=None, tgt=None):
101 task = Task.TaskBase.classes[name](self.env, generator=self)
102 if src:
103 task.set_inputs(src)
104 if tgt:
105 task.set_outputs(tgt)
106 return task
107 TaskGen.task_gen.create_task = create_task
109 def hash_constraints(self):
110 a = self.attr
111 sum = hash((str(a('before', '')),
112 str(a('after', '')),
113 str(a('ext_in', '')),
114 str(a('ext_out', '')),
115 self.__class__.maxjobs))
116 return sum
117 Task.TaskBase.hash_constraints = hash_constraints
120 # import cc
121 # from TaskGen import extension
122 # import Utils
124 # @extension(cc.EXT_CC)
125 # def c_hook(self, node):
126 # task = self.create_task('cc', node, node.change_ext('.o'))
127 # try:
128 # self.compiled_tasks.append(task)
129 # except AttributeError:
130 # raise Utils.WafError('Have you forgotten to set the feature "cc" on %s?' % str(self))
132 # bld = self.bld
133 # try:
134 # dc = bld.dc
135 # except AttributeError:
136 # dc = bld.dc = {}
138 # if task.outputs[0].id in dc:
139 # raise Utils.WafError('Samba, you are doing it wrong %r %s %s' % (task.outputs, task.generator, dc[task.outputs[0].id].generator))
140 # else:
141 # dc[task.outputs[0].id] = task
143 # return task