summaryrefslogtreecommitdiff
path: root/tools/build/v2/options/help.jam
blob: b507e1edd67159f00350d6bcc5837e0d41b3ac7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright 2003 Dave Abrahams 
# Copyright 2003, 2006 Rene Rivera 
# Copyright 2003, 2006 Vladimir Prus 
# Distributed under the Boost Software License, Version 1.0. 
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 

# This module is the plug-in handler for the --help and --help-.*
# command-line options
import modules ;
import assert ;
import doc : do-scan set-option set-output set-output-file print-help-usage print-help-top ;
import sequence ;
import set ;
import project ;
import print ;
import os ;
import version ;
import path ;

# List of possible modules, but which really aren't.
#
.not-modules =
    boost-build bootstrap site-config test user-config
    -tools allyourbase boost-base features python stlport testing unit-tests ;

# The help system options are parsed here and handed off to the doc
# module to translate into documentation requests and actions. The
# understood options are:
#
#    --help-disable-<option>
#    --help-doc-options
#    --help-enable-<option>
#    --help-internal
#    --help-options
#    --help-usage
#    --help-output <type>
#    --help-output-file <file>
#    --help [<module-or-class>]
#
rule process (
    command # The option.
    : values * # The values, starting after the "=".
    )
{
    assert.result --help : MATCH ^(--help).* : $(command) ;
    local did-help = ;
    switch $(command)
    {
        case --help-internal :
        local path-to-modules = [ modules.peek : BOOST_BUILD_PATH ] ;
        path-to-modules ?= . ;
        local possible-modules = [ GLOB $(path-to-modules) : *\\.jam ] ;
        local not-modules = [ GLOB $(path-to-modules) : *$(.not-modules)\\.jam ] ;
        local modules-to-list =
            [ sequence.insertion-sort
                [ set.difference $(possible-modules:D=:S=) : $(not-modules:D=:S=) ] ] ;
        local modules-to-scan ;
        for local m in $(modules-to-list)
        {
            local module-files = [ GLOB $(path-to-modules) : $(m)\\.jam ] ;
            modules-to-scan += $(module-files[1]) ;
        }
        do-scan $(modules-to-scan) : print-help-all ;
        did-help = true ;

        case --help-enable-* :
        local option = [ MATCH --help-enable-(.*) : $(command) ] ; option = $(option:L) ;
        set-option $(option) : enabled ;
        did-help = true ;

        case --help-disable-* :
        local option = [ MATCH --help-disable-(.*) : $(command) ] ; option = $(option:L) ;
        set-option $(option) ;
        did-help = true ;

        case --help-output :
        set-output $(values[1]) ;
        did-help = true ;

        case --help-output-file :
        set-output-file $(values[1]) ;
        did-help = true ;

        case --help-doc-options :
        local doc-module-spec = [ split-symbol doc ] ;
        do-scan $(doc-module-spec[1]) : print-help-options ;
        did-help = true ;

        case --help-options :
        print-help-usage ;
        did-help = true ;

        case --help :
        local spec = $(values[1]) ;
        if $(spec)
        {
            local spec-parts = [ split-symbol $(spec) ] ;
            if $(spec-parts)
            {
                if $(spec-parts[2])
                {
                    do-scan $(spec-parts[1]) : print-help-classes $(spec-parts[2]) ;
                    do-scan $(spec-parts[1]) : print-help-rules $(spec-parts[2]) ;
                    do-scan $(spec-parts[1]) : print-help-variables $(spec-parts[2]) ;
                }
                else
                {
                    do-scan $(spec-parts[1]) : print-help-module ;
                }
            }
            else
            {
                EXIT "Unrecognized help option '"$(command)" "$(spec)"'." ;
            }
        }
        else
        {
            version.print ;
            ECHO ;
            # First print documentation from the current Jamfile, if any.            
            # FIXME: Generally, this duplication of project.jam logic is bad.
            local names = [ modules.peek project : JAMROOT ]
              [ modules.peek project : JAMFILE ] ;
            local project-file = [ path.glob . : $(names) ] ;
            if ! $(project-file)
            {
                project-file = [ path.glob-in-parents . : $(names) ] ;
            }
            
            for local p in $(project-file)
            {
                do-scan $(p) : print-help-project $(p) ;
            }
            
            # Next any user-config help.
            local user-path = [ os.home-directories ] [ os.environ BOOST_BUILD_PATH ] ;
            local user-config = [ GLOB $(user-path) : user-config.jam ] ;
            if $(user-config)
            {
                do-scan $(user-config[1]) : print-help-config user $(user-config[1]) ;
            }
            
            # Next any site-config help.
            local site-config = [ GLOB $(user-path) : site-config.jam ] ;
            if $(site-config)
            {
                do-scan $(site-config[1]) : print-help-config site $(site-config[1]) ;
            }

            # Then the overall help.
            print-help-top ;
        }
        did-help = true ;
    }
    if $(did-help)
    {
        UPDATE all ;
        NOCARE all ;
    }
    return $(did-help) ;
}

# Split a reference to a symbol into module and symbol parts.
#
local rule split-symbol (
    symbol # The symbol to split.
    )
{
    local path-to-modules = [ modules.peek : BOOST_BUILD_PATH ] ;
    path-to-modules ?= . ;
    local module-name = $(symbol) ;
    local symbol-name = ;
    local result = ;
    while ! $(result)
    {
        local module-path = [ GLOB $(path-to-modules) : $(module-name)\\.jam ] ;
        if $(module-path)
        {
            # The 'module-name' in fact refers to module. Return the full
            # module path and a symbol within it. If 'symbol' passed to this
            # rule is already module, 'symbol-name' will be empty. Otherwise,
            # it's initialized on the previous loop iteration.
            # In case there are several modules by this name,
            # use the first one.
            result = $(module-path[1]) $(symbol-name) ;
        }
        else
        {
            if ! $(module-name:S)
            {
                result = - ;
            }
            else
            {
                local next-symbol-part = [ MATCH ^.(.*) : $(module-name:S) ] ;
                if $(symbol-name)
                {
                    symbol-name = $(next-symbol-part).$(symbol-name) ;
                }
                else
                {
                    symbol-name = $(next-symbol-part) ;
                }
                module-name = $(module-name:B) ;
            }
        }
    }
    if $(result) != -
    {
        return $(result) ;
    }
}