]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/build-system.jam
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / build / src / build-system.jam
1 # Copyright 2003, 2005, 2007 Dave Abrahams
2 # Copyright 2006, 2007 Rene Rivera
3 # Copyright 2003, 2004, 2005, 2006 Vladimir Prus
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
7
8 # This file is part of Boost Build version 2. You can think of it as forming the
9 # main() routine. It is invoked by the bootstrapping code in bootstrap.jam.
10
11 import build-request ;
12 import builtin ;
13 import "class" : new ;
14 import configure ;
15 import config-cache ;
16 import feature ;
17 import generators ;
18 import make ;
19 import modules ;
20 import os ;
21 import path ;
22 import project ;
23 import property ;
24 import property-set ;
25 import regex ;
26 import sequence ;
27 import targets ;
28 import toolset ;
29 import utility ;
30 import version ;
31 import virtual-target ;
32
33
34 ################################################################################
35 #
36 # Module global data.
37 #
38 ################################################################################
39
40 # Shortcut used in this module for accessing used command-line parameters.
41 .argv = [ modules.peek : ARGV ] ;
42
43 # Flag indicating we should display additional debugging information related to
44 # locating and loading Boost Build configuration files.
45 .debug-config = [ MATCH ^(--debug-configuration)$ : $(.argv) ] ;
46
47 # Virtual targets obtained when building main targets references on the command
48 # line. When running 'bjam --clean main_target' we want to clean only files
49 # belonging to that main target so we need to record which targets are produced
50 # for it.
51 .results-of-main-targets = ;
52
53 # Was an XML dump requested?
54 .out-xml = [ MATCH ^--out-xml=(.*)$ : $(.argv) ] ;
55
56 # Default toolset & version to be used in case no other toolset has been used
57 # explicitly by either the loaded configuration files, the loaded project build
58 # scripts or an explicit toolset request on the command line. If not specified,
59 # an arbitrary default will be used based on the current host OS. This value,
60 # while not strictly necessary, has been added to allow testing Boost-Build's
61 # default toolset usage functionality.
62 .default-toolset = ;
63 .default-toolset-version = ;
64
65
66 ################################################################################
67 #
68 # Public rules.
69 #
70 ################################################################################
71
72 # Returns the property set with the free features from the currently processed
73 # build request.
74 #
75 rule command-line-free-features ( )
76 {
77 return $(.command-line-free-features) ;
78 }
79
80
81 # Returns the location of the build system. The primary use case is building
82 # Boost where it is sometimes needed to get the location of other components
83 # (e.g. BoostBook files) and it is convenient to use locations relative to the
84 # Boost Build path.
85 #
86 rule location ( )
87 {
88 local r = [ modules.binding build-system ] ;
89 return $(r:P) ;
90 }
91
92
93 # Sets the default toolset & version to be used in case no other toolset has
94 # been used explicitly by either the loaded configuration files, the loaded
95 # project build scripts or an explicit toolset request on the command line. For
96 # more detailed information see the comment related to used global variables.
97 #
98 rule set-default-toolset ( toolset : version ? )
99 {
100 .default-toolset = $(toolset) ;
101 .default-toolset-version = $(version) ;
102 }
103
104 rule set-pre-build-hook ( function )
105 {
106 .pre-build-hook = $(function) ;
107 }
108
109 rule set-post-build-hook ( function )
110 {
111 .post-build-hook = $(function) ;
112 }
113
114 ################################################################################
115 #
116 # Local rules.
117 #
118 ################################################################################
119
120 # Returns actual Jam targets to be used for executing a clean request.
121 #
122 local rule actual-clean-targets ( )
123 {
124 # The cleaning is tricky. Say, if user says 'bjam --clean foo' where 'foo'
125 # is a directory, then we want to clean targets which are in 'foo' as well
126 # as those in any children Jamfiles under foo but not in any unrelated
127 # Jamfiles. To achieve this we first mark all projects explicitly detected
128 # as targets for this build system run as needing to be cleaned.
129 for local t in $(targets)
130 {
131 if [ class.is-a $(t) : project-target ]
132 {
133 local project = [ $(t).project-module ] ;
134 .should-clean-project.$(project) = true ;
135 }
136 }
137
138 # Construct a list of targets explicitly detected on this build system run
139 # as a result of building main targets.
140 local targets-to-clean ;
141 for local t in $(.results-of-main-targets)
142 {
143 # Do not include roots or sources.
144 targets-to-clean += [ virtual-target.traverse $(t) ] ;
145 }
146 targets-to-clean = [ sequence.unique $(targets-to-clean) ] ;
147
148 local to-clean ;
149 for local t in [ virtual-target.all-targets ]
150 {
151 # Remove only derived targets and only those asked to be cleaned,
152 # whether directly or by belonging to one of the removed projects.
153 local p = [ $(t).project ] ;
154 if [ $(t).action ] && ( $(t) in $(targets-to-clean) ||
155 [ should-clean-project [ $(p).project-module ] ] )
156 {
157 to-clean += $(t) ;
158 }
159 }
160
161 local to-clean-actual ;
162 for local t in $(to-clean)
163 {
164 to-clean-actual += [ $(t).actualize ] ;
165 }
166 return $(to-clean-actual) ;
167 }
168
169
170 # Given a target id, try to find and return the corresponding target. This is
171 # only invoked when there is no Jamfile in ".". This code somewhat duplicates
172 # code in project-target.find but we can not reuse that code without a
173 # project-targets instance.
174 #
175 local rule find-target ( target-id )
176 {
177 local split = [ MATCH (.*)//(.*) : $(target-id) ] ;
178
179 local pm ;
180 if $(split)
181 {
182 pm = [ project.find $(split[1]) : "." ] ;
183 }
184 else
185 {
186 pm = [ project.find $(target-id) : "." ] ;
187 }
188
189 local result ;
190 if $(pm)
191 {
192 result = [ project.target $(pm) ] ;
193 }
194
195 if $(split)
196 {
197 result = [ $(result).find $(split[2]) ] ;
198 }
199
200 return $(result) ;
201 }
202
203
204 # Initializes a new configuration module.
205 #
206 local rule initialize-config-module ( module-name : location ? )
207 {
208 project.initialize $(module-name) : $(location) ;
209 if USER_MODULE in [ RULENAMES ]
210 {
211 USER_MODULE $(module-name) ;
212 }
213 }
214
215
216 # Helper rule used to load configuration files. Loads the first configuration
217 # file with the given 'filename' at 'path' into module with name 'module-name'.
218 # Not finding the requested file may or may not be treated as an error depending
219 # on the must-find parameter. Returns a normalized path to the loaded
220 # configuration file or nothing if no file was loaded.
221 #
222 local rule load-config ( module-name : filename : path + : must-find ? )
223 {
224 if $(.debug-config)
225 {
226 local path-string = $(path) ;
227 if $(path-string) = "" { path-string = . ; }
228 ECHO notice: Searching '$(path-string)' for $(module-name)
229 configuration file '$(filename)'. ;
230 }
231 local where = [ GLOB $(path) : $(filename) ] ;
232 if $(where)
233 {
234 where = [ NORMALIZE_PATH $(where[1]) ] ;
235 if $(.debug-config)
236 {
237 local where-string = $(where:D) ;
238 if $(where-string) = "" { where-string = . ; }
239 where-string = '$(where-string)' ;
240 ECHO notice: Loading $(module-name) configuration file '$(filename)'
241 from $(where-string:J=" "). ;
242 }
243
244 # Set source location so that path-constant in config files with
245 # relative paths work. This is of most importance for
246 # project-config.jam, but may be used in other config files as well.
247 local attributes = [ project.attributes $(module-name) ] ;
248 $(attributes).set source-location : $(where:D) : exact ;
249 modules.load $(module-name) : $(filename) : $(path) ;
250 project.load-used-projects $(module-name) ;
251 }
252 else if $(must-find) || $(.debug-config)
253 {
254 local path-string = $(path) ;
255 if $(path-string) = "" { path-string = . ; }
256 path-string = '$(path-string)' ;
257 path-string = $(path-string:J=" ") ;
258 if $(must-find)
259 {
260 import errors ;
261 errors.user-error Configuration file '$(filename)' not found "in"
262 $(path-string). ;
263 }
264 ECHO notice: Configuration file '$(filename)' not found "in"
265 $(path-string). ;
266 }
267 return $(where) ;
268 }
269
270
271 # Loads all the configuration files used by Boost Build in the following order:
272 #
273 # -- test-config --
274 # Loaded only if specified on the command-line using the --test-config
275 # command-line parameter. It is ok for this file not to exist even if specified.
276 # If this configuration file is loaded, regular site and user configuration
277 # files will not be. If a relative path is specified, file is searched for in
278 # the current folder.
279 #
280 # -- site-config --
281 # Always named site-config.jam. Will only be found if located on the system
282 # root path (Windows), /etc (non-Windows), user's home folder or the Boost Build
283 # path, in that order. Not loaded in case the test-config configuration file is
284 # loaded or the --ignore-site-config command-line option is specified.
285 #
286 # -- user-config --
287 # Named user-config.jam by default or may be named explicitly using the
288 # --user-config command-line option or the BOOST_BUILD_USER_CONFIG environment
289 # variable. If named explicitly the file is looked for from the current working
290 # directory and if the default one is used then it is searched for in the
291 # user's home directory and the Boost Build path, in that order. Not loaded in
292 # case either the test-config configuration file is loaded or an empty file name
293 # is explicitly specified. If the file name has been given explicitly then the
294 # file must exist.
295 #
296 # -- project-config --
297 # Always named project-config.jam. Looked up in the current working folder and
298 # then upwards through its parents up to the root folder.
299 #
300 # Test configurations have been added primarily for use by Boost Build's
301 # internal unit testing system but may be used freely in other places as well.
302 #
303 local rule load-configuration-files
304 {
305 # Flag indicating that site configuration should not be loaded.
306 local ignore-site-config =
307 [ MATCH ^(--ignore-site-config)$ : $(.argv) ] ;
308
309 initialize-config-module test-config ;
310 local test-config = [ MATCH ^--test-config=(.*)$ : $(.argv) ] ;
311 local uq = [ MATCH \"(.*)\" : $(test-config) ] ;
312 if $(uq)
313 {
314 test-config = $(uq) ;
315 }
316 if $(test-config)
317 {
318 local where = [ load-config test-config : $(test-config:BS) :
319 $(test-config:D) ] ;
320 if $(where)
321 {
322 if $(.debug-config)
323 {
324 ECHO "notice: Regular site and user configuration files will" ;
325 ECHO "notice: be ignored due to the test configuration being"
326 "loaded." ;
327 }
328 }
329 else
330 {
331 test-config = ;
332 }
333 }
334
335 local user-path = [ os.home-directories ] [ os.environ BOOST_BUILD_PATH ] ;
336 local site-path = /etc $(user-path) ;
337 if [ os.name ] in NT CYGWIN
338 {
339 site-path = [ modules.peek : SystemRoot ] $(user-path) ;
340 }
341
342 if $(.debug-config) && ! $(test-config) && $(ignore-site-config)
343 {
344 ECHO "notice: Site configuration files will be ignored due to the" ;
345 ECHO "notice: --ignore-site-config command-line option." ;
346 }
347
348 initialize-config-module site-config ;
349 if ! $(test-config) && ! $(ignore-site-config)
350 {
351 load-config site-config : site-config.jam : $(site-path) ;
352 }
353
354 initialize-config-module user-config ;
355 if ! $(test-config)
356 {
357 local user-config = [ MATCH ^--user-config=(.*)$ : $(.argv) ] ;
358 user-config = $(user-config[-1]) ;
359 user-config ?= [ os.environ BOOST_BUILD_USER_CONFIG ] ;
360 # Special handling for the case when the OS does not strip the quotes
361 # around the file name, as is the case when using Cygwin bash.
362 user-config = [ utility.unquote $(user-config) ] ;
363 local explicitly-requested = $(user-config) ;
364 user-config ?= user-config.jam ;
365
366 if $(user-config)
367 {
368 if $(explicitly-requested)
369 {
370 # Treat explicitly entered user paths as native OS path
371 # references and, if non-absolute, root them at the current
372 # working directory.
373 user-config = [ path.make $(user-config) ] ;
374 user-config = [ path.root $(user-config) [ path.pwd ] ] ;
375 user-config = [ path.native $(user-config) ] ;
376
377 if $(.debug-config)
378 {
379 ECHO notice: Loading explicitly specified user configuration
380 file: ;
381 ECHO " $(user-config)" ;
382 }
383
384 load-config user-config : $(user-config:BS) : $(user-config:D)
385 : must-exist ;
386 }
387 else
388 {
389 load-config user-config : $(user-config) : $(user-path) ;
390 }
391 }
392 else if $(.debug-config)
393 {
394 ECHO notice: User configuration file loading explicitly disabled. ;
395 }
396 }
397
398 # We look for project-config.jam from "." upward. I am not sure this is 100%
399 # right decision, we might as well check for it only alongside the Jamroot
400 # file. However:
401 # - We need to load project-config.jam before Jamroot
402 # - We probably need to load project-config.jam even if there is no Jamroot
403 # - e.g. to implement automake-style out-of-tree builds.
404 local file = [ path.glob "." : project-config.jam ] ;
405 if ! $(file)
406 {
407 file = [ path.glob-in-parents "." : project-config.jam ] ;
408 }
409 if $(file)
410 {
411 initialize-config-module project-config : $(file:D) ;
412 load-config project-config : project-config.jam : $(file:D) ;
413 }
414
415 project.end-load ;
416 }
417
418
419 # Autoconfigure toolsets based on any instances of --toolset=xx,yy,...zz or
420 # toolset=xx,yy,...zz in the command line. May return additional properties to
421 # be processed as if they had been specified by the user.
422 #
423 local rule process-explicit-toolset-requests
424 {
425 local extra-properties ;
426
427 local option-toolsets = [ regex.split-list [ MATCH ^--toolset=(.*)$ : $(.argv) ] : "," ] ;
428 local feature-toolsets = [ regex.split-list [ MATCH ^toolset=(.*)$ : $(.argv) ] : "," ] ;
429
430 for local t in $(option-toolsets) $(feature-toolsets)
431 {
432 # Parse toolset-version/properties.
433 local toolset = [ MATCH ([^/]+)/?.* : $(t) ] ;
434 local properties = [ feature.expand-subfeatures <toolset>$(toolset) : true ] ;
435 local toolset-property = [ property.select <toolset> : $(properties) ] ;
436 local known ;
437 if $(toolset-property:G=) in [ feature.values <toolset> ]
438 {
439 known = true ;
440 }
441
442 # If the toolset is not known, configure it now.
443
444 # TODO: we should do 'using $(toolset)' in case no version has been
445 # specified and there are no versions defined for the given toolset to
446 # allow the toolset to configure its default version. For this we need
447 # to know how to detect whether a given toolset has any versions
448 # defined. An alternative would be to do this whenever version is not
449 # specified but that would require that toolsets correctly handle the
450 # case when their default version is configured multiple times which
451 # should be checked for all existing toolsets first.
452
453 if ! $(known)
454 {
455 if $(.debug-config)
456 {
457 ECHO "notice: [cmdline-cfg] toolset $(toolset) not"
458 "previously configured; attempting to auto-configure now" ;
459 }
460 local t,v = [ MATCH ([^-]+)-?(.+)? : $(toolset) ] ;
461 toolset.using $(t,v[1]) : $(t,v[2]) ;
462 }
463
464 # Make sure we get an appropriate property into the build request in
465 # case toolset has been specified using the "--toolset=..." command-line
466 # option form.
467 if ! $(t) in $(.argv) $(feature-toolsets)
468 {
469 if $(.debug-config)
470 {
471 ECHO notice: [cmdline-cfg] adding toolset=$(t) to the build
472 request. ;
473 }
474 extra-properties += toolset=$(t) ;
475 }
476 }
477
478 return $(extra-properties) ;
479 }
480
481
482 # Returns whether the given project (identifed by its project module) should be
483 # cleaned because it or any of its parent projects have already been marked as
484 # needing to be cleaned in this build. As an optimization, will explicitly mark
485 # all encountered project needing to be cleaned in case thay have not already
486 # been marked so.
487 #
488 local rule should-clean-project ( project )
489 {
490 if ! $(.should-clean-project.$(project))-is-defined
491 {
492 local r = "" ;
493 if ! [ project.is-jamroot-module $(project) ]
494 {
495 local parent = [ project.attribute $(project) parent-module ] ;
496 if $(parent)
497 {
498 r = [ should-clean-project $(parent) ] ;
499 }
500 }
501 .should-clean-project.$(project) = $(r) ;
502 }
503
504 return $(.should-clean-project.$(project)) ;
505 }
506
507
508 ################################################################################
509 #
510 # main()
511 # ------
512 #
513 ################################################################################
514
515 {
516 if --version in $(.argv)
517 {
518 version.print ;
519 EXIT ;
520 }
521
522 version.verify-engine-version ;
523
524 load-configuration-files ;
525
526 # Load explicitly specified toolset modules.
527 local extra-properties = [ process-explicit-toolset-requests ] ;
528
529 # Load the actual project build script modules. We always load the project
530 # in the current folder so 'use-project' directives have any chance of being
531 # seen. Otherwise, we would not be able to refer to subprojects using target
532 # ids.
533 local current-project ;
534 {
535 local current-module = [ project.find "." : "." ] ;
536 if $(current-module)
537 {
538 current-project = [ project.target $(current-module) ] ;
539 }
540 }
541
542 # Load the default toolset module if no other has already been specified.
543 if ! [ feature.values <toolset> ]
544 {
545 local default-toolset = $(.default-toolset) ;
546 local default-toolset-version = ;
547 if $(default-toolset)
548 {
549 default-toolset-version = $(.default-toolset-version) ;
550 }
551 else
552 {
553 default-toolset = gcc ;
554 if [ os.name ] = NT
555 {
556 default-toolset = msvc ;
557 }
558 else if [ os.name ] = VMS
559 {
560 default-toolset = vmsdecc ;
561 }
562 else if [ os.name ] = MACOSX
563 {
564 default-toolset = darwin ;
565 }
566 }
567
568 ECHO "warning: No toolsets are configured." ;
569 ECHO "warning: Configuring default toolset" \"$(default-toolset)\". ;
570 ECHO "warning: If the default is wrong, your build may not work correctly." ;
571 ECHO "warning: Use the \"toolset=xxxxx\" option to override our guess." ;
572 ECHO "warning: For more configuration options, please consult" ;
573 ECHO "warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html" ;
574
575 toolset.using $(default-toolset) : $(default-toolset-version) ;
576 }
577
578
579 # Parse command line for targets and properties. Note that this requires
580 # that all project files already be loaded.
581 # FIXME: This is not entirely true. Additional project files may be loaded
582 # only later via the project.find() rule when dereferencing encountered
583 # target ids containing explicit project references. See what to do about
584 # those as such 'lazy loading' may cause problems that are then extremely
585 # difficult to debug.
586 local build-request = [ build-request.from-command-line $(.argv)
587 $(extra-properties) ] ;
588 local target-ids = [ $(build-request).get-at 1 ] ;
589 local properties = [ $(build-request).get-at 2 ] ;
590
591
592 # Check that we actually found something to build.
593 if ! $(current-project) && ! $(target-ids)
594 {
595 import errors ;
596 errors.user-error no Jamfile "in" current directory found, and no target
597 references specified. ;
598 }
599
600
601 # Flags indicating that this build system run has been started in order to
602 # clean existing instead of create new targets. Note that these are not the
603 # final flag values as they may get changed later on due to some special
604 # targets being specified on the command line.
605 local clean ; if "--clean" in $(.argv) { clean = true ; }
606 local cleanall ; if "--clean-all" in $(.argv) { cleanall = true ; }
607
608
609 # List of explicitly requested files to build. Any target references read
610 # from the command line parameter not recognized as one of the targets
611 # defined in the loaded Jamfiles will be interpreted as an explicitly
612 # requested file to build. If any such files are explicitly requested then
613 # only those files and the targets they depend on will be built and they
614 # will be searched for among targets that would have been built had there
615 # been no explicitly requested files.
616 local explicitly-requested-files
617
618
619 # List of Boost Build meta-targets, virtual-targets and actual Jam targets
620 # constructed in this build system run.
621 local targets ;
622 local virtual-targets ;
623 local actual-targets ;
624
625
626 # Process each target specified on the command-line and convert it into
627 # internal Boost Build target objects. Detect special clean target. If no
628 # main Boost Build targets were explictly requested use the current project
629 # as the target.
630 for local id in $(target-ids)
631 {
632 if $(id) = clean
633 {
634 clean = true ;
635 }
636 else
637 {
638 local t ;
639 if $(current-project)
640 {
641 t = [ $(current-project).find $(id) : no-error ] ;
642 }
643 else
644 {
645 t = [ find-target $(id) ] ;
646 }
647
648 if ! $(t)
649 {
650 ECHO "notice: could not find main target" $(id) ;
651 ECHO "notice: assuming it is a name of file to create." ;
652 explicitly-requested-files += $(id) ;
653 }
654 else
655 {
656 targets += $(t) ;
657 }
658 }
659 }
660 if ! $(targets)
661 {
662 targets += [ project.target [ project.module-name "." ] ] ;
663 }
664
665 if [ option.get dump-generators : : true ]
666 {
667 generators.dump ;
668 }
669
670 # We wish to put config.log in the build directory corresponding to Jamroot,
671 # so that the location does not differ depending on the directory we run the
672 # build from. The amount of indirection necessary here is scary.
673 local first-project = [ $(targets[0]).project ] ;
674 local first-project-root-location = [ $(first-project).get project-root ] ;
675 local first-project-root-module = [ project.load
676 $(first-project-root-location) ] ;
677 local first-project-root = [ project.target $(first-project-root-module) ] ;
678 local first-build-build-dir = [ $(first-project-root).build-dir ] ;
679 configure.set-log-file $(first-build-build-dir)/config.log ;
680 config-cache.load $(first-build-build-dir)/project-cache.jam ;
681
682 # Expand properties specified on the command line into multiple property
683 # sets consisting of all legal property combinations. Each expanded property
684 # set will be used for a single build run. E.g. if multiple toolsets are
685 # specified then requested targets will be built with each of them.
686 # The expansion is being performed as late as possible so that the feature
687 # validation is performed after all necessary modules (including project targets
688 # on the command line) have been loaded.
689 if $(properties)
690 {
691 expanded += [ build-request.convert-command-line-elements $(properties) ] ;
692 expanded = [ build-request.expand-no-defaults $(expanded) ] ;
693 local xexpanded ;
694 for local e in $(expanded)
695 {
696 xexpanded += [ property-set.create [ feature.split $(e) ] ] ;
697 }
698 expanded = $(xexpanded) ;
699 }
700 else
701 {
702 expanded = [ property-set.empty ] ;
703 }
704
705 # Now that we have a set of targets to build and a set of property sets to
706 # build the targets with, we can start the main build process by using each
707 # property set to generate virtual targets from all of our listed targets
708 # and any of their dependants.
709 for local p in $(expanded)
710 {
711 .command-line-free-features = [ property-set.create [ $(p).free ] ] ;
712 for local t in $(targets)
713 {
714 local g = [ $(t).generate $(p) ] ;
715 if ! [ class.is-a $(t) : project-target ]
716 {
717 .results-of-main-targets += $(g[2-]) ;
718 }
719 virtual-targets += $(g[2-]) ;
720 }
721 }
722
723
724 # Convert collected virtual targets into actual raw Jam targets.
725 for t in $(virtual-targets)
726 {
727 actual-targets += [ $(t).actualize ] ;
728 }
729
730 config-cache.save ;
731
732
733 # If XML data output has been requested prepare additional rules and targets
734 # so we can hook into Jam to collect build data while its building and have
735 # it trigger the final XML report generation after all the planned targets
736 # have been built.
737 if $(.out-xml)
738 {
739 # Get a qualified virtual target name.
740 rule full-target-name ( target )
741 {
742 local name = [ $(target).name ] ;
743 local project = [ $(target).project ] ;
744 local project-path = [ $(project).get location ] ;
745 return $(project-path)//$(name) ;
746 }
747
748 # Generate an XML file containing build statistics for each constituent.
749 #
750 rule out-xml ( xml-file : constituents * )
751 {
752 # Prepare valid XML header and footer with some basic info.
753 local nl = "
754 " ;
755 local os = [ modules.peek : OS OSPLAT JAMUNAME ] "" ;
756 local timestamp = [ modules.peek : JAMDATE ] ;
757 local cwd = [ PWD ] ;
758 local command = $(.argv) ;
759 local bb-version = [ version.boost-build ] ;
760 .header on $(xml-file) =
761 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
762 "$(nl)<build format=\"1.0\" version=\"$(bb-version)\">"
763 "$(nl) <os name=\"$(os[1])\" platform=\"$(os[2])\"><![CDATA[$(os[3-]:J= )]]></os>"
764 "$(nl) <timestamp><![CDATA[$(timestamp)]]></timestamp>"
765 "$(nl) <directory><![CDATA[$(cwd)]]></directory>"
766 "$(nl) <command><![CDATA[\"$(command:J=\" \")\"]]></command>"
767 ;
768 .footer on $(xml-file) =
769 "$(nl)</build>" ;
770
771 # Generate the target dependency graph.
772 .contents on $(xml-file) +=
773 "$(nl) <targets>" ;
774 for local t in [ virtual-target.all-targets ]
775 {
776 local action = [ $(t).action ] ;
777 if $(action)
778 # If a target has no action, it has no dependencies.
779 {
780 local name = [ full-target-name $(t) ] ;
781 local sources = [ $(action).sources ] ;
782 local dependencies ;
783 for local s in $(sources)
784 {
785 dependencies += [ full-target-name $(s) ] ;
786 }
787
788 local path = [ $(t).path ] ;
789 local jam-target = [ $(t).actual-name ] ;
790
791 .contents on $(xml-file) +=
792 "$(nl) <target>"
793 "$(nl) <name><![CDATA[$(name)]]></name>"
794 "$(nl) <dependencies>"
795 "$(nl) <dependency><![CDATA[$(dependencies)]]></dependency>"
796 "$(nl) </dependencies>"
797 "$(nl) <path><![CDATA[$(path)]]></path>"
798 "$(nl) <jam-target><![CDATA[$(jam-target)]]></jam-target>"
799 "$(nl) </target>"
800 ;
801 }
802 }
803 .contents on $(xml-file) +=
804 "$(nl) </targets>" ;
805
806 # Build $(xml-file) after $(constituents). Do so even if a
807 # constituent action fails and regenerate the xml on every bjam run.
808 INCLUDES $(xml-file) : $(constituents) ;
809 ALWAYS $(xml-file) ;
810 __ACTION_RULE__ on $(xml-file) =
811 build-system.out-xml.generate-action ;
812 out-xml.generate $(xml-file) ;
813 }
814
815 # The actual build actions are here; if we did this work in the actions
816 # clause we would have to form a valid command line containing the
817 # result of @(...) below (the name of the XML file).
818 #
819 rule out-xml.generate-action ( args * : xml-file
820 : command status start end user system : output ? )
821 {
822 local contents =
823 [ on $(xml-file) return $(.header) $(.contents) $(.footer) ] ;
824 local f = @($(xml-file):E=$(contents)) ;
825 }
826
827 # Nothing to do here; the *real* actions happen in
828 # out-xml.generate-action.
829 actions quietly out-xml.generate { }
830
831 # Define the out-xml file target, which depends on all the targets so
832 # that it runs the collection after the targets have run.
833 out-xml $(.out-xml) : $(actual-targets) ;
834
835 # Set up a global __ACTION_RULE__ that records all the available
836 # statistics about each actual target in a variable "on" the --out-xml
837 # target.
838 #
839 rule out-xml.collect ( xml-file : target : command status start end user
840 system : output ? )
841 {
842 local nl = "
843 " ;
844 # Open the action with some basic info.
845 .contents on $(xml-file) +=
846 "$(nl) <action status=\"$(status)\" start=\"$(start)\" end=\"$(end)\" user=\"$(user)\" system=\"$(system)\">" ;
847
848 # If we have an action object we can print out more detailed info.
849 local action = [ on $(target) return $(.action) ] ;
850 if $(action)
851 {
852 local action-name = [ $(action).action-name ] ;
853 local action-sources = [ $(action).sources ] ;
854 local action-props = [ $(action).properties ] ;
855
856 # The qualified name of the action which we created the target.
857 .contents on $(xml-file) +=
858 "$(nl) <name><![CDATA[$(action-name)]]></name>" ;
859
860 # The sources that made up the target.
861 .contents on $(xml-file) +=
862 "$(nl) <sources>" ;
863 for local source in $(action-sources)
864 {
865 local source-actual = [ $(source).actual-name ] ;
866 .contents on $(xml-file) +=
867 "$(nl) <source><![CDATA[$(source-actual)]]></source>" ;
868 }
869 .contents on $(xml-file) +=
870 "$(nl) </sources>" ;
871
872 # The properties that define the conditions under which the
873 # target was built.
874 .contents on $(xml-file) +=
875 "$(nl) <properties>" ;
876 for local prop in [ $(action-props).raw ]
877 {
878 local prop-name = [ MATCH ^<(.*)>$ : $(prop:G) ] ;
879 .contents on $(xml-file) +=
880 "$(nl) <property name=\"$(prop-name)\"><![CDATA[$(prop:G=)]]></property>" ;
881 }
882 .contents on $(xml-file) +=
883 "$(nl) </properties>" ;
884 }
885
886 local locate = [ on $(target) return $(LOCATE) ] ;
887 locate ?= "" ;
888 .contents on $(xml-file) +=
889 "$(nl) <jam-target><![CDATA[$(target)]]></jam-target>"
890 "$(nl) <path><![CDATA[$(target:G=:R=$(locate))]]></path>"
891 "$(nl) <command><![CDATA[$(command)]]></command>"
892 "$(nl) <output><![CDATA[$(output)]]></output>" ;
893 .contents on $(xml-file) +=
894 "$(nl) </action>" ;
895 }
896
897 # When no __ACTION_RULE__ is set "on" a target, the search falls back to
898 # the global module.
899 module
900 {
901 __ACTION_RULE__ = build-system.out-xml.collect
902 [ modules.peek build-system : .out-xml ] ;
903 }
904
905 IMPORT
906 build-system :
907 out-xml.collect
908 out-xml.generate-action
909 : :
910 build-system.out-xml.collect
911 build-system.out-xml.generate-action
912 ;
913 }
914
915 local j = [ option.get jobs ] ;
916 if $(j)
917 {
918 modules.poke : PARALLELISM : $(j) ;
919 }
920
921 local k = [ option.get keep-going : true : true ] ;
922 if $(k) in "on" "yes" "true"
923 {
924 modules.poke : KEEP_GOING : 1 ;
925 }
926 else if $(k) in "off" "no" "false"
927 {
928 modules.poke : KEEP_GOING : 0 ;
929 }
930 else
931 {
932 EXIT "error: Invalid value for the --keep-going option" ;
933 }
934
935 # The 'all' pseudo target is not strictly needed expect in the case when we
936 # use it below but people often assume they always have this target
937 # available and do not declare it themselves before use which may cause
938 # build failures with an error message about not being able to build the
939 # 'all' target.
940 NOTFILE all ;
941
942 # And now that all the actual raw Jam targets and all the dependencies
943 # between them have been prepared all that is left is to tell Jam to update
944 # those targets.
945 if $(explicitly-requested-files)
946 {
947 # Note that this case can not be joined with the regular one when only
948 # exact Boost Build targets are requested as here we do not build those
949 # requested targets but only use them to construct the dependency tree
950 # needed to build the explicitly requested files.
951 UPDATE $(explicitly-requested-files:G=e) $(.out-xml) ;
952 }
953 else if $(cleanall)
954 {
955 UPDATE clean-all ;
956 }
957 else if $(clean)
958 {
959 common.Clean clean : [ actual-clean-targets ] ;
960 UPDATE clean ;
961 }
962 else
963 {
964 configure.print-configure-checks-summary ;
965
966 if $(.pre-build-hook)
967 {
968 $(.pre-build-hook) ;
969 }
970
971 DEPENDS all : $(actual-targets) ;
972 if UPDATE_NOW in [ RULENAMES ]
973 {
974 local ok = [ UPDATE_NOW all ] ;
975 # Force sequence updating of regular targets, then the xml
976 # log output target. To ensure the output records all built
977 # as otherwise if could execute out-of-sequence when
978 # doing parallel builds.
979 if $(.out-xml)
980 {
981 UPDATE_NOW $(.out-xml) : : ignore-minus-n ;
982 }
983 if $(.post-build-hook)
984 {
985 $(.post-build-hook) $(ok) ;
986 }
987 # Prevent automatic update of the 'all' target, now that we have
988 # explicitly updated what we wanted.
989 UPDATE ;
990 }
991 else
992 {
993 UPDATE all $(.out-xml) ;
994 }
995 }
996 }