File: stage.jam

package info (click to toggle)
boost-build 2.0-m11-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,624 kB
  • ctags: 2,387
  • sloc: ansic: 12,978; python: 5,209; xml: 4,782; cpp: 555; yacc: 456; sh: 237; makefile: 71
file content (554 lines) | stat: -rw-r--r-- 19,080 bytes parent folder | download
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#  Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
#  distribute this software is granted provided this copyright notice appears in
#  all copies. This software is provided "as is" without express or implied
#  warranty, and with no claim as to its suitability for any purpose.

#  This module defines the 'install' rule, used to copy a set of targets to
#  a single location

import targets ;
import "class" : new ;
import property ;
import errors : error ;
import type : type ;
import type ;
import regex ;
import generators ;
import feature ;
import project ;
import property-set ;
import virtual-target ;
import path ;

feature.feature <install-dependencies> : off on : incidental ;
feature.feature <install-type> : : free incidental ;
feature.feature <install-source-root> : : free path  ;
feature.feature <so-version> : : free incidental ;

class install-target-class : basic-target
{
    import feature project type errors generators path stage ;    
    import "class" : new ;
    
    rule __init__ ( name-and-dir : project : sources * : requirements * : default-build * )
    {
        basic-target.__init__ $(name-and-dir) : $(project) : $(sources) : $(requirements) 
          : $(default-build) ;
    }

    # If <location> is not set, sets it based on the project data.
    rule update-location ( property-set )
    {
        local loc = [ $(property-set).get <location> ] ;
        if ! $(loc)
        {
            loc = [ path.root $(self.name) [ $(self.project).get location ] ] ;

            property-set = [ $(property-set).add-raw $(loc:G=<location>) ] ;
        }
        
        return $(property-set) ;
    }
            
    # Takes a target that is installed and property set which is
    # used when installing.
    rule adjust-properties ( target : build-property-set )
    {
        local ps-raw ;
        local a = [ $(target).action ] ;       
        if $(a)
        {
            local ps = [ $(a).properties ] ;
            ps-raw = [ $(ps).raw ] ;
                        
            # Unless <hardcode-dll-paths>true is in properties, which can
            # happen only if the user has explicitly requested it, nuke all
            # <dll-path> properties                                  
            if [ $(property-set).get <hardcode-dll-paths> ] != true
            {
                ps-raw = [ property.change $(ps-raw) : <dll-path> ] ;
            }
            
            # If any <dll-path> properties were specified for installing,
            # add them.
            local l = [ $(build-property-set).get <dll-path> ] ;
            ps-raw += $(l:G=<dll-path>) ;
            
            # Also copy <linkflags> feature from current build
            # set, to be used for relinking.
            local l = [ $(build-property-set).get <linkflags> ] ;
            ps-raw += $(l:G=<linkflags>) ;            
        }
        
        # Remove the <tag> feature on original targets.
        ps-raw = [ property.change $(ps-raw) : <tag> ] ;
        # And <location>. If stage target has another stage target
        # in sources, then we'll get virtual targets with <location>
        # property set.
        ps-raw = [ property.change $(ps-raw) : <location> ] ;
        
        
        local d = [ $(build-property-set).get <dependency> ] ;
        ps-raw += $(d:G=<dependency>) ;
        
        local d = [ $(build-property-set).get <location> ] ;
        ps-raw += $(d:G=<location>) ;
        
        local d = [ $(build-property-set).get <install-source-root> ] ;
        # Make the path absolute: we'll use it to compute relative
        # paths and making the path absolute will help.
        if $(d)
        {            
            d = [ path.root $(d) [ path.pwd ] ] ;
            ps-raw += $(d:G=<install-source-root>) ;
        }        
        
        if $(ps-raw)
        {
            return [ property-set.create $(ps-raw) ]  ;
        }        
        else
        {
            return [ property-set.empty ] ;
        }        
    }
    
        
    rule construct ( name : source-targets * : property-set )
    {                
        source-targets = [ 
          targets-to-stage $(source-targets) : $(property-set) ] ;
        
        property-set = [ update-location $(property-set) ] ;          
        
        local ename = [ $(property-set).get <name> ] ;              
                
        if $(ename) && $(source-targets[2])
        {
            errors.error 
              "When <name> property is used in 'install', only one source is allowed" ;
        }
        
                                       
        local result ;
        for local i in $(source-targets)
        {            
            local staged-targets ;
                        
            local new-properties = 
              [ adjust-properties $(i) : $(property-set) ] ;
                                    
            # See if something special should be done when staging this
            # type. It is indicated by presense of special "staged" type            
            local t = [ $(i).type ] ;            
            if $(t) && [ type.registered INSTALLED_$(t) ]
            {
                if $(ename)
                {
                    error.error "In 'install': <name> property specified with target that requires relinking" ;
                }
                else
                {
                    local targets = [ generators.construct $(self.project) $(name) : 
                      INSTALLED_$(t) : $(new-properties) : $(i) : * ] ;
                    staged-targets += $(targets[2-]) ;                                
                }                                                
            }
            else             
            {                
                staged-targets = [ stage.copy-file $(self.project) $(ename)
                  : $(i) : $(new-properties) ] ;
            }
            
            if ! $(staged-targets)
            {                    
                errors.error "Unable to generate staged version of " [ $(source).str ] ;
            }                
            
            for t in $(staged-targets) 
            {
                result += [ virtual-target.register $(t) ] ;          
            }            
        }
        
        return [ property-set.empty ] $(result) ;
    }   
    

