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