From 6b5dff9697de9ff977e0ed04dade2bfcaae9b574 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 23 Jul 2010 11:31:31 +0000 Subject: [PATCH] Handle bjam_signature in all cases where were import a callable into bjam. [SVN r64292] --- src/build/project.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/build/project.py b/src/build/project.py index b1ff07c49..d1c720c04 100644 --- a/src/build/project.py +++ b/src/build/project.py @@ -797,6 +797,13 @@ class ProjectRules: "error_reporting_wrapper", "add_rule_for_type"]] self.all_names_ = [x for x in self.local_names] + def _import_rule(self, bjam_module, name, callable): + if hasattr(callable, "bjam_signature"): + bjam.import_rule(bjam_module, name, self.make_wrapper(callable), callable.bjam_signature) + else: + bjam.import_rule(bjam_module, name, self.make_wrapper(callable)) + + def add_rule_for_type(self, type): rule_name = type.lower(); @@ -811,14 +818,20 @@ class ProjectRules: self.rules[name] = callable self.all_names_.append(name) + # Add new rule at global bjam scope. This might not be ideal, + # added because if a jamroot does 'import foo' where foo calls + # add_rule, we need to import new rule to jamroot scope, and + # I'm lazy to do this now. + self._import_rule("", name, callable) + def all_names(self): return self.all_names_ - def call_and_report_errors(self, callable, *args): + def call_and_report_errors(self, callable, *args, **kw): result = None try: self.manager_.errors().push_jamfile_context() - result = callable(*args) + result = callable(*args, **kw) except ExceptionWithUserContext, e: e.report() except Exception, e: @@ -835,8 +848,8 @@ class ProjectRules: """Given a free-standing function 'callable', return a new callable that will call 'callable' and report all exceptins, using 'call_and_report_errors'.""" - def wrapper(*args): - self.call_and_report_errors(callable, *args) + def wrapper(*args, **kw): + self.call_and_report_errors(callable, *args, **kw) return wrapper def init_project(self, project_module): @@ -851,12 +864,10 @@ class ProjectRules: else: n = string.replace(n, "_", "-") - bjam.import_rule(project_module, n, - self.make_wrapper(v)) + self._import_rule(project_module, n, v) for n in self.rules: - bjam.import_rule(project_module, n, - self.make_wrapper(self.rules[n])) + self._import_rule(project_module, n, self.rules[n]) def project(self, *args): @@ -990,10 +1001,7 @@ attribute is allowed only for top-level 'project' invocations""") for f in m.__dict__: v = m.__dict__[f] if callable(v): - if hasattr(v, "bjam_signature"): - bjam.import_rule(jamfile_module, name + "." + f, v, v.bjam_signature) - else: - bjam.import_rule(jamfile_module, name + "." + f, v) + self._import_rule(jamfile_module, name + "." + f, v) if names_to_import: if not local_names: @@ -1004,7 +1012,7 @@ attribute is allowed only for top-level 'project' invocations""") """The number of names to import and local names do not match.""") for n, l in zip(names_to_import, local_names): - bjam.import_rule(jamfile_module, l, m.__dict__[n]) + self._import_rule(jamfile_module, l, m.__dict__[n]) def conditional(self, condition, requirements): """Calculates conditional requirements for multiple requirements