2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-15 00:52:16 +00:00

Improve python-to-jam-to-python tunnelling of values, and 'generate' metatarget.

[SVN r64691]
This commit is contained in:
Vladimir Prus
2010-08-09 10:30:54 +00:00
parent a273e0d03e
commit c49d198fd3
7 changed files with 31 additions and 34 deletions

View File

@@ -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.

View File

@@ -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"]:

View File

@@ -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:

View File

@@ -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.

View File

@@ -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

View File

@@ -6,4 +6,4 @@ import generate ;
import gen ;
generate a2 : a.cpp : <generating-rule>@gen.generate_example ;
generate a2 : a.cpp : <generating-rule>@gen.generate-example ;

View File

@@ -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