]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/util/doc.jam
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / src / util / doc.jam
1 # Copyright 2002, 2005 Dave Abrahams
2 # Copyright 2002, 2003, 2006 Rene Rivera
3 # Copyright 2003 Vladimir Prus
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7 # Documentation system, handles --help requests.
8 # It defines rules that attach documentation to modules, rules, and variables.
9 # Collects and generates documentation for the various parts of the build
10 # system. The documentation is collected from comments integrated into the code.
11
12 import modules ;
13 import print ;
14 import set ;
15 import container ;
16 import "class" ;
17 import sequence ;
18 import path ;
19
20
21 # The type of output to generate.
22 # "console" is formated text echoed to the console (the default);
23 # "text" is formated text appended to the output file;
24 # "html" is HTML output to the file.
25 #
26 help-output = console ;
27
28
29 # The file to output documentation to when generating "text" or "html" help.
30 # This is without extension as the extension is determined by the type of
31 # output.
32 #
33 help-output-file = help ;
34
35 # Whether to include local rules in help output.
36 #
37 .option.show-locals ?= ;
38
39 # When showing documentation for a module, whether to also generate
40 # automatically the detailed docs for each item in the module.
41 #
42 .option.detailed ?= ;
43
44 # Generate debug output as the help is generated and modules are parsed.
45 #
46 .option.debug ?= ;
47
48 # These are all the options available for enabling or disabling to control the
49 # help system in various ways. Options can be enabled or disabled with
50 # '--help-enable-<option>', and '--help-disable-<option>' respectively.
51 #
52 .option-description = Help Options ;
53
54 # Enable or disable a documentation option.
55 #
56 local rule set-option (
57 option # The option name.
58 : value ? # Enabled (non-empty), or disabled (empty)
59 )
60 {
61 .option.$(option) = $(value) ;
62 }
63
64
65 # Set the type of output.
66 #
67 local rule set-output ( type )
68 {
69 help-output = $(type) ;
70 }
71
72
73 # Set the output to a file.
74 #
75 local rule set-output-file ( file )
76 {
77 help-output-file = $(file) ;
78 }
79
80
81 # Extracts the brief comment from a complete comment. The brief comment is the
82 # first sentence.
83 #
84 local rule brief-comment (
85 docs * # The comment documentation.
86 )
87 {
88 local d = $(docs:J=" ") ;
89 local p = [ MATCH ".*([.])$" : $(d) ] ;
90 if ! $(p) { d = $(d)"." ; }
91 d = $(d)" " ;
92 local m = [ MATCH "^([^.]+[.])(.*)" : $(d) ] ;
93 local brief = $(m[1]) ;
94 while $(m[2]) && [ MATCH "^([^ ])" : $(m[2]) ]
95 {
96 m = [ MATCH "^([^.]+[.])(.*)" : $(m[2]) ] ;
97 brief += $(m[1]) ;
98 }
99 return $(brief:J="") ;
100 }
101
102
103 # Specifies the documentation for the current module.
104 #
105 local rule set-module-doc (
106 module-name ? # The name of the module to document.
107 : docs * # The documentation for the module.
108 )
109 {
110 module-name ?= * ;
111
112 $(module-name).brief = [ brief-comment $(docs) ] ;
113 $(module-name).docs = $(docs) ;
114
115 if ! $(module-name) in $(documented-modules)
116 {
117 documented-modules += $(module-name) ;
118 }
119 }
120
121
122 # Specifies the documentation for the current module.
123 #
124 local rule set-module-copyright (
125 module-name ? # The name of the module to document.
126 : copyright * # The copyright for the module.
127 )
128 {
129 module-name ?= * ;
130
131 $(module-name).copy-brief = [ brief-comment $(copyright) ] ;
132 $(module-name).copy-docs = $(docs) ;
133
134 if ! $(module-name) in $(documented-modules)
135 {
136 documented-modules += $(module-name) ;
137 }
138 }
139
140
141 # Specifies the documentation for a rule in the current module. If called in the
142 # global module, this documents a global rule.
143 #
144 local rule set-rule-doc (
145 name # The name of the rule.
146 module-name ? # The name of the module to document.
147 is-local ? # Whether the rule is local to the module.
148 : docs * # The documentation for the rule.
149 )
150 {
151 module-name ?= * ;
152
153 $(module-name).$(name).brief = [ brief-comment $(docs) ] ;
154 $(module-name).$(name).docs = $(docs) ;
155 $(module-name).$(name).is-local = $(is-local) ;
156
157 if ! $(name) in $($(module-name).rules)
158 {
159 $(module-name).rules += $(name) ;
160 }
161 }
162
163
164 # Specify a class, will turn a rule into a class.
165 #
166 local rule set-class-doc (
167 name # The name of the class.
168 module-name ? # The name of the module to document.
169 : super-name ? # The super class name.
170 )
171 {
172 module-name ?= * ;
173
174 $(module-name).$(name).is-class = true ;
175 $(module-name).$(name).super-name = $(super-name) ;
176 $(module-name).$(name).class-rules =
177 [ MATCH "^($(name)[.].*)" : $($(module-name).rules) ] ;
178 $(module-name).$($(module-name).$(name).class-rules).is-class-rule = true ;
179
180 $(module-name).classes += $(name) ;
181 $(module-name).class-rules += $($(module-name).$(name).class-rules) ;
182 $(module-name).rules =
183 [ set.difference $($(module-name).rules) :
184 $(name) $($(module-name).$(name).class-rules) ] ;
185 }
186
187
188 # Set the argument call signature of a rule.
189 #
190 local rule set-rule-arguments-signature (
191 name # The name of the rule.
192 module-name ? # The name of the module to document.
193 : signature * # The arguments signature.
194 )
195 {
196 module-name ?= * ;
197
198 $(module-name).$(name).signature = $(signature) ;
199 }
200
201
202 # Specifies the documentation for an argument of a rule.
203 #
204 local rule set-argument-doc (
205 name # The name of the argument.
206 qualifier # Argument syntax qualifier, "*", "+", etc.
207 rule-name # The name of the rule.
208 module-name ? # THe optional name of the module.
209 : docs * # The documentation.
210 )
211 {
212 module-name ?= * ;
213
214 $(module-name).$(rule-name).args.$(name).qualifier = $(qualifier) ;
215 $(module-name).$(rule-name).args.$(name).docs = $(docs) ;
216
217 if ! $(name) in $($(module-name).$(rule-name).args)
218 {
219 $(module-name).$(rule-name).args += $(name) ;
220 }
221 }
222
223
224 # Specifies the documentation for a variable in the current module. If called in
225 # the global module, the global variable is documented.
226 #
227 local rule set-variable-doc (
228 name # The name of the variable.
229 default # The default value.
230 initial # The initial value.
231 module-name ? # The name of the module to document.
232 : docs * # The documentation for the variable.
233 )
234 {
235 module-name ?= * ;
236
237 $(module-name).$(name).brief = [ brief-comment $(docs) ] ;
238 $(module-name).$(name).default = $(default) ;
239 $(module-name).$(name).initial = $(initial) ;
240 $(module-name).$(name).docs = $(docs) ;
241
242 if ! $(name) in $($(module-name).variables)
243 {
244 $(module-name).variables += $(name) ;
245 }
246 }
247
248
249 # Generates a general description of the documentation and help system.
250 #
251 local rule print-help-top ( )
252 {
253 print.section "General command line usage" ;
254
255 print.text " b2 [options] [properties] [targets]
256
257 Options, properties and targets can be specified in any order.
258 " ;
259
260 print.section "Important Options" ;
261
262 print.list-start ;
263 print.list-item "--clean Remove targets instead of building" ;
264 print.list-item "-a Rebuild everything" ;
265 print.list-item "-n Don't execute the commands, only print them" ;
266 print.list-item "-d+2 Show commands as they are executed" ;
267 print.list-item "-d0 Suppress all informational messages" ;
268 print.list-item "-q Stop at first error" ;
269 print.list-item "--reconfigure Rerun all configuration checks" ;
270 print.list-item "--debug-configuration Diagnose configuration" ;
271 print.list-item "--debug-building Report which targets are built with what properties" ;
272 print.list-item "--debug-generator Diagnose generator search/execution" ;
273 print.list-end ;
274
275 print.section "Further Help"
276 The following options can be used to obtain additional documentation.
277 ;
278
279 print.list-start ;
280 print.list-item "--help-options Print more obscure command line options." ;
281 print.list-item "--help-internal Boost.Build implementation details." ;
282 print.list-item "--help-doc-options Implementation details doc formatting." ;
283 print.list-end ;
284 }
285
286
287 # Generate Jam/Boost.Jam command usage information.
288 #
289 local rule print-help-usage ( )
290 {
291 print.section "Boost.Build Usage"
292 "b2 [ options... ] targets..."
293 ;
294 print.list-start ;
295 print.list-item -a;
296 Build all targets, even if they are current. ;
297 print.list-item -fx;
298 Read '"x"' as the Jamfile for building instead of searching for the
299 Boost.Build system. ;
300 print.list-item -jx;
301 Run up to '"x"' commands concurrently. ;
302 print.list-item -n;
303 Do not execute build commands. Instead print out the commands as they
304 would be executed if building. ;
305 print.list-item -ox;
306 Output the used build commands to file '"x"'. ;
307 print.list-item -q;
308 Quit as soon as a build failure is encountered. Without this option
309 Boost.Jam will continue building as many targets as it can. ;
310 print.list-item -sx=y;
311 Sets a Jam variable '"x"' to the value '"y"', overriding any value that
312 variable would have from the environment. ;
313 print.list-item -tx;
314 Rebuild the target '"x"', even if it is up-to-date. ;
315 print.list-item -v;
316 Display the version of b2. ;
317 print.list-item --x;
318 Any option not explicitly handled by Boost.Build remains available to
319 build scripts using the '"ARGV"' variable. ;
320 print.list-item --abbreviate-paths;
321 Use abbreviated paths for targets. ;
322 print.list-item --hash;
323 Shorten target paths by using an MD5 hash. ;
324 print.list-item -dn;
325 Enables output of diagnostic messages. The debug level '"n"' and all
326 below it are enabled by this option. ;
327 print.list-item -d+n;
328 Enables output of diagnostic messages. Only the output for debug level
329 '"n"' is enabled. ;
330 print.list-end ;
331 print.section "Debug Levels"
332 Each debug level shows a different set of information. Usually with
333 higher levels producing more verbose information. The following levels
334 are supported: ;
335 print.list-start ;
336 print.list-item 0;
337 Turn off all diagnostic output. Only errors are reported. ;
338 print.list-item 1;
339 Show the actions taken for building targets, as they are executed. ;
340 print.list-item 2;
341 Show "quiet" actions and display all action text, as they are executed. ;
342 print.list-item 3;
343 Show dependency analysis, and target/source timestamps/paths. ;
344 print.list-item 4;
345 Show arguments of shell invocations. ;
346 print.list-item 5;
347 Show rule invocations and variable expansions. ;
348 print.list-item 6;
349 Show directory/header file/archive scans, and attempts at binding to targets. ;
350 print.list-item 7;
351 Show variable settings. ;
352 print.list-item 8;
353 Show variable fetches, variable expansions, and evaluation of '"if"' expressions. ;
354 print.list-item 9;
355 Show variable manipulation, scanner tokens, and memory usage. ;
356 print.list-item 10;
357 Show execution times for rules. ;
358 print.list-item 11;
359 Show parsing progress of Jamfiles. ;
360 print.list-item 12;
361 Show graph for target dependencies. ;
362 print.list-item 13;
363 Show changes in target status (fate). ;
364 print.list-end ;
365 }
366
367 # Generates description of options controlling the help system. This
368 # automatically reads the options as all variables in the module given
369 # with the name `module-name` of the form ".option.*".
370 #
371 local rule print-help-options (
372 module-name
373 )
374 {
375 local options-to-list = [ MATCH ^[.]option[.](.*) : $($(module-name).variables) ] ;
376 if $(options-to-list)
377 {
378 local option-title = $($(module-name)..option-description.initial) ;
379 if ! $(option-title) || $(option-title) = "(empty)"
380 {
381 option-title = "$(module-name) Options" ;
382 }
383 local option-description = $(option-title)
384 $($(module-name)..option-description.docs) ;
385 print.section $(option-description) ;
386 print.list-start ;
387 for local option in [ sequence.insertion-sort $(options-to-list) ]
388 {
389 local def = disabled ;
390 if $($(module-name)..option.$(option).default) != "(empty)"
391 {
392 def = $($(module-name)..option.$(option).default) ;
393 }
394 print.list-item $(option): $($(module-name)..option.$(option).docs)
395 Default is $(def). ;
396 }
397 print.list-end ;
398 }
399 }
400
401
402 # Generate brief documentation for all the known items in the section for a
403 # module. Possible sections are: "rules", and "variables".
404 #
405 local rule print-help-module-section (
406 module # The module name.
407 section # rules or variables.
408 : section-head # The title of the section.
409 section-description * # The detailed description of the section.
410 )
411 {
412 if $($(module).$(section))
413 {
414 print.section $(section-head) $(section-description) ;
415 print.list-start ;
416 for local item in [ sequence.insertion-sort $($(module).$(section)) ]
417 {
418 local show = ;
419 if ! $($(module).$(item).is-local)
420 {
421 show = yes ;
422 }
423 if $(.option.show-locals)
424 {
425 show = yes ;
426 }
427 if $(show)
428 {
429 print.list-item $(item): $($(module).$(item).brief) ;
430 }
431 }
432 print.list-end ;
433 }
434 }
435
436
437 # Generate documentation for all possible modules. We attempt to list all known
438 # modules together with a brief description of each.
439 #
440 local rule print-help-all (
441 ignored # Usually the module name, but is ignored here.
442 )
443 {
444 print.section "Modules"
445 "These are all the known modules. Use --help <module> to get more"
446 "detailed information."
447 ;
448 if $(documented-modules)
449 {
450 print.list-start ;
451 for local module-name in [ sequence.insertion-sort $(documented-modules) ]
452 {
453 # The brief docs for each module.
454 print.list-item $(module-name): $($(module-name).brief) ;
455 }
456 print.list-end ;
457 }
458 # The documentation for each module when details are requested.
459 if $(documented-modules) && $(.option.detailed)
460 {
461 for local module-name in [ sequence.insertion-sort $(documented-modules) ]
462 {
463 # The brief docs for each module.
464 print-help-module $(module-name) ;
465 }
466 }
467 }
468
469
470 # Generate documentation for a module. Basic information about the module is
471 # generated.
472 #
473 local rule print-help-module (
474 module-name # The module to generate docs for.
475 )
476 {
477 # Print the docs.
478 print.section "Module '$(module-name)'" $($(module-name).docs) ;
479
480 # Print out the documented classes.
481 print-help-module-section $(module-name) classes : "Module '$(module-name)' classes"
482 Use --help $(module-name).<class-name> to get more information. ;
483
484 # Print out the documented rules.
485 print-help-module-section $(module-name) rules : "Module '$(module-name)' rules"
486 Use --help $(module-name).<rule-name> to get more information. ;
487
488 # Print out the documented variables.
489 print-help-module-section $(module-name) variables : "Module '$(module-name)' variables"
490 Use --help $(module-name).<variable-name> to get more information. ;
491
492 # Print out all the same information but indetailed form.
493 if $(.option.detailed)
494 {
495 print-help-classes $(module-name) ;
496 print-help-rules $(module-name) ;
497 print-help-variables $(module-name) ;
498 }
499 }
500
501
502 # Generate documentation for a set of rules in a module.
503 #
504 local rule print-help-rules (
505 module-name # Module of the rules.
506 : name * # Optional list of rules to describe.
507 )
508 {
509 name ?= $($(module-name).rules) ;
510 if [ set.intersection $(name) : $($(module-name).rules) $($(module-name).class-rules) ]
511 {
512 # Print out the given rules.
513 for local rule-name in [ sequence.insertion-sort $(name) ]
514 {
515 if $(.option.show-locals) || ! $($(module-name).$(rule-name).is-local)
516 {
517 local signature = $($(module-name).$(rule-name).signature:J=" ") ;
518 signature ?= "" ;
519 print.section "Rule '$(module-name).$(rule-name) ( $(signature) )'"
520 $($(module-name).$(rule-name).docs) ;
521 if $($(module-name).$(rule-name).args)
522 {
523 print.list-start ;
524 for local arg-name in $($(module-name).$(rule-name).args)
525 {
526 print.list-item $(arg-name): $($(module-name).$(rule-name).args.$(arg-name).docs) ;
527 }
528 print.list-end ;
529 }
530 }
531 }
532 }
533 }
534
535
536 # Generate documentation for a set of classes in a module.
537 #
538 local rule print-help-classes (
539 module-name # Module of the classes.
540 : name * # Optional list of classes to describe.
541 )
542 {
543 name ?= $($(module-name).classes) ;
544 if [ set.intersection $(name) : $($(module-name).classes) ]
545 {
546 # Print out the given classes.
547 for local class-name in [ sequence.insertion-sort $(name) ]
548 {
549 if $(.option.show-locals) || ! $($(module-name).$(class-name).is-local)
550 {
551 local signature = $($(module-name).$(class-name).signature:J=" ") ;
552 signature ?= "" ;
553 print.section "Class '$(module-name).$(class-name) ( $(signature) )'"
554 $($(module-name).$(class-name).docs)
555 "Inherits from '"$($(module-name).$(class-name).super-name)"'." ;
556 if $($(module-name).$(class-name).args)
557 {
558 print.list-start ;
559 for local arg-name in $($(module-name).$(class-name).args)
560 {
561 print.list-item $(arg-name): $($(module-name).$(class-name).args.$(arg-name).docs) ;
562 }
563 print.list-end ;
564 }
565 }
566
567 # Print out the documented rules of the class.
568 print-help-module-section $(module-name) $(class-name).class-rules : "Class '$(module-name).$(class-name)' rules"
569 Use --help $(module-name).<rule-name> to get more information. ;
570
571 # Print out all the rules if details are requested.
572 if $(.option.detailed)
573 {
574 print-help-rules $(module-name) : $($(module-name).$(class-name).class-rules) ;
575 }
576 }
577 }
578 }
579
580
581 # Generate documentation for a set of variables in a module.
582 #
583 local rule print-help-variables (
584 module-name ? # Module of the variables.
585 : name * # Optional list of variables to describe.
586 )
587 {
588 name ?= $($(module-name).variables) ;
589 if [ set.intersection $(name) : $($(module-name).variables) ]
590 {
591 # Print out the given variables.
592 for local variable-name in [ sequence.insertion-sort $(name) ]
593 {
594 print.section "Variable '$(module-name).$(variable-name)'" $($(module-name).$(variable-name).docs) ;
595 if $($(module-name).$(variable-name).default) ||
596 $($(module-name).$(variable-name).initial)
597 {
598 print.list-start ;
599 if $($(module-name).$(variable-name).default)
600 {
601 print.list-item "default value:" '$($(module-name).$(variable-name).default:J=" ")' ;
602 }
603 if $($(module-name).$(variable-name).initial)
604 {
605 print.list-item "initial value:" '$($(module-name).$(variable-name).initial:J=" ")' ;
606 }
607 print.list-end ;
608 }
609 }
610 }
611 }
612
613
614 # Generate documentation for a project.
615 #
616 local rule print-help-project (
617 unused ?
618 : jamfile * # The project Jamfile.
619 )
620 {
621 if $(jamfile<$(jamfile)>.docs)
622 {
623 # Print the docs.
624 print.section "Project-specific help"
625 Project has jamfile at $(jamfile) ;
626
627 print.lines $(jamfile<$(jamfile)>.docs) "" ;
628 }
629 }
630
631
632 # Generate documentation for a config file.
633 #
634 local rule print-help-config (
635 unused ?
636 : type # The type of configuration file user or site.
637 config-file # The configuration Jamfile.
638 )
639 {
640 if $(jamfile<$(config-file)>.docs)
641 {
642 # Print the docs.
643 print.section "Configuration help"
644 Configuration file at $(config-file) ;
645
646 print.lines $(jamfile<$(config-file)>.docs) "" ;
647 }
648 }
649
650
651 ws = " " ;
652
653 # Extract the text from a block of comments.
654 #
655 local rule extract-comment (
656 var # The name of the variable to extract from.
657 )
658 {
659 local comment = ;
660 local line = $($(var)[1]) ;
661 local l = [ MATCH "^[$(ws)]*(#)(.*)$" : $(line) ] ;
662 while $(l[1]) && $($(var))
663 {
664 if $(l[2]) { comment += [ MATCH "^[$(ws)]?(.*)$" : $(l[2]) ] ; }
665 else { comment += "" ; }
666 $(var) = $($(var)[2-]) ;
667 line = $($(var)[1]) ;
668 l = [ MATCH "^[$(ws)]*(#)(.*)$" : $(line) ] ;
669 }
670 return $(comment) ;
671 }
672
673
674 # Extract s single line of Jam syntax, ignoring any comments.
675 #
676 local rule extract-syntax (
677 var # The name of the variable to extract from.
678 )
679 {
680 local syntax = ;
681 local line = $($(var)[1]) ;
682 while ! $(syntax) && ! [ MATCH "^[$(ws)]*(#)" : $(line) ] && $($(var))
683 {
684 local m = [ MATCH "^[$(ws)]*(.*)$" : $(line) ] ;
685 if $(m)
686 {
687 syntax = $(m) ;
688 }
689 $(var) = $($(var)[2-]) ;
690 line = $($(var)[1]) ;
691 }
692 return $(syntax) ;
693 }
694
695
696 # Extract the next token, this is either a single Jam construct or a comment as
697 # a single token.
698 #
699 local rule extract-token (
700 var # The name of the variable to extract from.
701 )
702 {
703 local parts = ;
704 while ! $(parts)
705 {
706 parts = [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]*(.*)" : $($(var)[1]) ] ;
707 if ! $(parts)
708 {
709 $(var) = $($(var)[2-]) ;
710 }
711 }
712 local token = ;
713 if [ MATCH "^(#)" : $(parts[1]) ]
714 {
715 token = $(parts:J=" ") ;
716 $(var) = $($(var)[2-]) ;
717 }
718 else
719 {
720 token = $(parts[1]) ;
721 $(var) = $(parts[2-]:J=" ") $($(var)[2-]) ;
722 }
723 return $(token) ;
724 }
725
726
727 # Scan for a rule declaration as the next item in the variable.
728 #
729 local rule scan-rule (
730 syntax ? # The first part of the text which contains the rule declaration.
731 : var # The name of the variable to extract from.
732 )
733 {
734 local rule-parts =
735 [ MATCH "^[$(ws)]*(rule|local[$(ws)]*rule)[$(ws)]+([^$(ws)]+)[$(ws)]*(.*)" : $(syntax:J=" ") ] ;
736 if $(rule-parts[1])
737 {
738 # Mark as doc for rule.
739 local rule-name = $(rule-parts[2]) ;
740 if $(scope-name)
741 {
742 rule-name = $(scope-name).$(rule-name) ;
743 }
744 local is-local = [ MATCH "^(local).*" : $(rule-parts[1]) ] ;
745 if $(comment-block)
746 {
747 set-rule-doc $(rule-name) $(module-name) $(is-local) : $(comment-block) ;
748 }
749 # Parse args of rule.
750 $(var) = $(rule-parts[3-]) $($(var)) ;
751 set-rule-arguments-signature $(rule-name) $(module-name) : [ scan-rule-arguments $(var) ] ;
752 # Scan within this rules scope.
753 local scope-level = [ extract-token $(var) ] ;
754 local scope-name = $(rule-name) ;
755 while $(scope-level) && $($(var))
756 {
757 local comment-block = [ extract-comment $(var) ] ;
758 local syntax-block = [ extract-syntax $(var) ] ;
759 if [ scan-rule $(syntax-block) : $(var) ]
760 {
761 }
762 else if [ MATCH "^(\\{)" : $(syntax-block) ]
763 {
764 scope-level += "{" ;
765 }
766 else if [ MATCH "^[^\\}]*([\\}])[$(ws)]*$" : $(syntax-block) ]
767 {
768 scope-level = $(scope-level[2-]) ;
769 }
770 }
771
772 return true ;
773 }
774 }
775
776
777 # Scan the arguments of a rule.
778 #
779 local rule scan-rule-arguments (
780 var # The name of the variable to extract from.
781 )
782 {
783 local arg-syntax = ;
784 local token = [ extract-token $(var) ] ;
785 while $(token) != "(" && $(token) != "{"
786 {
787 token = [ extract-token $(var) ] ;
788 }
789 if $(token) != "{"
790 {
791 token = [ extract-token $(var) ] ;
792 }
793 local arg-signature = ;
794 while $(token) != ")" && $(token) != "{"
795 {
796 local arg-name = ;
797 local arg-qualifier = " " ;
798 local arg-doc = ;
799 if $(token) = ":"
800 {
801 arg-signature += $(token) ;
802 token = [ extract-token $(var) ] ;
803 }
804 arg-name = $(token) ;
805 arg-signature += $(token) ;
806 token = [ extract-token $(var) ] ;
807 if [ MATCH "^([\\*\\+\\?])" : $(token) ]
808 {
809 arg-qualifier = $(token) ;
810 arg-signature += $(token) ;
811 token = [ extract-token $(var) ] ;
812 }
813 if $(token) = ":"
814 {
815 arg-signature += $(token) ;
816 token = [ extract-token $(var) ] ;
817 }
818 if [ MATCH "^(#)" : $(token) ]
819 {
820 $(var) = $(token) $($(var)) ;
821 arg-doc = [ extract-comment $(var) ] ;
822 token = [ extract-token $(var) ] ;
823 }
824 set-argument-doc $(arg-name) $(arg-qualifier) $(rule-name) $(module-name) : $(arg-doc) ;
825 }
826 while $(token) != "{"
827 {
828 token = [ extract-token $(var) ] ;
829 }
830 $(var) = "{" $($(var)) ;
831 arg-signature ?= "" ;
832 return $(arg-signature) ;
833 }
834
835
836 # Scan for a variable declaration.
837 #
838 local rule scan-variable (
839 syntax ? # The first part of the text which contains the variable declaration.
840 : var # The name of the variable to extract from.
841 )
842 {
843 # [1] = name, [2] = value(s)
844 local var-parts =
845 [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]+([\\?\\=]*)[$(ws)]+([^\\;]*)\\;" : $(syntax) ] ;
846 if $(var-parts)
847 {
848 local value = [ MATCH "^(.*)[ ]$" : $(var-parts[3-]:J=" ") ] ;
849 local default-value = "" ;
850 local initial-valie = "" ;
851 if $(var-parts[2]) = "?="
852 {
853 default-value = $(value) ;
854 default-value ?= "(empty)" ;
855 }
856 else
857 {
858 initial-value = $(value) ;
859 initial-value ?= "(empty)" ;
860 }
861 if $(comment-block)
862 {
863 set-variable-doc $(var-parts[1]) $(default-value) $(initial-value) $(module-name) : $(comment-block) ;
864 }
865 return true ;
866 }
867 }
868
869
870 # Scan a class declaration.
871 #
872 local rule scan-class (
873 syntax ? # The syntax text for the class declaration.
874 )
875 {
876 # [1] = class?, [2] = name, [3] = superclass
877 local class-parts =
878 [ MATCH "^[$(ws)]*([^$(ws)]+)[$(ws)]+([^$(ws)]+)[$(ws)]+:*[$(ws)]*([^$(ws);]*)" : $(syntax) ] ;
879 if $(class-parts[1]) = "class" || $(class-parts[1]) = "class.class"
880 {
881 set-class-doc $(class-parts[2]) $(module-name) : $(class-parts[3]) ;
882 }
883 }
884
885
886 # Scan a module file for documentation comments. This also invokes any actions
887 # assigned to the module. The actions are the rules that do the actual output of
888 # the documentation. This rule is invoked as the header scan rule for the module
889 # file.
890 #
891 rule scan-module (
892 target # The module file.
893 : text * # The text in the file, one item per line.
894 : action * # Rule to call to output docs for the module.
895 )
896 {
897 if $(.option.debug) { ECHO "HELP:" scanning module target '$(target)' ; }
898 local module-name = $(target:B) ;
899 local module-documented = ;
900 local comment-block = ;
901 local syntax-block = ;
902 # This is a hack because we can not get the line of a file if it happens to
903 # not have a new-line termination.
904 text += "}" ;
905 while $(text)
906 {
907 comment-block = [ extract-comment text ] ;
908 syntax-block = [ extract-syntax text ] ;
909 if $(.option.debug)
910 {
911 ECHO "HELP:" comment block; '$(comment-block)' ;
912 ECHO "HELP:" syntax block; '$(syntax-block)' ;
913 }
914 if [ scan-rule $(syntax-block) : text ] { }
915 else if [ scan-variable $(syntax-block) : text ] { }
916 else if [ scan-class $(syntax-block) ] { }
917 else if [ MATCH .*([cC]opyright).* : $(comment-block:J=" ") ]
918 {
919 # mark as the copy for the module.
920 set-module-copyright $(module-name) : $(comment-block) ;
921 }
922 else if $(action[1]) in "print-help-project" "print-help-config"
923 && ! $(jamfile<$(target)>.docs)
924 {
925 # special module docs for the project jamfile.
926 jamfile<$(target)>.docs = $(comment-block) ;
927 }
928 else if ! $(module-documented)
929 {
930 # document the module.
931 set-module-doc $(module-name) : $(comment-block) ;
932 module-documented = true ;
933 }
934 }
935 if $(action)
936 {
937 $(action[1]) $(module-name) : $(action[2-]) ;
938 }
939 }
940
941
942 # Import scan-module to global scope, so that it is available during header
943 # scanning phase.
944 #
945 IMPORT $(__name__) : scan-module : : doc.scan-module ;
946
947
948 # Read in a file using the SHELL builtin and return the individual lines as
949 # would be done for header scanning.
950 #
951 local rule read-file (
952 file # The file to read in.
953 )
954 {
955 file = [ path.native [ path.root [ path.make $(file) ] [ path.pwd ] ] ] ;
956 if ! $(.file<$(file)>.lines)
957 {
958 local content ;
959 switch [ modules.peek : OS ]
960 {
961 case NT :
962 content = [ SHELL "TYPE \"$(file)\"" ] ;
963
964 case * :
965 content = [ SHELL "cat \"$(file)\"" ] ;
966 }
967 local lines ;
968 local nl = "
969 " ;
970 local << = "([^$(nl)]*)[$(nl)](.*)" ;
971 local line+ = [ MATCH "$(<<)" : "$(content)" ] ;
972 while $(line+)
973 {
974 lines += $(line+[1]) ;
975 line+ = [ MATCH "$(<<)" : "$(line+[2])" ] ;
976 }
977 .file<$(file)>.lines = $(lines) ;
978 }
979 return $(.file<$(file)>.lines) ;
980 }
981
982
983 # Add a scan action to perform to generate the help documentation. The action
984 # rule is passed the name of the module as the first argument. The second
985 # argument(s) are optional and passed directly as specified here.
986 #
987 local rule do-scan (
988 modules + # The modules to scan and perform the action on.
989 : action * # The action rule, plus the secondary arguments to pass to the action rule.
990 )
991 {
992 if $(help-output) = text
993 {
994 print.output $(help-output-file).txt plain ;
995 ALWAYS $(help-output-file).txt ;
996 DEPENDS all : $(help-output-file).txt ;
997 }
998 if $(help-output) = html
999 {
1000 print.output $(help-output-file).html html ;
1001 ALWAYS $(help-output-file).html ;
1002 DEPENDS all : $(help-output-file).html ;
1003 }
1004 for local module-file in $(modules[1--2])
1005 {
1006 scan-module $(module-file) : [ read-file $(module-file) ] ;
1007 }
1008 scan-module $(modules[-1]) : [ read-file $(modules[-1]) ] : $(action) ;
1009 }