From c49d198fd374dbb4f662655cbb1de61e2d962d08 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 9 Aug 2010 10:30:54 +0000 Subject: [PATCH] Improve python-to-jam-to-python tunnelling of values, and 'generate' metatarget. [SVN r64691] --- v2/build/engine.py | 14 -------------- v2/build/project.py | 17 ++++++----------- v2/build/property.py | 4 ++-- v2/build/targets.py | 4 ++-- v2/build/toolset.py | 4 ++-- v2/example/generate/jamroot.jam | 2 +- v2/util/__init__.py | 20 ++++++++++++++++++-- 7 files changed, 31 insertions(+), 34 deletions(-) diff --git a/v2/build/engine.py b/v2/build/engine.py index 23fd6e58c..be9736e06 100644 --- a/v2/build/engine.py +++ b/v2/build/engine.py @@ -12,8 +12,6 @@ import re import b2.build.property_set as property_set import b2.util -_indirect_rule = re.compile("^([^%]*)%([^%]+)$") - class BjamAction: """Class representing bjam action defined from Python.""" @@ -138,18 +136,6 @@ class Engine: self.actions[action_name] = BjamAction(action_name, function) - def qualify_bjam_action(self, action_name, context_module): - - if _indirect_rule.match(action_name): - # Rule is already in indirect format - return action_name - else: - ix = action_name.find('.') - if ix != -1 and action_name[:ix] == context_module: - return context_module + '%' + action_name[ix+1:] - - return context_module + '%' + action_name - def register_bjam_action (self, action_name, function=None): """Informs self that 'action_name' is declared in bjam. diff --git a/v2/build/project.py b/v2/build/project.py index 1739d787a..8199579cf 100644 --- a/v2/build/project.py +++ b/v2/build/project.py @@ -53,6 +53,8 @@ import imp import traceback import b2.util.option as option +from b2.util import record_jam_to_value_mapping, qualify_jam_action + class ProjectRegistry: def __init__(self, manager, global_build_dir): @@ -847,7 +849,6 @@ class ProjectRules: if x not in ["__init__", "init_project", "add_rule", "error_reporting_wrapper", "add_rule_for_type", "reverse"]] self.all_names_ = [x for x in self.local_names] - self.reverse = {} def _import_rule(self, bjam_module, name, callable): if hasattr(callable, "bjam_signature"): @@ -1080,8 +1081,10 @@ attribute is allowed only for top-level 'project' invocations""") v = m.__dict__[f] f = f.replace("_", "-") if callable(v): - self._import_rule(jamfile_module, name + "." + f, v) - self.reverse.setdefault(jamfile_module, {})[name + "." + f] = v + qn = name + "." + f + self._import_rule(jamfile_module, qn, v) + record_jam_to_value_mapping(qualify_jam_action(qn, jamfile_module), v) + if names_to_import: if not local_names: @@ -1111,14 +1114,6 @@ attribute is allowed only for top-level 'project' invocations""") else: return [c + ":" + r for r in requirements] - def reverse_lookup(self, jamfile_module, name_in_jamfile_modue): - """Return callable that we've previously imported to jam.""" - - if self.reverse.has_key(jamfile_module): - return self.reverse[jamfile_module].get(name_in_jamfile_modue, None) - - return None - def option(self, name, value): name = name[0] if not name in ["site-config", "user-config", "project-config"]: diff --git a/v2/build/property.py b/v2/build/property.py index fece8c6d8..c4b13dbcb 100644 --- a/v2/build/property.py +++ b/v2/build/property.py @@ -10,7 +10,7 @@ import re from b2.util.utility import * from b2.build import feature -from b2.util import sequence +from b2.util import sequence, qualify_jam_action import b2.util.set from b2.manager import get_manager @@ -215,7 +215,7 @@ def translate_indirect(properties, context_module): result = [] for p in properties: if p.value()[0] == '@': - q = get_manager().engine().qualify_bjam_action(p.value()[1:], context_module) + q = qualify_jam_action(p.value()[1:], context_module) get_manager().engine().register_bjam_action(q) result.append(Property(p.feature(), '@' + q, p.condition())) else: diff --git a/v2/build/targets.py b/v2/build/targets.py index 87f96a4af..716cc2645 100644 --- a/v2/build/targets.py +++ b/v2/build/targets.py @@ -447,10 +447,10 @@ class ProjectTarget (AbstractTarget): # Record the name of the target, not instance, since this # rule is called before main target instaces are created. - self.explicit_targets_.add(target_name) + self.explicit_targets_.update(target_names) def mark_targets_as_always(self, target_names): - self.always_targets_.add(target_name) + self.always_targets_.update(target_names) def add_alternative (self, target_instance): """ Add new target alternative. diff --git a/v2/build/toolset.py b/v2/build/toolset.py index c5e1fb38f..b42679878 100644 --- a/v2/build/toolset.py +++ b/v2/build/toolset.py @@ -12,7 +12,7 @@ import feature, property, generators, property_set import b2.util.set -from b2.util import cached +from b2.util import cached, qualify_jam_action from b2.util.utility import * from b2.util import bjam_signature from b2.manager import get_manager @@ -122,7 +122,7 @@ def flags(rule_or_module, variable_name, condition, values = []): # Jamfile module (this will be considered as rule), but who cares? # Probably, 'flags' rule should be split into 'flags' and # 'flags-on-module'. - rule_or_module = get_manager().engine().qualify_bjam_action(rule_or_module, caller) + rule_or_module = qualify_jam_action(rule_or_module, caller) else: # FIXME: revive checking that we don't set flags for a different # module unintentionally diff --git a/v2/example/generate/jamroot.jam b/v2/example/generate/jamroot.jam index 07b8623b4..c48f2207b 100644 --- a/v2/example/generate/jamroot.jam +++ b/v2/example/generate/jamroot.jam @@ -6,4 +6,4 @@ import generate ; import gen ; -generate a2 : a.cpp : @gen.generate_example ; +generate a2 : a.cpp : @gen.generate-example ; diff --git a/v2/util/__init__.py b/v2/util/__init__.py index a53988f3b..f0fb48eb5 100644 --- a/v2/util/__init__.py +++ b/v2/util/__init__.py @@ -43,6 +43,19 @@ def unquote(s): _extract_jamfile_and_rule = re.compile("(Jamfile<.*>)%(.*)") +def qualify_jam_action(action_name, context_module): + + if _extract_jamfile_and_rule.match(action_name): + # Rule is already in indirect format + return action_name + else: + ix = action_name.find('.') + if ix != -1 and action_name[:ix] == context_module: + return context_module + '%' + action_name[ix+1:] + + return context_module + '%' + action_name + + def set_jam_action(name, *args): m = _extract_jamfile_and_rule.match(name) @@ -102,10 +115,13 @@ def value_to_jam(value, methods=False): return exported_name +def record_jam_to_value_mapping(jam_value, python_value): + __jam_to_python[jam_value] = python_value + def jam_to_value_maybe(jam_value): - if type(jam_value) == type("") and jam_value.startswith("###"): - return __jam_to_python[jam_value] + if type(jam_value) == type(""): + return __jam_to_python.get(jam_value, jam_value) else: return jam_value