Boost logo

Boost-Commit :

From: ghost_at_[hidden]
Date: 2007-10-14 03:20:56


Author: vladimir_prus
Date: 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
New Revision: 40002
URL: http://svn.boost.org/trac/boost/changeset/40002

Log:
Port a bunch of other Jamfile rules.

Text files modified:
   branches/build/python_port/python/TODO.txt | 4
   branches/build/python_port/python/boost/build/build/project.py | 181 ++++++++++++++++++---------------------
   branches/build/python_port/python/boost/build/build/targets.py | 17 +-
   branches/build/python_port/python/boost/build/util/path.py | 57 +++++++++++
   branches/build/python_port/python/tests/bjam/make/Jamroot | 2
   5 files changed, 151 insertions(+), 110 deletions(-)

Modified: branches/build/python_port/python/TODO.txt
==============================================================================
--- branches/build/python_port/python/TODO.txt (original)
+++ branches/build/python_port/python/TODO.txt 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
@@ -24,12 +24,15 @@
 10. In the make example, the action is called fine but
 the associated procedural code is not executed.
 
+11. Test the 'use-project' rule, 'build-project' too.
+
 
 Sanity checks:
 --------------
 
 - Review all FIXME in code
 - Remove all porting state comments at the top of files.
+- Update copyrights, add Pedro to copyrights.
 
 
 Post-port
@@ -43,3 +46,4 @@
 - Keep all information pertaining to a project inside project
 target. Kill ProjectAttributes class.
 
+********************************************************************************
\ No newline at end of file

Modified: branches/build/python_port/python/boost/build/build/project.py
==============================================================================
--- branches/build/python_port/python/boost/build/build/project.py (original)
+++ branches/build/python_port/python/boost/build/build/project.py 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
@@ -81,6 +81,13 @@
         # Map from project module to target for the project
         self.module2target = {}
 
+ # Map from project target to the list of
+ # (id,location) pairs corresponding to all 'use-project'
+ # invocations.
+ # TODO: should not have a global map, keep this
+ # in ProjectTarget.
+ self.used_projects = {}
+
         self.saved_current_project = []
 
         self.JAMROOT = self.manager.getenv("JAMROOT");
@@ -123,7 +130,7 @@
             #
             # While "build-project" and "use-project" can potentially refer
             # to child projects from parent projects, we don't immediately
- # loading child projects when seing those attributes. Instead,
+ # load child projects when seing those attributes. Instead,
             # we record the minimal information that will be used only later.
             
             self.load_used_projects(mname)
@@ -131,18 +138,15 @@
         return mname
 
     def load_used_projects(self, module_name):
- ### FIXME:
         # local used = [ modules.peek $(module-name) : .used-projects ] ;
- used = []
+ used = self.used_projects[module_name]
     
         location = self.attribute(module_name, "location")
- while used:
- id = used[0]
- where = used[1]
-
- use(id, os.path.join(location, where))
- del used[0]
- del used[1]
+ for u in used:
+ id = u[0]
+ where = u[1]
+
+ self.use(id, os.path.join(location, where))
 
     def load_parent(self, location):
         """Loads parent of Jamfile at 'location'.
@@ -287,6 +291,8 @@
         self.initialize(jamfile_module, dir, os.path.basename(jamfile_to_load))
 
         saved_project = self.current_project
+
+ self.used_projects[jamfile_module] = []
         
         # Now load the Jamfile in it's own context.
         # Initialization might have load parent Jamfiles, which might have
@@ -515,6 +521,35 @@
         Calling that rule wil relay to 'callable'."""
         self.project_rules.add_rule(name, callable)
 
+ def glob_internal(self, project, wildcards, excludes, rule_name):
+ location = project.get("source-location")
+
+ result = []
+ callable = boost.build.util.path.__dict__[rule_name]
+
+ paths = callable(location, wildcards, excludes)
+ has_dir = 0
+ for w in wildcards:
+ if os.path.dirname(w):
+ has_dir = 1
+ break
+
+ if has_dir or rule_name != "glob":
+ # The paths we've found are relative to current directory,
+ # but the names specified in sources list are assumed to
+ # be relative to source directory of the corresponding
+ # prject. So, just make the name absolute.
+ result = [os.path.join(os.getcwd(), p) for p in paths]
+ else:
+ # There were not directory in wildcard, so the files are all
+ # in the source directory of the project. Just drop the
+ # directory, instead of making paths absolute.
+ result = [os.path.basename(p) for p in paths]
+
+ return result
+
+
+# FIXME:
 # Defines a Boost.Build extension project. Such extensions usually
 # contain library targets and features that can be used by many people.
 # Even though extensions are really projects, they can be initialize as
@@ -555,36 +590,6 @@
 # $(attributes).set parent-module : $(root-project) : exact ;
 # }
 #}