    # Given the list of source targets explicitly passed to 'stage',
    # returns the list of targets which must be staged.
    rule targets-to-stage ( source-targets * : property-set )
    {   
        local result ;
               
        # Traverse the dependencies, if needed.
        if [ $(property-set).get <install-dependencies> ] = "on"
        {
            source-targets = [ collect-targets $(source-targets) ] ;
        }
        
        # Filter the target types, if needed
        local included-types = [ $(property-set).get <install-type> ] ;                               
        for local r in $(source-targets)
        {
            local ty = [ $(r).type ] ;        
            if $(ty)
            {
                # Don't stage searched libs.
                if $(ty) != SEARCHED_LIB
                {
                    if $(included-types)
                    {                        
                        if [ include-type $(ty) : $(included-types) ]
                        {
                            result += $(r) ;
                        }                                    
                    }                
                    else
                    {
                        result += $(r) ;                        
                    }   
                }                                
            }
            else if ! $(included-types)
            {
                # Don't install typeless target if there's
                # explicit list of allowed types.
                result += $(r) ;
            }                
        }
                
        return $(result) ;
    }
    
    # CONSIDER: figure out why we can't use virtual-target.traverse here.
    rule collect-targets ( targets * )
    {
        # Find subvariants
        local s ;        
        for local t in $(targets)
        {
            s += [ $(t).creating-subvariant ] ;
        }
        s = [ sequence.unique $(s) ] ;
        
        local result = $(targets) ;
        for local i in $(s)
        {
            result += [ $(i).all-referenced-targets ] ;
        }
        local result2 ;
        for local r in $(result)
        {
            if $(r:G) != <use>
            {
                result2 += $(r:G=) ;
            }            
        }        
        result = [ sequence.unique $(result2) ] ;        
    }
                
    # Returns true iff 'type' is subtype of some element of 'types-to-include'.
    local rule include-type ( type : types-to-include * )
    {
        local found ;
        while $(types-to-include) && ! $(found)
        {
            if [ type.is-subtype $(type) $(types-to-include[1]) ]
            {
                found = true ;
            }            
            types-to-include = $(types-to-include[2-]) ;
        }
        
        return $(found) ;
    }            
}

# Creates a copy of target 'source'. The 'properties' object should
# have a <location> property which specifies where the target must
# be placed.
rule copy-file ( project name ? : source : properties )
{   
    local targets ;
    name ?= [ $(source).name ] ;

    new-a = [ 
      new non-scanning-action $(source) : common.copy : $(properties) ] ;    
    local source-root = [ $(properties).get <install-source-root> ] ;
    if $(source-root) 
    {        
        # Get the real path of the target. We probably need to strip
        # relative path from the target name at construction...
        local path = [ $(source).path ] ;
        path = [ path.root $(name:D) $(path) ] ;
        # Make the path absolute. Otherwise, it's hard to compute relative
        # path. The 'source-root' is already absolute, see the
        # 'adjust-properties' method above.
        path = [ path.root $(path) [ path.pwd ] ] ;

        relative = [ path.relative-to $(source-root) $(path) ] ;
        
        targets = [ new file-target $(name:D=$(relative)) exact : [ $(source).type ] 
          : $(project) : $(new-a) ] ;
    }        
    else
    {
        targets = [ new file-target $(name:D=) exact : [ $(source).type ] 
          : $(project) : $(new-a) ] ;
    }
            
    return $(targets) ;
}

