summaryrefslogtreecommitdiffstats
path: root/third_party/waf/waflib/extras/bjam.py
blob: 8e04d3a66fcea2a1f466a21b5d71ef2ac0227ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /usr/bin/env python
# per rosengren 2011

from os import sep, readlink
from waflib import Logs
from waflib.TaskGen import feature, after_method
from waflib.Task import Task, always_run

def options(opt):
	grp = opt.add_option_group('Bjam Options')
	grp.add_option('--bjam_src', default=None, help='You can find it in <boost root>/tools/jam/src')
	grp.add_option('--bjam_uname', default='linuxx86_64', help='bjam is built in <src>/bin.<uname>/bjam')
	grp.add_option('--bjam_config', default=None)
	grp.add_option('--bjam_toolset', default=None)

def configure(cnf):
	if not cnf.env.BJAM_SRC:
		cnf.env.BJAM_SRC = cnf.options.bjam_src
	if not cnf.env.BJAM_UNAME:
		cnf.env.BJAM_UNAME = cnf.options.bjam_uname
	try:
		cnf.find_program('bjam', path_list=[
			cnf.env.BJAM_SRC + sep + 'bin.' + cnf.env.BJAM_UNAME
		])
	except Exception:
		cnf.env.BJAM = None
	if not cnf.env.BJAM_CONFIG:
		cnf.env.BJAM_CONFIG = cnf.options.bjam_config
	if not cnf.env.BJAM_TOOLSET:
		cnf.env.BJAM_TOOLSET = cnf.options.bjam_toolset

@feature('bjam')
@after_method('process_rule')
def process_bjam(self):
	if not self.bld.env.BJAM:
		self.create_task('bjam_creator')
	self.create_task('bjam_build')
	self.create_task('bjam_installer')
	if getattr(self, 'always', False):
		always_run(bjam_creator)
		always_run(bjam_build)
	always_run(bjam_installer)

class bjam_creator(Task):
	ext_out = 'bjam_exe'
	vars=['BJAM_SRC', 'BJAM_UNAME']
	def run(self):
		env = self.env
		gen = self.generator
		bjam = gen.bld.root.find_dir(env.BJAM_SRC)
		if not bjam:
			Logs.error('Can not find bjam source')
			return -1
		bjam_exe_relpath = 'bin.' + env.BJAM_UNAME + '/bjam'
		bjam_exe = bjam.find_resource(bjam_exe_relpath)
		if bjam_exe:
			env.BJAM = bjam_exe.srcpath()
			return 0
		bjam_cmd = ['./build.sh']
		Logs.debug('runner: ' + bjam.srcpath() + '> ' + str(bjam_cmd))
		result = self.exec_command(bjam_cmd, cwd=bjam.srcpath())
		if not result == 0:
			Logs.error('bjam failed')
			return -1
		bjam_exe = bjam.find_resource(bjam_exe_relpath)
		if bjam_exe:
			env.BJAM = bjam_exe.srcpath()
			return 0
		Logs.error('bjam failed')
		return -1

class bjam_build(Task):
	ext_in = 'bjam_exe'
	ext_out = 'install'
	vars = ['BJAM_TOOLSET']
	def run(self):
		env = self.env
		gen = self.generator
		path = gen.path
		bld = gen.bld
		if hasattr(gen, 'root'):
			build_root = path.find_node(gen.root)
		else:
			build_root = path
		jam = bld.srcnode.find_resource(env.BJAM_CONFIG)
		if jam:
			Logs.debug('bjam: Using jam configuration from ' + jam.srcpath())
			jam_rel = jam.relpath_gen(build_root)
		else:
			Logs.warn('No build configuration in build_config/user-config.jam. Using default')
			jam_rel = None
		bjam_exe = bld.srcnode.find_node(env.BJAM)
		if not bjam_exe:
			Logs.error('env.BJAM is not set')
			return -1
		bjam_exe_rel = bjam_exe.relpath_gen(build_root)
		cmd = ([bjam_exe_rel] +
			(['--user-config=' + jam_rel] if jam_rel else []) +
			['--stagedir=' + path.get_bld().path_from(build_root)] +
			['--debug-configuration'] +
			['--with-' + lib for lib in self.generator.target] +
			(['toolset=' + env.BJAM_TOOLSET] if env.BJAM_TOOLSET else []) +
			['link=' + 'shared'] +
			['variant=' + 'release']
		)
		Logs.debug('runner: ' + build_root.srcpath() + '> ' + str(cmd))
		ret = self.exec_command(cmd, cwd=build_root.srcpath())
		if ret != 0:
			return ret
		self.set_outputs(path.get_bld().ant_glob('lib/*') + path.get_bld().ant_glob('bin/*'))
		return 0

class bjam_installer(Task):
	ext_in = 'install'
	def run(self):
		gen = self.generator
		path = gen.path
		for idir, pat in (('${LIBDIR}', 'lib/*'), ('${BINDIR}', 'bin/*')):
			files = []
			for n in path.get_bld().ant_glob(pat):
				try:
					t = readlink(n.srcpath())
					gen.bld.symlink_as(sep.join([idir, n.name]), t, postpone=False)
				except OSError:
					files.append(n)
			gen.bld.install_files(idir, files, postpone=False)
		return 0