-
-#rule glob-internal ( project : wildcards + : excludes * : rule-name )
-#{
-# local location = [ $(project).get source-location ] ;
-#
-# local result ;
-# local paths = [ path.$(rule-name) $(location)
-# : [ sequence.transform path.make : $(wildcards) ]
-# : [ sequence.transform path.make : $(excludes) ] ] ;
-# if $(wildcards:D) || $(rule-name) != glob
-# {
-# # The paths we've found are relative to current directory,
-# # but the names specified in sources list are assumed to
-# # be relative to source directory of the corresponding
-# # prject. So, just make the name absolute.
-# for local p in $(paths)
-# {
-# result += [ path.root $(p) [ path.pwd ] ] ;
-# }
-# }
-# else
-# {
-# # There were not directory in wildcard, so the files are all
-# # in the source directory of the project. Just drop the
-# # directory, instead of making paths absolute.
-# result = $(paths:D="") ;
-# }
-#
-# return $(result) ;
-#}
         
 
 class ProjectAttributes:
@@ -715,6 +720,7 @@
             # while using self.__dict__[r] would give unbound one.
             v = getattr(self, n)
             if callable(v):
+ n = string.replace(n, "_", "-")
                 print "Importing '%s' to bjam" % n
                 bjam.import_rule(project_module, n, v)
 
@@ -724,8 +730,6 @@
     def project(self, *args):
 
         jamfile_module = self.registry.current().project_module()
- print "Setting 'test'"
- bjam.call("set-variable", jamfile_module, "test", "passed")
         attributes = self.registry.attributes(jamfile_module)
         
         id = None
@@ -785,9 +789,44 @@
         value path is taken to be either absolute, or relative to this project
         root."""
         self.registry.current().add_constant(name[0], value, path=1)
-
- def foobar(self, param):
- print "foobar called!"
+
+ def use_project(self, id, where):
+ # See comment in 'load' for explanation why we record the
+ # parameters as opposed to loading the project now.
+ m = self.registry.current().project_module();
+ self.registry.used_projects[m].append((id, where))
+
+ def build_project(self, dir):
+ jamfile_module = self.registry.current().project_module()
+ attributes = self.registry.attributes(jamfile_module)
+ now = attributes.get("projects-to-build")
+ attributes.set("projects-to-build", now.append(dir))
+
+ def explicit(self, target_names):
+ t = self.registry.current()
+ for n in target_names:
+ t.mark_target_as_explicit(n)
+
+ def glob(self, wildcards, excludes=None):
+ return self.registry.glob_internal(self.registry.current(),
+ wildcards, excludes, "glob")
+
+ def glob_tree(self, wildcards, excludes=None):
+ bad = 0
+ for p in wildcards:
+ if os.path.dirname(p):
+ bad = 1
+
+ if excludes:
+ for p in excludes:
+ if os.path.dirname(p):
+ bad = 1
+
+ if bad:
+ self.registry.manager().errors()(
+"The patterns to 'glob-tree' may not include directory")
+ return self.registry.glob_internal(self.registry.current(),
+ wildcards, excludes, "glob_tree")
     
 
 # FIXME
@@ -839,53 +878,7 @@
     
 
 
-## rule use-project ( id : where )
-## {
-## # See comment in 'load' for explanation.
-## .used-projects += $(id) $(where) ;
-## }
-
-## rule build-project ( dir )
-## {
-## import project ;
-## local attributes = [ project.attributes $(__name__) ] ;
-
-## local now = [ $(attributes).get projects-to-build ] ;
-## $(attributes).set projects-to-build : $(now) $(dir) ;
-## }
-
-## rule explicit ( target-names * )
-## {
-## import project ;
-## # If 'explicit' is used in a helper rule defined in Jamroot,
-## # and inherited by children, then most of the time
-## # we want 'explicit' to operate on the Jamfile where
-## # the helper rule is invoked.
-## local t = [ project.current ] ;
-## for local n in $(target-names)
-## {
-## $(t).mark-target-as-explicit $(n) ;
-## }
-## }
-
-## rule glob ( wildcards + : excludes * )
-## {
-## import project ;
-## return [ project.glob-internal [ project.current ]
-## : $(wildcards) : $(excludes) : glob ] ;
-## }
 
-## rule glob-tree ( wildcards + : excludes * )
-## {
-## import project ;
-
-## if $(wildcards:D) || $(excludes:D)
-## {
-## errors.user-error "The patterns to 'glob-tree' may not include directory" ;
-## }
-## return [ project.glob-internal [ project.current ]
-## : $(wildcards) : $(excludes) : glob-tree ] ;
-## }
 
 ## # Calculates conditional requirements for multiple requirements
 ## # at once. This is a shorthand to be reduce duplication and to
@@ -899,9 +892,3 @@
 ## return $(condition:J=,):$(requirements) ;
 ## }
 ## }
-
-
-## local rule __test__ ( )
-## {
-## import assert ;
-## }

Modified: branches/build/python_port/python/boost/build/build/targets.py
==============================================================================
--- branches/build/python_port/python/boost/build/build/targets.py (original)
+++ branches/build/python_port/python/boost/build/build/targets.py 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
@@ -399,15 +399,14 @@
             result.append (self.project_module_.registry ().target (p))
                         
         return result
-
-# # Add 'target' to the list of targets in this project that should be build
-# # only by explicit request
-# rule mark-target-as-explicit ( target-name )
-# {
-# # Record the name of the target, not instance, since this
-# # rule is called before main target instaces are created.
-# self.explicit_targets_ += $(target-name) ;
-# }
+
+ def mark_target_as_explicit (self, target_name):
+ """Add 'target' to the list of targets in this project
+ that should be build only by explicit request."""
+
+ # Record the name of the target, not instance, since this
+ # rule is called before main target instaces are created.
+ self.explicit_.append(target_name)
 
     def create_main_target (self, name):
         """ Returns a 'MainTarget' class instance corresponding to the 'name'.

