third_party:waf: update to upstream 2.0.4 release
[bbaumbach/samba-autobuild/.git] / third_party / waf / waflib / extras / relocation.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #! /usr/bin/env python
6 # encoding: utf-8
7
8 """
9 Waf 1.6
10
11 Try to detect if the project directory was relocated, and if it was,
12 change the node representing the project directory. Just call:
13
14  waf configure build
15
16 Note that if the project directory name changes, the signatures for the tasks using
17 files in that directory will change, causing a partial build.
18 """
19
20 import os
21 from waflib import Build, ConfigSet, Task, Utils, Errors
22 from waflib.TaskGen import feature, after_method
23
24 EXTRA_LOCK = '.old_srcdir'
25
26 old1 = Build.BuildContext.store
27 def store(self):
28         old1(self)
29         db = os.path.join(self.variant_dir, EXTRA_LOCK)
30         env = ConfigSet.ConfigSet()
31         env.SRCDIR = self.srcnode.abspath()
32         env.store(db)
33 Build.BuildContext.store = store
34
35 old2 = Build.BuildContext.init_dirs
36 def init_dirs(self):
37
38         if not (os.path.isabs(self.top_dir) and os.path.isabs(self.out_dir)):
39                 raise Errors.WafError('The project was not configured: run "waf configure" first!')
40
41         srcdir = None
42         db = os.path.join(self.variant_dir, EXTRA_LOCK)
43         env = ConfigSet.ConfigSet()
44         try:
45                 env.load(db)
46                 srcdir = env.SRCDIR
47         except:
48                 pass
49
50         if srcdir:
51                 d = self.root.find_node(srcdir)
52                 if d and srcdir != self.top_dir and getattr(d, 'children', ''):
53                         srcnode = self.root.make_node(self.top_dir)
54                         print("relocating the source directory %r -> %r" % (srcdir, self.top_dir))
55                         srcnode.children = {}
56
57                         for (k, v) in d.children.items():
58                                 srcnode.children[k] = v
59                                 v.parent = srcnode
60                         d.children = {}
61
62         old2(self)
63
64 Build.BuildContext.init_dirs = init_dirs
65
66
67 def uid(self):
68         try:
69                 return self.uid_
70         except AttributeError:
71                 # this is not a real hot zone, but we want to avoid surprises here
72                 m = Utils.md5()
73                 up = m.update
74                 up(self.__class__.__name__.encode())
75                 for x in self.inputs + self.outputs:
76                         up(x.path_from(x.ctx.srcnode).encode())
77                 self.uid_ = m.digest()
78                 return self.uid_
79 Task.Task.uid = uid
80
81 @feature('c', 'cxx', 'd', 'go', 'asm', 'fc', 'includes')
82 @after_method('propagate_uselib_vars', 'process_source')
83 def apply_incpaths(self):
84         lst = self.to_incnodes(self.to_list(getattr(self, 'includes', [])) + self.env['INCLUDES'])
85         self.includes_nodes = lst
86         bld = self.bld
87         self.env['INCPATHS'] = [x.is_child_of(bld.srcnode) and x.path_from(bld.bldnode) or x.abspath() for x in lst]
88
89