From fa7f2cb8accbdf1ed7fe13439b89ef7e4518f692 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 26 Jul 2010 11:40:00 +0000 Subject: [PATCH] Make build-dir project attribute and command-line option work. [SVN r64357] --- v2/build/project.py | 22 +++++++++++----------- v2/build/targets.py | 3 +-- v2/build_system.py | 1 - v2/test/build_dir.py | 2 +- v2/util/option.py | 5 +++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/v2/build/project.py b/v2/build/project.py index ff50f224d..a772edc41 100644 --- a/v2/build/project.py +++ b/v2/build/project.py @@ -56,7 +56,7 @@ class ProjectRegistry: def __init__(self, manager, global_build_dir): self.manager = manager - self.global_build_dir = None + self.global_build_dir = global_build_dir self.project_rules_ = ProjectRules(self) # The target corresponding to the project being loaded now @@ -339,7 +339,7 @@ expected value %s actual value %s""" % (jamfile_module, saved_project, self.current_project)) if self.global_build_dir: - id = self.attribute(jamfile_module, "id") + id = self.attributeDefault(jamfile_module, "id", None) project_root = self.attribute(jamfile_module, "project-root") location = self.attribute(jamfile_module, "location") @@ -393,8 +393,6 @@ actual value %s""" % (jamfile_module, saved_project, self.current_project)) # source paths are correct. if not location: location = "" - else: - location = b2.util.path.relpath(os.getcwd(), location) attributes = ProjectAttributes(self.manager, location, module_name) self.module2attributes[module_name] = attributes @@ -523,8 +521,7 @@ actual value %s""" % (jamfile_module, saved_project, self.current_project)) try: return self.module2attributes[project].get(attribute) except: - print "Sucks", project, attribute - raise "Sucks" + raise BaseException("No attribute '%s' for project" % (attribute, project)) def attributeDefault(self, project, attribute, default): """Returns the value of the specified attribute in the @@ -708,7 +705,7 @@ class ProjectAttributes: self.attributes = {} self.usage_requirements = None - def set(self, attribute, specification, exact): + def set(self, attribute, specification, exact=False): """Set the named attribute from the specification given by the user. The value actually set may be different.""" @@ -893,6 +890,8 @@ class ProjectRules: id = '/' + id self.registry.register_id (id, jamfile_module) + attributes.set('id', id) + explicit_build_dir = None for a in args: if a: @@ -912,16 +911,17 @@ class ProjectRules: # This is Jamroot. if id: if explicit_build_dir and os.path.isabs(explicit_build_dir): - self.register.manager.errors()( + self.registry.manager.errors()( """Absolute directory specified via 'build-dir' project attribute Don't know how to combine that with the --build-dir option.""") rid = id if rid[0] == '/': rid = rid[1:] - - p = os.path.join(self.registry.global_build_dir, - rid, explicit_build_dir) + + p = os.path.join(self.registry.global_build_dir, rid) + if explicit_build_dir: + p = os.path.join(p, explicit_build_dir) attributes.set("build-dir", p, exact=1) elif explicit_build_dir: self.registry.manager.errors()( diff --git a/v2/build/targets.py b/v2/build/targets.py index d86f67a68..30bbf6fdd 100644 --- a/v2/build/targets.py +++ b/v2/build/targets.py @@ -380,8 +380,7 @@ class ProjectTarget (AbstractTarget): if not self.build_dir_: self.build_dir_ = self.get ('build-dir') if not self.build_dir_: - self.build_dir_ = os.path.join (os.path.dirname( - self.project_.get ('location')), 'bin') + self.build_dir_ = os.path.join(self.project_.get ('location'), 'bin') return self.build_dir_ diff --git a/v2/build_system.py b/v2/build_system.py index 7146579c2..57f41cff8 100644 --- a/v2/build_system.py +++ b/v2/build_system.py @@ -453,7 +453,6 @@ def main_real(): engine = Engine() global_build_dir = option.get("build-dir") - manager = Manager(engine, global_build_dir) if "--version" in sys.argv: diff --git a/v2/test/build_dir.py b/v2/test/build_dir.py index c5bcbc5b9..ad5327979 100644 --- a/v2/test/build_dir.py +++ b/v2/test/build_dir.py @@ -99,7 +99,7 @@ exe a : a.cpp ; build-project sub ; """ % string.replace(os.getcwd(), '\\', '\\\\')) -t.run_build_system("--build-dir=build", status=1) +t.run_build_system("--build-dir=build") t.fail_test(string.find(t.stdout(), "Absolute directory specified via 'build-dir' project attribute") == -1) diff --git a/v2/util/option.py b/v2/util/option.py index 1f253f1c4..bf0eb2346 100644 --- a/v2/util/option.py +++ b/v2/util/option.py @@ -5,6 +5,7 @@ # http://www.boost.org/LICENSE_1_0.txt) import sys +import re import b2.util.regex options = {} @@ -21,11 +22,11 @@ def get(name, default_value=None, implied_value=None): global options - matches = b2.util.regex.transform(sys.argv, "--$(name)=(.*)") + matches = b2.util.regex.transform(sys.argv, "--" + re.escape(name) + "=(.*)") if matches: return matches[-1] else: - m = b2.util.regex.transform(sys.argv, "--$(name)") + m = b2.util.regex.transform(sys.argv, "--" + re.escape(name)) if m and implied_value: return implied_value elif options.has_key(name):