rule symlink ( name : project : source : properties )
{
    local a = [ new action $(source) : symlink.ln :
      $(properties) ] ;
    local targets = [ 
     new file-target $(name) exact : [ $(source).type ] : $(project) : $(a) ] ;
    
    return $(targets) ;
}

rule relink-file ( project : source : property-set  ) 
{                                
    local action = [ $(source).action ] ;
    local cloned-action = [ virtual-target.clone-action $(action) : $(project) :
      "" : $(property-set) ] ;
    local result = [ $(cloned-action).targets ] ;                        
    
    return $(result) ;
}

# Declare installed version of the EXE type. Generator for this type will
# cause relinking to the new location.
type.register INSTALLED_EXE : : EXE ;

class installed-exe-generator : generator
{
    import type property-set modules stage ;
    
    rule __init__ ( )
    {
        generator.__init__ install-exe : EXE : INSTALLED_EXE ;
    }
    
    rule run ( project name ? : property-set : source : multiple ? )
    {
        if [ $(property-set).get <os> ] in NT CYGWIN
        {
            # Relinking is never needed on NT
            return [ stage.copy-file $(project) 
              : $(source) : $(property-set) ] ; 
        }
        else 
        {
            return [ stage.relink-file $(project) 
              : $(source) : $(property-set) ] ;            
        }                
    }    
}

generators.register [ new installed-exe-generator ] ;


# Installing shared link on Unix might cause a creation of
# versioned symbolic links. 
type.register INSTALLED_SHARED_LIB : : SHARED_LIB ;
class installed-shared-lib-generator : generator
{
    import type property-set modules stage ;
    
    rule __init__ ( )
    {
        generator.__init__ install-shared-lib : SHARED_LIB
          : INSTALLED_SHARED_LIB ;
    }
    
    rule run ( project name ? : property-set : source : multiple ? )
    {                        
        if [ $(property-set).get <os> ] = NT
        {
            local copied = [ stage.copy-file $(project) 
              : $(source) : $(property-set) ] ; 
        
            copied = [ virtual-target.register $(copied) ] ;
            
            return $(copied) ;
        }
        else 
        {
            local a = [ $(source).action ] ;            
            local copied ;
            if ! $(a)
            {
                # Non-derived file, just copy.
                copied = [ stage.copy-file $(project) 
                  : $(source) : $(property-set) ] ; 
            }
            else
            {                            
                local cp = [ $(a).properties ] ;
                local current-dll-path = [ $(cp).get <dll-path> ] ;
                local new-dll-path = [ $(property-set).get <dll-path> ] ;
                                    
                if $(current-dll-path) != $(new-dll-path)
                {
                    # Rpath changed, need to relink.
                    copied = [ stage.relink-file 
                        $(project) : $(source) : $(property-set) ] ;
                }
                else
                {                                        
                    copied = [ stage.copy-file $(project) 
                      : $(source) : $(property-set) ] ; 
                }
            }
                                
            copied = [ virtual-target.register $(copied) ] ;
                                    
            local result = $(copied) ;
            # If the name is in the form NNN.XXX.YYY.ZZZ, where all
            # 'X', 'Y' and 'Z' are numbers, we need to create
            # NNN.XXX and NNN.XXX.YYY symbolic links.
            local m = [ MATCH (.*)\\.([0123456789]+)\\.([0123456789]+)\\.([0123456789]+)$ 
              : [ $(copied).name ] ] ;
            if $(m)
            {
                result += [ stage.symlink $(m[1]).$(m[2]) : $(project)
                  : $(copied) : $(property-set) ] ;
                result += [ stage.symlink $(m[1]).$(m[2]).$(m[3])  : $(project)
                  : $(copied) : $(property-set) ] ;
            }
                                    
            return $(result) ;
        }                
    }    
}

generators.register [ new installed-shared-lib-generator ] ;



