summaryrefslogtreecommitdiff
path: root/tools/build/v2/build/configure.jam
blob: 66b81b3498e5b8ea99168e9b8c74adf1c4592e42 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright (c) 2010 Vladimir Prus.
#
# Use, modification and distribution is subject to 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 defines function to help with two main tasks:
#
# - Discovering build-time configuration for the purposes of adjusting the build
#   process.
# - Reporting what is built, and how it is configured.

import "class" : new ;
import common ;
import path ;
import property ;
import property-set ;
import targets ;
import config-cache ;


rule log-summary ( )
{
}


.width = 30 ;

rule set-width ( width )
{
    .width = $(width) ;
}


# Declare that the components specified by the parameter exist.
#
rule register-components ( components * )
{
    .components += $(components) ;
}


# Declare that the components specified by the parameters will be built.
#
rule components-building ( components * )
{
    .built-components += $(components) ;
}


# Report something about component configuration that the user should better
# know.
#
rule log-component-configuration ( component : message )
{
    # FIXME: Implement per-property-set logs.
    .component-logs.$(component) += $(message) ;
}


rule log-check-result ( result )
{
    if ! $(.announced-checks)
    {
        ECHO "Performing configuration checks\n" ;
        .announced-checks = 1 ;
    }

    ECHO $(result) ;
    # FIXME: Unfinished code. Nothing seems to set .check-results at the moment.
    #.check-results += $(result) ;
}


rule log-library-search-result ( library : result )
{
    local x = [ PAD "    - $(library)" : $(.width) ] ;
    log-check-result "$(x) : $(result)" ;
}


rule print-component-configuration ( )
{
    # FIXME: See what was intended with this initial assignment.
    # local c = [ sequence.unique $(.components) ] ;

    ECHO "\nComponent configuration:\n" ;
    local c ;
    for c in $(.components)
    {
        local s ;
        if $(c) in $(.built-components)
        {
            s = "building" ;
        }
        else
        {
            s = "not building" ;
        }
        ECHO [ PAD "    - $(c)" : $(.width) ] ": $(s)" ;
        for local m in $(.component-logs.$(c))
        {
            ECHO "        -" $(m) ;
        }
    }
    ECHO ;
}


rule print-configure-checks-summary ( )
{
    # FIXME: The problem with this approach is that the user sees the checks
    # summary when all checks are done, and has no progress reporting while the
    # checks are being executed.
    if $(.check-results)
    {
        ECHO "Configuration checks summary\n" ;
        for local r in $(.check-results)
        {
            ECHO $(r) ;
        }
        ECHO ;
    }
}


# Attempt to build a metatarget named by 'metatarget-reference' in context of
# 'project' with properties 'ps'. Returns non-empty value if build is OK.
#
rule builds-raw ( metatarget-reference : project : ps : what : retry ? )
{
    local result ;

    if ! $(retry) && ! $(.$(what)-tested.$(ps))
    {
        .$(what)-tested.$(ps) = true ;

        local cache-name = $(what) [ $(ps).raw ] ;
        cache-name = $(cache-name:J=-) ;
        local value = [ config-cache.get $(cache-name) ] ;
        
        local targets = [ targets.generate-from-reference 
            $(metatarget-reference) : $(project) : $(ps) ] ;

        local jam-targets ;
        for local t in $(targets[2-])
        {
            jam-targets += [ $(t).actualize ] ;
        }
             
        if $(value)
        {
            local x = [ PAD "    - $(what)" : $(.width) ] ; 
            if $(value) = true
            {
                .$(what)-supported.$(ps) = yes ;
                result = true ;
                log-check-result "$(x) : yes (cached)" ;
            }
            else
            {
                log-check-result "$(x) : no  (cached)" ;
            }
        }       
        else if ! UPDATE_NOW in [ RULENAMES ]
        {
            # Cannot determine. Assume existance.
        }
        else
        {
            local x = [ PAD "    - $(what)" : $(.width) ] ;
            if [ UPDATE_NOW $(jam-targets) :
                 $(.log-fd) : ignore-minus-n : ignore-minus-q ]
            {
                .$(what)-supported.$(ps) = yes ;
                result = true ;
                log-check-result "$(x) : yes" ;
            }
            else
            {
                log-check-result "$(x) : no" ;
            }
        }
        if ! $(value)
        {
            if $(result)
            {
                config-cache.set $(cache-name) : true ;
            }
            else
            {
                config-cache.set $(cache-name) : false ;
            }
        }        
        return $(result) ;
    }
    else
    {
        return $(.$(what)-supported.$(ps)) ;
    }
}

rule builds ( metatarget-reference : properties * : what ? : retry ? )
{
    # FIXME: This should not be hardcoded. Other checks might want to consider a
    # different set of features as relevant.
    local toolset = [ property.select <toolset> : $(properties) ] ;
    local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
    local relevant = [ property.select <target-os> <toolset>
        $(toolset-version-property) <address-model> <architecture> :
        $(properties) ] ;
    local ps = [ property-set.create $(relevant) ] ;
    local t = [ targets.current ] ;
    local p = [ $(t).project ] ;

    if ! $(what)
    {
        local resolved = [ targets.resolve-reference $(metatarget-reference) : $(p) ] ;
        local name = [ $(resolved[1]).name ] ;
        what = "$(name) builds" ;
    }

    return [ builds-raw $(metatarget-reference) : $(p) : $(ps) : $(what) :
        $(retry) ] ;
}


# Called by Boost.Build startup code to specify the file to receive the
# configuration check results. Should never be called by user code.
#
rule set-log-file ( log-file )
{
    path.makedirs [ path.parent $(log-file) ] ;
    .log-fd = [ FILE_OPEN $(log-file) : "w" ] ;
}


# Frontend rules

class check-target-builds-worker
{
    import configure ;
    import property-set ;
    import targets ;
    import property ;

    rule __init__ ( target message ? : true-properties * : false-properties * )
    {
        self.target = $(target) ;
        self.message = $(message) ;
        self.true-properties = $(true-properties) ;
        self.false-properties = $(false-properties) ;
    }

    rule check ( properties * )
    {
        local choosen ;
        if [ configure.builds $(self.target) : $(properties) : $(self.message) ]
        {
            choosen = $(self.true-properties) ;
        }
        else
        {
            choosen = $(self.false-properties) ;
        }
        return [ property.evaluate-conditionals-in-context $(choosen) :
            $(properties) ] ;
    }
}


rule check-target-builds ( target message ? : true-properties * :
    false-properties * )
{
    local instance = [ new check-target-builds-worker $(target) $(message) :
        $(true-properties) : $(false-properties) ] ;
    return <conditional>@$(instance).check ;
}


IMPORT $(__name__) : check-target-builds :  : check-target-builds ;