Modified: branches/build/python_port/python/boost/build/util/path.py
==============================================================================
--- branches/build/python_port/python/boost/build/util/path.py (original)
+++ branches/build/python_port/python/boost/build/util/path.py 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
@@ -1,3 +1,7 @@
+# Status: this module is ported on demand by however needs something
+# from it. Functionality that is not needed by Python port will
+# be dropped.
+
 # Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
 # distribute this software is granted provided this copyright notice appears in
 # all copies. This software is provided "as is" without express or implied
@@ -810,10 +814,55 @@
 #
 
 
-def glob(dir, patterns):
- result = []
- for pattern in patterns:
- result.extend(builtin_glob(os.path.join(dir, pattern)))
+#def glob(dir, patterns):
+# result = []
+# for pattern in patterns:
+# result.extend(builtin_glob(os.path.join(dir, pattern)))
+# return result
+
+def glob(dirs, patterns, exclude_patterns=None):
+ """Returns the list of files matching the given pattern in the
+ specified directory. Both directories and patterns are
+ supplied as portable paths. Each pattern should be non-absolute
+ path, and can't contain '.' or '..' elements. Each slash separated
+ element of pattern can contain the following special characters:
+ - '?', which match any character
+ - '*', which matches arbitrary number of characters.
+ A file $(d)/e1/e2/e3 (where 'd' is in $(dirs)) matches pattern p1/p2/p3
+ if and only if e1 matches p1, e2 matches p2 and so on.
+ For example:
+ [ glob . : *.cpp ]
+ [ glob . : */build/Jamfile ]
+ """
+ if not exclude_patterns:
+ exclude_patterns = []
+
+ real_patterns = [os.path.join(d, p) for p in patterns for d in dirs]
+ real_exclude_patterns = [os.path.join(d, p) for p in exclude_patterns
+ for d in dirs]
+
+ inc = [os.path.normpath(name) for p in real_patterns
+ for name in builtin_glob(p)]
+ exc = [os.path.normpath(name) for p in real_exclude_patterns
+ for name in builtin_glob(p)]
+ return [x for x in inc if x not in exc]
+
+def glob_tree(roots, patterns, exclude_patterns=None):
+ """Recursive version of GLOB. Builds the glob of files while
+ also searching in the subdirectories of the given roots. An
+ optional set of exclusion patterns will filter out the
+ matching entries from the result. The exclusions also apply
+ to the subdirectory scanning, such that directories that
+ match the exclusion patterns will not be searched."""
+
+ if not exclude_patterns:
+ exclude_patterns = []
+
+ result = glob(roots, patterns, exclude_patterns)
+ subdirs = [s for s in result if s != "." and s != ".." and os.path.isdir(s)]
+ if subdirs:
+ result.extend(glob_tree(subdirs, patterns, exclude_patterns))
+
     return result
 
 def glob_in_parents(dir, patterns, upper_limit=None):

Modified: branches/build/python_port/python/tests/bjam/make/Jamroot
==============================================================================
--- branches/build/python_port/python/tests/bjam/make/Jamroot (original)
+++ branches/build/python_port/python/tests/bjam/make/Jamroot 2007-10-14 03:20:55 EDT (Sun, 14 Oct 2007)
@@ -4,6 +4,8 @@
 constant FOO : foo ;
 ECHO "FOO is" $(FOO) ;
 
+#ECHO "GLOB RESULT:" [ glob-tree * ] ;
+
 make a : a.cpp : $(__name__).copy ;
 
 rule copy ( targets : sources : properties * )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk