Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / build_system.py
1 # Status: mostly ported. Missing is --out-xml support, 'configure' integration
2 # and some FIXME.
3 # Base revision: 64351
4
5 # Copyright 2003, 2005 Dave Abrahams 
6 # Copyright 2006 Rene Rivera 
7 # Copyright 2003, 2004, 2005, 2006, 2007 Vladimir Prus 
8 # Distributed under the Boost Software License, Version 1.0. 
9 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 
10
11
12
13 from b2.build.engine import Engine
14 from b2.manager import Manager
15 from b2.util.path import glob
16 from b2.build import feature, property_set
17 import b2.build.virtual_target
18 from b2.build.targets import ProjectTarget
19 from b2.util.sequence import unique
20 import b2.build.build_request
21 from b2.build.errors import ExceptionWithUserContext
22 import b2.tools.common
23 from b2.build.toolset import using
24
25 import b2.build.project as project
26 import b2.build.virtual_target as virtual_target
27 import b2.build.build_request as build_request
28
29 import b2.util.regex
30
31 from b2.manager import get_manager
32 from b2.util import cached
33 from b2.util import option
34
35
36 import bjam
37
38 import os
39 import sys
40 import re
41
42 ################################################################################
43 #
44 # Module global data.
45 #
46 ################################################################################
47
48 # Flag indicating we should display additional debugging information related to
49 # locating and loading Boost Build configuration files.
50 debug_config = False
51
52 # Legacy option doing too many things, some of which are not even documented.
53 # Should be phased out.
54 #   * Disables loading site and user configuration files.
55 #   * Disables auto-configuration for toolsets specified explicitly on the
56 #     command-line.
57 #   * Causes --toolset command-line options to be ignored.
58 #   * Prevents the default toolset from being used even if no toolset has been
59 #     configured at all.
60 legacy_ignore_config = False
61
62 # The cleaning is tricky. Say, if user says 'bjam --clean foo' where 'foo' is a
63 # directory, then we want to clean targets which are in 'foo' as well as those
64 # in any children Jamfiles under foo but not in any unrelated Jamfiles. To
65 # achieve this we collect a list of projects under which cleaning is allowed.
66 project_targets = []
67
68 # Virtual targets obtained when building main targets references on the command
69 # line. When running 'bjam --clean main_target' we want to clean only files
70 # belonging to that main target so we need to record which targets are produced
71 # for it.
72 results_of_main_targets = []
73
74 # Was an XML dump requested?
75 out_xml = False
76
77 # Default toolset & version to be used in case no other toolset has been used
78 # explicitly by either the loaded configuration files, the loaded project build
79 # scripts or an explicit toolset request on the command line. If not specified,
80 # an arbitrary default will be used based on the current host OS. This value,
81 # while not strictly necessary, has been added to allow testing Boost-Build's
82 # default toolset usage functionality.
83 default_toolset = None
84 default_toolset_version = None
85
86 ################################################################################
87 #
88 # Public rules.
89 #
90 ################################################################################
91
92 # Returns the property set with the free features from the currently processed
93 # build request.
94 #
95 def command_line_free_features():
96     return command_line_free_features
97
98 # Sets the default toolset & version to be used in case no other toolset has
99 # been used explicitly by either the loaded configuration files, the loaded
100 # project build scripts or an explicit toolset request on the command line. For
101 # more detailed information see the comment related to used global variables.
102 #
103 def set_default_toolset(toolset, version=None):
104     default_toolset = toolset
105     default_toolset_version = version
106
107     
108 pre_build_hook = []
109
110 def add_pre_build_hook(callable):
111     pre_build_hook.append(callable)
112
113 post_build_hook = None
114
115 def set_post_build_hook(callable):
116     post_build_hook = callable
117
118 ################################################################################
119 #
120 # Local rules.
121 #
122 ################################################################################
123
124 # Returns actual Jam targets to be used for executing a clean request.
125 #
126 def actual_clean_targets(targets):
127
128     # Construct a list of projects explicitly detected as targets on this build
129     # system run. These are the projects under which cleaning is allowed.
130     for t in targets:
131         if isinstance(t, b2.build.targets.ProjectTarget):
132             project_targets.append(t.project_module())
133
134     # Construct a list of targets explicitly detected on this build system run
135     # as a result of building main targets.
136     targets_to_clean = set()
137     for t in results_of_main_targets:
138         # Do not include roots or sources.
139         targets_to_clean.update(virtual_target.traverse(t))
140
141     to_clean = []
142     for t in get_manager().virtual_targets().all_targets():
143
144         # Remove only derived targets.
145         if t.action():
146             p = t.project()
147             if t in targets_to_clean or should_clean_project(p.project_module()):
148                 to_clean.append(t)
149
150     return [t.actualize() for t in to_clean]
151
152 _target_id_split = re.compile("(.*)//(.*)")
153
154 # Given a target id, try to find and return the corresponding target. This is
155 # only invoked when there is no Jamfile in ".". This code somewhat duplicates
156 # code in project-target.find but we can not reuse that code without a
157 # project-targets instance.
158 #
159 def find_target(target_id):
160
161     projects = get_manager().projects()
162     m = _target_id_split.match(target_id)
163     if m:
164         pm = projects.find(m.group(1), ".")
165     else:
166         pm = projects.find(target_id, ".")
167
168     if pm:
169         result = projects.target(pm)
170
171     if m:
172         result = result.find(m.group(2))
173
174     return result
175
176 def initialize_config_module(module_name, location=None):
177
178     get_manager().projects().initialize(module_name, location)
179
180 # Helper rule used to load configuration files. Loads the first configuration
181 # file with the given 'filename' at 'path' into module with name 'module-name'.
182 # Not finding the requested file may or may not be treated as an error depending
183 # on the must-find parameter. Returns a normalized path to the loaded
184 # configuration file or nothing if no file was loaded.
185 #
186 def load_config(module_name, filename, paths, must_find=False):
187
188     if debug_config:
189         print "notice: Searching  '%s' for '%s' configuration file '%s." \
190               % (paths, module_name, filename)
191
192     where = None
193     for path in paths:
194         t = os.path.join(path, filename)
195         if os.path.exists(t):
196             where = t
197             break
198
199     if where:
200         where = os.path.realpath(where)
201         
202         if debug_config:
203             print "notice: Loading '%s' configuration file '%s' from '%s'." \
204                   % (module_name, filename, where)
205
206         # Set source location so that path-constant in config files
207         # with relative paths work. This is of most importance
208         # for project-config.jam, but may be used in other
209         # config files as well.
210         attributes = get_manager().projects().attributes(module_name) ;
211         attributes.set('source-location', os.path.dirname(where), True)
212         get_manager().projects().load_standalone(module_name, where)
213         
214     else:
215         msg = "Configuration file '%s' not found in '%s'." % (filename, path)
216         if must_find:
217             get_manager().errors()(msg)
218
219         elif debug_config:
220             print msg
221
222     return where
223
224 # Loads all the configuration files used by Boost Build in the following order:
225 #
226 #   -- test-config --
227 #   Loaded only if specified on the command-line using the --test-config
228 # command-line parameter. It is ok for this file not to exist even if specified.
229 # If this configuration file is loaded, regular site and user configuration
230 # files will not be. If a relative path is specified, file is searched for in
231 # the current folder.
232 #
233 #   -- site-config --
234 #   Always named site-config.jam. Will only be found if located on the system
235 # root path (Windows), /etc (non-Windows), user's home folder or the Boost Build
236 # path, in that order. Not loaded in case the test-config configuration file is
237 # loaded or either the --ignore-site-config or the --ignore-config command-line
238 # option is specified.
239 #
240 #   -- user-config --
241 #   Named user-config.jam by default or may be named explicitly using the
242 # --user-config command-line option or the BOOST_BUILD_USER_CONFIG environment
243 # variable. If named explicitly the file is looked for from the current working
244 # directory and if the default one is used then it is searched for in the
245 # user's home directory and the Boost Build path, in that order. Not loaded in
246 # case either the test-config configuration file is loaded, --ignore-config
247 # command-line option is specified or an empty file name is explicitly
248 # specified. If the file name has been given explicitly then the file must
249 # exist.
250 #
251 # Test configurations have been added primarily for use by Boost Build's
252 # internal unit testing system but may be used freely in other places as well.
253 #
254 def load_configuration_files():
255     
256     # Flag indicating that site configuration should not be loaded.
257     ignore_site_config = "--ignore-site-config" in sys.argv
258
259     if legacy_ignore_config and debug_config:
260         print "notice: Regular site and user configuration files will be ignored"
261         print "notice: due to the --ignore-config command-line option."
262
263     initialize_config_module("test-config")
264     test_config = None
265     for a in sys.argv:
266         m = re.match("--test-config=(.*)$", a)
267         if m:
268             test_config = b2.util.unquote(m.group(1))
269             break
270
271     if test_config:
272         where = load_config("test-config", os.path.basename(test_config), [os.path.dirname(test_config)])
273         if where:
274             if debug_config and not legacy_ignore_config:
275                 print "notice: Regular site and user configuration files will"
276                 print "notice: be ignored due to the test configuration being loaded."
277
278     user_path = [os.path.expanduser("~")] + bjam.variable("BOOST_BUILD_PATH")
279     site_path = ["/etc"] + user_path
280     if os.name in ["nt"]:
281         site_path = [os.getenv("SystemRoot")] + user_path
282
283     if ignore_site_config and not legacy_ignore_config:
284         print "notice: Site configuration files will be ignored due to the"
285         print "notice: --ignore-site-config command-line option."
286
287     initialize_config_module("site-config")
288     if not test_config and not ignore_site_config and not legacy_ignore_config:
289         load_config('site-config', 'site-config.jam', site_path)
290
291     initialize_config_module('user-config')
292     if not test_config and not legacy_ignore_config:
293
294         # Here, user_config has value of None if nothing is explicitly
295         # specified, and value of '' if user explicitly does not want
296         # to load any user config.
297         user_config = None
298         for a in sys.argv:
299             m = re.match("--user-config=(.*)$", a)
300             if m:
301                 user_config = m.group(1)
302                 break
303
304         if user_config is None:
305             user_config = os.getenv("BOOST_BUILD_USER_CONFIG")
306             
307         # Special handling for the case when the OS does not strip the quotes
308         # around the file name, as is the case when using Cygwin bash.
309         user_config = b2.util.unquote(user_config)
310         explicitly_requested = user_config
311         
312         if user_config is None:
313             user_config = "user-config.jam"
314
315         if user_config:
316             if explicitly_requested:
317
318                 user_config = os.path.abspath(user_config)
319             
320                 if debug_config:
321                     print "notice: Loading explicitly specified user configuration file:"
322                     print "    " + user_config
323             
324                     load_config('user-config', os.path.basename(user_config), [os.path.dirname(user_config)], True)
325             else:
326                 load_config('user-config', os.path.basename(user_config), user_path)
327         else:
328             if debug_config:
329                 print "notice: User configuration file loading explicitly disabled."
330         
331     # We look for project-config.jam from "." upward.
332     # I am not sure this is 100% right decision, we might as well check for
333     # it only alonside the Jamroot file. However:
334     #
335     # - We need to load project-root.jam before Jamroot
336     # - We probably would need to load project-root.jam even if there's no
337     #   Jamroot - e.g. to implement automake-style out-of-tree builds.
338     if os.path.exists("project-config.jam"):
339         file = ["project-config.jam"]
340     else:
341         file = b2.util.path.glob_in_parents(".", ["project-config.jam"])
342
343     if file:
344         initialize_config_module('project-config', os.path.dirname(file[0]))
345         load_config('project-config', "project-config.jam", [os.path.dirname(file[0])], True)
346
347
348 # Autoconfigure toolsets based on any instances of --toolset=xx,yy,...zz or
349 # toolset=xx,yy,...zz in the command line. May return additional properties to
350 # be processed as if they had been specified by the user.
351 #
352 def process_explicit_toolset_requests():
353
354     extra_properties = []
355
356     option_toolsets = [e for option in b2.util.regex.transform(sys.argv, "^--toolset=(.*)$")
357                        for e in option.split(',')]
358     feature_toolsets = [e for option in b2.util.regex.transform(sys.argv, "^toolset=(.*)$")
359                        for e in option.split(',')]
360
361     for t in option_toolsets + feature_toolsets:
362         
363         # Parse toolset-version/properties.
364         (toolset_version, toolset, version) = re.match("(([^-/]+)-?([^/]+)?)/?.*", t).groups()
365
366         if debug_config:
367             print "notice: [cmdline-cfg] Detected command-line request for '%s': toolset= %s version=%s" \
368             % (toolset_version, toolset, version)
369
370         # If the toolset is not known, configure it now.
371         known = False
372         if toolset in feature.values("toolset"):
373             known = True
374
375         if known and version and not feature.is_subvalue("toolset", toolset, "version", version):
376             known = False
377         # TODO: we should do 'using $(toolset)' in case no version has been
378         # specified and there are no versions defined for the given toolset to
379         # allow the toolset to configure its default version. For this we need
380         # to know how to detect whether a given toolset has any versions
381         # defined. An alternative would be to do this whenever version is not
382         # specified but that would require that toolsets correctly handle the
383         # case when their default version is configured multiple times which
384         # should be checked for all existing toolsets first.
385
386         if not known:
387
388             if debug_config:
389                 print "notice: [cmdline-cfg] toolset '%s' not previously configured; attempting to auto-configure now" % toolset_version
390             if version is not None:
391                using(toolset, version)
392             else:
393                using(toolset)
394
395         else:
396
397             if debug_config:
398
399                 print "notice: [cmdline-cfg] toolset '%s' already configured" % toolset_version
400
401         # Make sure we get an appropriate property into the build request in
402         # case toolset has been specified using the "--toolset=..." command-line
403         # option form.
404         if not t in sys.argv and not t in feature_toolsets:
405
406             if debug_config:
407                 print "notice: [cmdline-cfg] adding toolset=%s) to the build request." % t ;
408             extra_properties += "toolset=%s" % t
409
410     return extra_properties
411
412
413
414 # Returns 'true' if the given 'project' is equal to or is a (possibly indirect)
415 # child to any of the projects requested to be cleaned in this build system run.
416 # Returns 'false' otherwise. Expects the .project-targets list to have already
417 # been constructed.
418 #
419 @cached
420 def should_clean_project(project):
421
422     if project in project_targets:
423         return True
424     else:
425
426         parent = get_manager().projects().attribute(project, "parent-module")
427         if parent and parent != "user-config":
428             return should_clean_project(parent)
429         else:
430             return False
431
432 ################################################################################
433 #
434 # main()
435 # ------
436 #
437 ################################################################################
438
439 def main():
440
441     sys.argv = bjam.variable("ARGV")
442
443     # FIXME: document this option.
444     if "--profiling" in sys.argv:
445         import cProfile
446         r = cProfile.runctx('main_real()', globals(), locals(), "stones.prof")
447
448         import pstats
449         stats = pstats.Stats("stones.prof")
450         stats.strip_dirs()
451         stats.sort_stats('time', 'calls')
452         stats.print_callers(20)
453         return r
454     else:
455         try:
456             return main_real()
457         except ExceptionWithUserContext, e:
458             e.report()
459
460 def main_real():
461
462     global debug_config, legacy_ignore_config, out_xml
463
464     debug_config = "--debug-configuration" in sys.argv
465     legacy_ignore_config = "--ignore_config" in sys.argv
466     out_xml = any(re.match("^--out-xml=(.*)$", a) for a in sys.argv)
467         
468     engine = Engine()
469
470     global_build_dir = option.get("build-dir")
471     manager = Manager(engine, global_build_dir)
472
473     import b2.build.configure as configure
474
475     if "--version" in sys.argv:
476
477         version.report()
478         return
479
480     # This module defines types and generator and what not,
481     # and depends on manager's existence
482     import b2.tools.builtin
483
484     b2.tools.common.init(manager)
485
486     load_configuration_files()
487
488     extra_properties = []
489     # Note that this causes --toolset options to be ignored if --ignore-config
490     # is specified.
491     if not legacy_ignore_config:
492         extra_properties = process_explicit_toolset_requests()
493
494     # We always load project in "." so that 'use-project' directives have any
495     # chance of being seen. Otherwise, we would not be able to refer to
496     # subprojects using target ids.
497     current_project = None
498     projects = get_manager().projects()
499     if projects.find(".", "."):
500         current_project = projects.target(projects.load("."))
501
502     # In case there are no toolsets currently defined makes the build run using
503     # the default toolset.
504     if not legacy_ignore_config and not feature.values("toolset"):
505
506         dt = default_toolset
507         dtv = None
508         if default_toolset:
509             dtv = default_toolset_version
510         else:
511             dt = "gcc"
512             if os.name == 'nt':
513                 dt = "msvc"
514             # FIXME:    
515             #else if [ os.name ] = MACOSX
516             #{
517             #    default-toolset = darwin ;
518             #}                        
519
520         print "warning: No toolsets are configured."
521         print "warning: Configuring default toolset '%s'." % dt
522         print "warning: If the default is wrong, your build may not work correctly."
523         print "warning: Use the \"toolset=xxxxx\" option to override our guess."
524         print "warning: For more configuration options, please consult"
525         print "warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html"
526
527         using(dt, dtv)
528
529     # Parse command line for targets and properties. Note that this requires
530     # that all project files already be loaded.
531     (target_ids, properties) = build_request.from_command_line(sys.argv[1:] + extra_properties)
532
533     # Expand properties specified on the command line into multiple property
534     # sets consisting of all legal property combinations. Each expanded property
535     # set will be used for a single build run. E.g. if multiple toolsets are
536     # specified then requested targets will be built with each of them.
537     if properties:
538         expanded = build_request.expand_no_defaults(properties)
539     else:
540         expanded = [property_set.empty()]
541
542     # Check that we actually found something to build.
543     if not current_project and not target_ids:
544         get_manager().errors()("no Jamfile in current directory found, and no target references specified.")
545         # FIXME:
546         # EXIT
547
548     # Flags indicating that this build system run has been started in order to
549     # clean existing instead of create new targets. Note that these are not the
550     # final flag values as they may get changed later on due to some special
551     # targets being specified on the command line.
552     clean = "--clean" in sys.argv
553     cleanall = "--clean-all" in sys.argv
554
555     # List of explicitly requested files to build. Any target references read
556     # from the command line parameter not recognized as one of the targets
557     # defined in the loaded Jamfiles will be interpreted as an explicitly
558     # requested file to build. If any such files are explicitly requested then
559     # only those files and the targets they depend on will be built and they
560     # will be searched for among targets that would have been built had there
561     # been no explicitly requested files.
562     explicitly_requested_files = []
563
564     # List of Boost Build meta-targets, virtual-targets and actual Jam targets
565     # constructed in this build system run.
566     targets = []
567     virtual_targets = []
568     actual_targets = []
569
570     explicitly_requested_files = []
571
572     # Process each target specified on the command-line and convert it into
573     # internal Boost Build target objects. Detect special clean target. If no
574     # main Boost Build targets were explictly requested use the current project
575     # as the target.
576     for id in target_ids:
577         if id == "clean":
578             clean = 1
579         else:
580             t = None
581             if current_project:
582                 t = current_project.find(id, no_error=1)
583             else:
584                 t = find_target(id)
585
586             if not t:
587                 print "notice: could not find main target '%s'" % id
588                 print "notice: assuming it's a name of file to create " ;
589                 explicitly_requested_files.append(id)
590             else:
591                 targets.append(t)
592
593     if not targets:
594         targets = [projects.target(projects.module_name("."))]
595
596     # FIXME: put this BACK.
597     
598     ## if [ option.get dump-generators : : true ] 
599     ## {
600     ##     generators.dump ;
601     ## }
602
603     
604     # We wish to put config.log in the build directory corresponding
605     # to Jamroot, so that the location does not differ depending on
606     # directory where we do build.  The amount of indirection necessary
607     # here is scary.
608     first_project = targets[0].project()
609     first_project_root_location = first_project.get('project-root')
610     first_project_root_module = manager.projects().load(first_project_root_location)
611     first_project_root = manager.projects().target(first_project_root_module)
612     first_build_build_dir = first_project_root.build_dir()
613     configure.set_log_file(os.path.join(first_build_build_dir, "config.log"))
614
615     virtual_targets = []
616
617     global results_of_main_targets
618
619     # Now that we have a set of targets to build and a set of property sets to
620     # build the targets with, we can start the main build process by using each
621     # property set to generate virtual targets from all of our listed targets
622     # and any of their dependants.
623     for p in expanded:
624         manager.set_command_line_free_features(property_set.create(p.free()))
625         
626         for t in targets:
627             try:
628                 g = t.generate(p)
629                 if not isinstance(t, ProjectTarget):
630                     results_of_main_targets.extend(g.targets())
631                 virtual_targets.extend(g.targets())
632             except ExceptionWithUserContext, e:
633                 e.report()
634             except Exception:                
635                 raise
636
637     # Convert collected virtual targets into actual raw Jam targets.
638     for t in virtual_targets:
639         actual_targets.append(t.actualize())
640
641
642      # FIXME: restore
643 ##     # If XML data output has been requested prepare additional rules and targets
644 ##     # so we can hook into Jam to collect build data while its building and have
645 ##     # it trigger the final XML report generation after all the planned targets
646 ##     # have been built.
647 ##     if $(.out-xml)
648 ##     {
649 ##         # Get a qualified virtual target name.
650 ##         rule full-target-name ( target )
651 ##         {
652 ##             local name = [ $(target).name ] ;
653 ##             local project = [ $(target).project ] ;
654 ##             local project-path = [ $(project).get location ] ;
655 ##             return $(project-path)//$(name) ;
656 ##         }
657
658 ##         # Generate an XML file containing build statistics for each constituent.
659 ##         #
660 ##         rule out-xml ( xml-file : constituents * )
661 ##         {
662 ##             # Prepare valid XML header and footer with some basic info.
663 ##             local nl = "
664 ## " ;
665 ##             local jam       = [ version.jam ] ;
666 ##             local os        = [ modules.peek : OS OSPLAT JAMUNAME ] "" ;
667 ##             local timestamp = [ modules.peek : JAMDATE ] ;
668 ##             local cwd       = [ PWD ] ;
669 ##             local command   = $(.sys.argv) ;
670 ##             local bb-version = [ version.boost-build ] ;
671 ##             .header on $(xml-file) =
672 ##                 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
673 ##                 "$(nl)<build format=\"1.0\" version=\"$(bb-version)\">"
674 ##                 "$(nl)  <jam version=\"$(jam:J=.)\" />"
675 ##                 "$(nl)  <os name=\"$(os[1])\" platform=\"$(os[2])\"><![CDATA[$(os[3-]:J= )]]></os>"
676 ##                 "$(nl)  <timestamp><![CDATA[$(timestamp)]]></timestamp>"
677 ##                 "$(nl)  <directory><![CDATA[$(cwd)]]></directory>"
678 ##                 "$(nl)  <command><![CDATA[\"$(command:J=\" \")\"]]></command>"
679 ##                 ;
680 ##             .footer on $(xml-file) =
681 ##                 "$(nl)</build>" ;
682
683 ##             # Generate the target dependency graph.
684 ##             .contents on $(xml-file) +=
685 ##                 "$(nl)  <targets>" ;
686 ##             for local t in [ virtual-target.all-targets ]
687 ##             {
688 ##                 local action = [ $(t).action ] ;
689 ##                 if $(action)
690 ##                     # If a target has no action, it has no dependencies.
691 ##                 {
692 ##                     local name = [ full-target-name $(t) ] ;
693 ##                     local sources = [ $(action).sources ] ;
694 ##                     local dependencies ;
695 ##                     for local s in $(sources)
696 ##                     {
697 ##                         dependencies += [ full-target-name $(s) ] ;
698 ##                     }
699
700 ##                     local path = [ $(t).path ] ;
701 ##                     local jam-target = [ $(t).actual-name ] ;
702
703 ##                     .contents on $(xml-file) +=
704 ##                         "$(nl)    <target>"
705 ##                         "$(nl)      <name><![CDATA[$(name)]]></name>"
706 ##                         "$(nl)      <dependencies>"
707 ##                         "$(nl)        <dependency><![CDATA[$(dependencies)]]></dependency>"
708 ##                         "$(nl)      </dependencies>"
709 ##                         "$(nl)      <path><![CDATA[$(path)]]></path>"
710 ##                         "$(nl)      <jam-target><![CDATA[$(jam-target)]]></jam-target>"
711 ##                         "$(nl)    </target>"
712 ##                         ;
713 ##                 }
714 ##             }
715 ##             .contents on $(xml-file) +=
716 ##                 "$(nl)  </targets>" ;
717
718 ##             # Build $(xml-file) after $(constituents). Do so even if a
719 ##             # constituent action fails and regenerate the xml on every bjam run.
720 ##             INCLUDES $(xml-file) : $(constituents) ;
721 ##             ALWAYS $(xml-file) ;
722 ##             __ACTION_RULE__ on $(xml-file) = build-system.out-xml.generate-action ;
723 ##             out-xml.generate $(xml-file) ;
724 ##         }
725
726 ##         # The actual build actions are here; if we did this work in the actions
727 ##         # clause we would have to form a valid command line containing the
728 ##         # result of @(...) below (the name of the XML file).
729 ##         #
730 ##         rule out-xml.generate-action ( args * : xml-file
731 ##             : command status start end user system : output ? )
732 ##         {
733 ##             local contents =
734 ##                 [ on $(xml-file) return $(.header) $(.contents) $(.footer) ] ;
735 ##             local f = @($(xml-file):E=$(contents)) ;
736 ##         }
737
738 ##         # Nothing to do here; the *real* actions happen in
739 ##         # out-xml.generate-action.
740 ##         actions quietly out-xml.generate { }
741
742 ##         # Define the out-xml file target, which depends on all the targets so
743 ##         # that it runs the collection after the targets have run.
744 ##         out-xml $(.out-xml) : $(actual-targets) ;
745
746 ##         # Set up a global __ACTION_RULE__ that records all the available
747 ##         # statistics about each actual target in a variable "on" the --out-xml
748 ##         # target.
749 ##         #
750 ##         rule out-xml.collect ( xml-file : target : command status start end user
751 ##             system : output ? )
752 ##         {
753 ##             local nl = "
754 ## " ;
755 ##             # Open the action with some basic info.
756 ##             .contents on $(xml-file) +=
757 ##                 "$(nl)  <action status=\"$(status)\" start=\"$(start)\" end=\"$(end)\" user=\"$(user)\" system=\"$(system)\">" ;
758
759 ##             # If we have an action object we can print out more detailed info.
760 ##             local action = [ on $(target) return $(.action) ] ;
761 ##             if $(action)
762 ##             {
763 ##                 local action-name    = [ $(action).action-name ] ;
764 ##                 local action-sources = [ $(action).sources     ] ;
765 ##                 local action-props   = [ $(action).properties  ] ;
766
767 ##                 # The qualified name of the action which we created the target.
768 ##                 .contents on $(xml-file) +=
769 ##                     "$(nl)    <name><![CDATA[$(action-name)]]></name>" ;
770
771 ##                 # The sources that made up the target.
772 ##                 .contents on $(xml-file) +=
773 ##                     "$(nl)    <sources>" ;
774 ##                 for local source in $(action-sources)
775 ##                 {
776 ##                     local source-actual = [ $(source).actual-name ] ;
777 ##                     .contents on $(xml-file) +=
778 ##                         "$(nl)      <source><![CDATA[$(source-actual)]]></source>" ;
779 ##                 }
780 ##                 .contents on $(xml-file) +=
781 ##                     "$(nl)    </sources>" ;
782
783 ##                 # The properties that define the conditions under which the
784 ##                 # target was built.
785 ##                 .contents on $(xml-file) +=
786 ##                     "$(nl)    <properties>" ;
787 ##                 for local prop in [ $(action-props).raw ]
788 ##                 {
789 ##                     local prop-name = [ MATCH ^<(.*)>$ : $(prop:G) ] ;
790 ##                     .contents on $(xml-file) +=
791 ##                         "$(nl)      <property name=\"$(prop-name)\"><![CDATA[$(prop:G=)]]></property>" ;
792 ##                 }
793 ##                 .contents on $(xml-file) +=
794 ##                     "$(nl)    </properties>" ;
795 ##             }
796
797 ##             local locate = [ on $(target) return $(LOCATE) ] ;
798 ##             locate ?= "" ;
799 ##             .contents on $(xml-file) +=
800 ##                 "$(nl)    <jam-target><![CDATA[$(target)]]></jam-target>"
801 ##                 "$(nl)    <path><![CDATA[$(target:G=:R=$(locate))]]></path>"
802 ##                 "$(nl)    <command><![CDATA[$(command)]]></command>"
803 ##                 "$(nl)    <output><![CDATA[$(output)]]></output>" ;
804 ##             .contents on $(xml-file) +=
805 ##                 "$(nl)  </action>" ;
806 ##         }
807
808 ##         # When no __ACTION_RULE__ is set "on" a target, the search falls back to
809 ##         # the global module.
810 ##         module
811 ##         {
812 ##             __ACTION_RULE__ = build-system.out-xml.collect
813 ##                 [ modules.peek build-system : .out-xml ] ;
814 ##         }
815         
816 ##         IMPORT
817 ##             build-system :
818 ##             out-xml.collect
819 ##             out-xml.generate-action
820 ##             : :
821 ##             build-system.out-xml.collect
822 ##             build-system.out-xml.generate-action
823 ##             ;
824 ##     }
825
826     j = option.get("jobs")
827     if j:
828         bjam.call("set-variable", PARALLELISM, j)
829         
830     k = option.get("keep-going", "true", "true")
831     if k in ["on", "yes", "true"]:
832         bjam.call("set-variable", "KEEP_GOING", "1")
833     elif k in ["off", "no", "false"]:
834         bjam.call("set-variable", "KEEP_GOING", "0")
835     else:
836         print "error: Invalid value for the --keep-going option"
837         sys.exit()
838                 
839     # The 'all' pseudo target is not strictly needed expect in the case when we
840     # use it below but people often assume they always have this target
841     # available and do not declare it themselves before use which may cause
842     # build failures with an error message about not being able to build the
843     # 'all' target.
844     bjam.call("NOTFILE", "all")
845
846     # And now that all the actual raw Jam targets and all the dependencies
847     # between them have been prepared all that is left is to tell Jam to update
848     # those targets.
849     if explicitly_requested_files:
850         # Note that this case can not be joined with the regular one when only
851         # exact Boost Build targets are requested as here we do not build those
852         # requested targets but only use them to construct the dependency tree
853         # needed to build the explicitly requested files.
854         # FIXME: add $(.out-xml)
855         bjam.call("UPDATE", ["<e>%s" % x for x in explicitly_requested_files])
856     elif cleanall:
857         bjam.call("UPDATE", "clean-all")
858     elif clean:
859         manager.engine().set_update_action("common.Clean", "clean",
860                                            actual_clean_targets(targets))
861         bjam.call("UPDATE", "clean")
862     else:
863         # FIXME:
864         #configure.print-configure-checks-summary ;
865
866         if pre_build_hook:
867             for h in pre_build_hook:
868                 h()
869
870         bjam.call("DEPENDS", "all", actual_targets)
871         ok = bjam.call("UPDATE_NOW", "all") # FIXME: add out-xml
872         if post_build_hook:
873             post_build_hook(ok)
874         # Prevent automatic update of the 'all' target, now that
875         # we have explicitly updated what we wanted.            
876         bjam.call("UPDATE")
877
878     if manager.errors().count() == 0:
879         return ["ok"]
880     else:
881         return []