summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2015-08-01 20:53:20 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2015-08-01 20:53:20 +0200
commit27777472fa26be115dab083b5df09b2e449a214c (patch)
treef5a905d92267f6350a6041c2978b5d22a1eefd50
parentfefac2c941149fb49bcb5126060be74494d0c287 (diff)
downloadmpv-build.tar.bz2
mpv-build.tar.xz
build: clean up features.py using pure functions instead of classesbuild
-rw-r--r--waftools/features.py104
1 files changed, 45 insertions, 59 deletions
diff --git a/waftools/features.py b/waftools/features.py
index d038392a82..1253bb2424 100644
--- a/waftools/features.py
+++ b/waftools/features.py
@@ -1,73 +1,59 @@
from waflib.Options import OptionsContext
import optparse
-class Feature(object):
- def __init__(self, group, feature):
- self.group = group
- self.identifier, self.attributes = feature['name'], feature
-
- def add_options(self):
- [self.add_option(option_rule) for option_rule in self.option_rules()]
-
- def add_option(self, rule):
- self.group.add_option(self.option(rule['state']),
- action=rule['action'],
- default=rule['default'],
- dest=self.storage(),
- help=self.help(rule['state']))
-
- # private
- def option_rules(self):
- return {
- 'autodetect': [
- {'state': 'disable', 'action': 'store_false', 'default': None},
- {'state': 'enable', 'action': 'store_true', 'default': None},
- ],
- 'disable': [
- {'state': 'disable', 'action': 'store_false', 'default': False},
- {'state': 'enable', 'action': 'store_true', 'default': False},
- ],
- 'enable': [
- {'state': 'disable', 'action': 'store_false', 'default': True},
- ],
- }[self.behaviour()]
-
-
- def behaviour(self):
- if 'default' in self.attributes:
- return self.attributes['default']
- else:
- return 'autodetect'
-
-
- def option(self, state):
- return "--{0}-{1}".format(state, self.identifier)
-
- def help(self, state):
- default = self.behaviour()
- if (default, state) == ("autodetect", "enable") or default == state:
- return optparse.SUPPRESS_HELP
- return "{0} {1} [{2}]" \
- .format(state, self.attributes['desc'], default)
-
- def storage(self):
- return "enable_{0}".format(self.identifier)
-
-def add_feature(group, feature):
- Feature(group, feature).add_options()
+__OPTION_RULES__ = {
+ 'autodetect': [
+ {'state': 'disable', 'action': 'store_false', 'default': None},
+ {'state': 'enable', 'action': 'store_true', 'default': None},
+ ],
+ 'disable': [
+ {'state': 'disable', 'action': 'store_false', 'default': False},
+ {'state': 'enable', 'action': 'store_true', 'default': False},
+ ],
+ 'enable': [
+ {'state': 'disable', 'action': 'store_false', 'default': True},
+ ],
+}
+
+def _feature_behaviour(feature):
+ return feature.get('default', 'autodetect')
+
+def _feature_storage(feature):
+ return "enable_{0}".format(feature['name'])
+
+def _feature_option(feature, rule):
+ return "--{0}-{1}".format(rule['state'], feature['name'])
+
+def _feature_help(feature, rule):
+ default = _feature_behaviour(feature)
+ state = rule['state']
+ if (default, state) == ("autodetect", "enable") or default == state:
+ return optparse.SUPPRESS_HELP
+ return "{0} {1} [{2}]".format(state, feature['desc'], default)
+
+def _add_option(group, feature, rule):
+ group.add_option(_feature_option(feature, rule),
+ action=rule['action'],
+ default=rule['default'],
+ dest=_feature_storage(feature),
+ help=_feature_help(feature, rule))
+
+def _add_options(group, feature):
+ rules = __OPTION_RULES__[_feature_behaviour(feature)]
+ [_add_option(group, feature, rule) for rule in rules]
def parse_features(opt, group_name, features):
- def is_feature(dep):
+ def _is_feature(dep):
return dep['name'].find('--') >= 0
- def strip_feature(dep):
+ def _strip(dep):
dep['name'] = dep['name'].lstrip('-')
return dep
- features = [strip_feature(dep) for dep in features if is_feature(dep)]
- group = opt.get_option_group(group_name)
+ features = [_strip(feature) for feature in features if _is_feature(feature)]
+ group = opt.get_option_group(group_name)
if not group:
group = opt.add_option_group(group_name)
- [add_feature(group, feature) for feature in features]
+ [_add_options(group, feature) for feature in features]
OptionsContext.parse_features = parse_features