# Main target rule for 'install'
rule install ( name : sources * : requirements * : default-build * )
{
    local project = [ project.current ] ;
    
    # Unless the user has explicitly asked us to hardcode dll paths, add
    # <hardcode-dll-paths>false in requirements, to override default
    # value.
    if ! <hardcode-dll-paths>true in $(requirements)
    {
        requirements += <hardcode-dll-paths>false ;
    }        
        
    if <tag> in $(requirements:G)
    {
        errors.user-error 
          "The <tag> property is not allowed for the 'install' rule" ;
    }
           
    targets.main-target-alternative
      [ new install-target-class $(name) : $(project) 
        : [ targets.main-target-sources $(sources) : $(name) ]
        : [ targets.main-target-requirements $(requirements) : $(project) ] 
        : [ targets.main-target-default-build $(default-build) : $(project) ] 
      ] ;
}

IMPORT $(__name__) : install : : install ;
IMPORT $(__name__) : install : : stage ;

rule add-variant-and-compiler ( name : type ? : property-set )
{
    return [ rename $(name) : $(type) : $(property-set) ] ;
}

rule add-variant ( name : type ? : property-set )
{
    return [ rename $(name) : $(type) : $(property-set) : unversioned ] ;
}

rule rename ( name : type ? : property-set : unversioned ? )
{    
    if [ type.is-derived $(type) LIB ]
    {            
        local properties = [ $(property-set).raw ] ;
    
        local tags = ;
    
        local thread-tag ;
        if <threading>multi in $(properties) { thread-tag = mt ; }
        
        local runtime-tag = ;
        if <runtime-link>static in $(properties) { runtime-tag += s ; }
        if <runtime-debugging>on in $(properties) { runtime-tag += g ; }
        
        if <variant>debug-python in $(properties) { runtime-tag += y ; }
        if <variant>debug in $(properties) { runtime-tag += d ; }
        if <stdlib>stlport in $(properties) { runtime-tag += p ; }
        if <stdlib-stlport:iostream>hostios in $(properties) { runtime-tag += n ; }
        
        local toolset-tag = ;
        # 'unversioned' should be a parameter.
        if ! $(unversioned)
        {
            switch [ $(property-set).get <toolset> ]
            {
                case borland* : toolset-tag += bcb ;
                case como* : toolset-tag += como ;
                case cw : toolset-tag += cw ;
                case darwin* : toolset-tag += ;
                case edg* : toolset-tag += edg ;
                case gcc* : toolset-tag += gcc ;
                case intel-linux* : toolset-tag += il ;
                case intel-win* : toolset-tag += iw ;
                case kcc* : toolset-tag += kcc ;
                case kylix* : toolset-tag += bck ;
                #case metrowerks* : toolset-tag += cw ;
                #case mingw* : toolset-tag += mgw ;
                case mipspro* : toolset-tag += mp ;
                case msvc* : toolset-tag += vc ;
                case sun* : toolset-tag += sw ;
                case tru64cxx* : toolset-tag += tru ;
                case vacpp* : toolset-tag += xlc ;
            }
            local version = [ MATCH "<toolset.*version>([0123456789]+)[.]([0123456789]*)" : $(properties) ] ;
            toolset-tag += $(version) ;
        }

        # Note yet clear if this should be added on Linux (where we have
        # version in soname) and how it should be done on Windows.
        #local version-tag = ;
        #if ! $(gUNVERSIONED_VARIANT_TAG)
        #{
        #    local version-number = [ get-values <version> : $(properties) ] ;
        #    version-number ?= $(BOOST_VERSION) ;
        #    version-tag = [ MATCH "^([^.]+)[.]([^.]+)" : $(version-number[1]) ] ;
        #    version-tag = $(version-tag:J="_") ;
        #}
    
        tags += $(toolset-tag:J=) ;
        tags += $(thread-tag:J=) ;
        tags += $(runtime-tag:J=) ;
        #tags += $(version-tag) ;
    
        local result ;
        
        if $(tags)
        {
            result = $(name)-$(tags:J=-) ;
        }
        else
        {
            result = $(name) ;
        }
        return [ virtual-target.add-prefix-and-suffix $(result) : $(type) 
          : $(property-set) ] ;
    }    
}