waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

relocation.py (2267B)


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