This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith_selector.py
152 lines (122 loc) · 4.92 KB
/
with_selector.py
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from waflib.Configure import conf
from waflib.Errors import ConfigurationError
from waflib.Options import OptionsContext
from waflib import Context, Utils
import sys
all_optional = set()
all_default = {}
all_set = {'system': {}, 'bundle': {}}
def options(opt):
grp = opt.add_option_group('Dependency selection options')
grp.add_option('--all-bundled', dest='all_system',
action='store_const', const='bundle',
help="Use bundled libs where it's generally ok")
grp.add_option('--all-system', dest='all_system',
action='store_const', const='system',
help="Disable bundled libs where it's generally ok")
def configure(cfg):
if cfg.options.all_system:
x = all_set[cfg.options.all_system]
for k in x:
if getattr(cfg.options, k, None) == None:
setattr(cfg.options, k, x[k])
def with_opt(ctx, name, variants, default, help=None, cross=False,
bundle_all=None, system_all=None):
grp = ctx.get_option_group('Dependency selection options')
help = help or 'Select %s' % name
help_tail = "\v[default: %r" % default
if bundle_all: help_tail += ', --all-bundled: %r' % bundle_all
if system_all: help_tail += ', --all-system: %r' % system_all
help_tail += ']'
def x(name, help):
wname = 'with_' + name
helpmsg = '%s: %s%s' % (help, ', '.join(variants), help_tail)
all_default[wname] = default
if bundle_all: all_set['bundle'][wname] = bundle_all
if system_all: all_set['system'][wname] = system_all
if 'none' in variants: all_optional.add(name)
grp.add_option('--with-'+name, dest=wname, action='store', help=helpmsg)
if 'none' in variants:
grp.add_option(
'--without-'+name, dest=wname,
action='store_const', const='none',
help='Disable %s (same as --with-%s=none)' % (name, name))
x(name, help)
if cross: x(name + '-host', help + ' (for host)')
OptionsContext.with_opt = with_opt
def system_opt(ctx, name, cross=False, optional=False):
variants = ['bundle', 'system']
if optional:
variants.append('none')
system = 'system,none'
else:
system = 'system'
with_opt(ctx, name, variants, cross=cross,
default='system,bundle', bundle_all='bundle', system_all=system)
OptionsContext.system_opt = system_opt
app = Context.g_module.APPNAME.upper()
def run_fun(ctx, fun, def_name):
if fun == None:
return
if isinstance(fun, str):
incl_dir = ctx.path.find_dir(fun)
if not incl_dir:
ctx.fatal('%s/%s not found. Are git submodules missing?' %
(ctx.path.abspath(), fun))
ctx.env['SYSTEM_INCLUDES_' + def_name] = incl_dir.abspath()
return
return fun(ctx)
# at least ljx messes around with variants, so stash every variant
def save_envs(ctx):
stashed = set()
for k in ctx.all_envs:
stashed.add(k)
ctx.all_envs[k].stash()
return stashed
def revert_envs(ctx, stashed):
for k in stashed:
ctx.all_envs[k].revert()
def commit_envs(ctx, stashed):
for k in stashed:
ctx.all_envs[k].commit()
@conf
# chk_fun: if string, header only lib's include path
def with_chk(ctx, name, chks, cross=False, post_chk=None, define=None,
define_name=None):
def_name = define_name or Utils.quote_define_name(name)
envname = 'WITH_' + def_name
defines = 'DEFINES_' + def_name
if define == None and name in all_optional:
define = app + '_WITH_' + def_name
if 'none' not in chks:
chks['none'] = None
def x(name):
wname = 'with_' + name
opts = (getattr(ctx.options, wname) or all_default[wname]).split(',')
if opts == []:
ctx.fatal('No value specified for --with-%s' % name)
last_except = None
for opt in opts:
if not opt in chks:
ctx.fatal('Unknown option for --with-%s: %s' % (name, opt))
saved = save_envs(ctx)
try:
run_fun(ctx, chks[opt], def_name)
ctx.env[envname] = opt
if define:
val = '%s=%s' % (define, opt != 'none' and 1 or 0)
ctx.env.append_value(defines, val)
if post_chk: post_chk(ctx)
ctx.msg('Using ' + name, opt,
color = opt != 'none' and 'GREEN' or 'YELLOW')
commit_envs(ctx, saved)
return
except ConfigurationError:
revert_envs(ctx, saved)
last_except = sys.exc_info()
if sys.hexversion < 0x3000000:
exec('raise last_except[0], last_except[1], last_except[2]')
else:
exec('raise last_except[0].with_traceback(last_except[1], last_except[2])')
x(name)
if cross: ctx.only_host_env(lambda bull,shit: x(name+'-host'))