summaryrefslogtreecommitdiff
path: root/tools/build/v2/build/version.jam
blob: d4b787d6d3962daf0237c95c2aaac39ef62ee1d4 (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
# Copyright 2002, 2003, 2004, 2006 Vladimir Prus
# Copyright 2008, 2012 Jurko Gospodnetic
# 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)

import numbers ;


.major = "2011" ;
.minor = "12" ;


rule boost-build ( )
{
    return "$(.major).$(.minor)-svn" ;
}


rule print ( )
{
    if [ verify-engine-version ]
    {        
        ECHO "Boost.Build" [ boost-build ] ;
    }    
}


rule verify-engine-version ( )
{
    local v = [ modules.peek : JAM_VERSION ] ;
    
    if $(v[1]) != $(.major) || $(v[2]) != $(.minor)
    {
        local argv = [ modules.peek : ARGV ] ;
        local e = $(argv[1]) ;
        local l = [ modules.binding version ] ;
        l = $(l:D) ;
        l = $(l:D) ;
        ECHO "warning: mismatched versions of Boost.Build engine and core" ;
        ECHO "warning: Boost.Build engine ($(e)) is $(v:J=.)" ;
        ECHO "warning: Boost.Build core (at $(l)) is" [ boost-build ] ;
    }
    else
    {
        return true ;
    }    
}


# Utility rule for testing whether all elements in a sequence are equal to 0.
#
local rule is-all-zeroes ( sequence * )
{
    local result = "true" ;
    for local e in $(sequence)
    {
        if $(e) != "0"
        {
            result = "" ;
        }
    }
    return $(result) ;
}


# Returns "true" if the first version is less than the second one.
#
rule version-less ( lhs + : rhs + )
{
    numbers.check $(lhs) ;
    numbers.check $(rhs) ;

    local done ;
    local result ;

    while ! $(done) && $(lhs) && $(rhs)
    {
        if [ numbers.less $(lhs[1]) $(rhs[1]) ]
        {
            done = "true" ;
            result = "true" ;
        }
        else if [ numbers.less $(rhs[1]) $(lhs[1])  ]
        {
            done = "true" ;
        }
        else
        {
            lhs = $(lhs[2-]) ;
            rhs = $(rhs[2-]) ;
        }
    }
    if ( ! $(done) && ! $(lhs) && ! [ is-all-zeroes $(rhs) ] )
    {
        result = "true" ;
    }
    
    return $(result) ;
}


# Returns "true" if the current JAM version version is at least the given
# version.
#
rule check-jam-version ( version + )
{
    local version-tag = $(version:J=.) ;
    if ! $(version-tag)
    {
        import errors ;
        errors.error Invalid version specifier: : $(version:E="(undefined)") ;
    }

    if ! $(.jam-version-check.$(version-tag))-is-defined
    {
        local jam-version = [ modules.peek : JAM_VERSION ] ;
        if ! $(jam-version)
        {
            import errors ;
            errors.error "Unable to deduce Boost Jam version. Your Boost Jam"
                "installation is most likely terribly outdated." ;
        }
        .jam-version-check.$(version-tag) = "true" ;
        if [ version-less [ modules.peek : JAM_VERSION ] : $(version) ]
        {
            .jam-version-check.$(version-tag) = "" ;
        }
    }
    return $(.jam-version-check.$(version-tag)) ;
}


rule __test__ ( )
{
    import assert ;
    
    local jam-version = [ modules.peek : JAM_VERSION ] ;
    local future-version = $(jam-version) ;
    future-version += "1" ;

    assert.true  check-jam-version $(jam-version)    ;
    assert.false check-jam-version $(future-version) ;

    assert.true  version-less  0          :  1          ;
    assert.false version-less  0          :  0          ;
    assert.true  version-less  1          :  2          ;
    assert.false version-less  1          :  1          ;
    assert.false version-less  2          :  1          ;
    assert.true  version-less  3 1 20     :  3 4 10     ;
    assert.false version-less  3 1 10     :  3 1 10     ;
    assert.false version-less  3 4 10     :  3 1 20     ;
    assert.true  version-less  3 1 20 5 1 :  3 4 10     ;
    assert.false version-less  3 1 10 5 1 :  3 1 10     ;
    assert.false version-less  3 4 10 5 1 :  3 1 20     ;
    assert.true  version-less  3 1 20     :  3 4 10 5 1 ;
    assert.true  version-less  3 1 10     :  3 1 10 5 1 ;
    assert.false version-less  3 4 10     :  3 1 20 5 1 ;
    assert.false version-less  3 1 10     :  3 1 10 0 0 ;
    assert.false version-less  3 1 10 0 0 :  3 1 10     ;
    assert.false version-less  3 1 10 0   :  3 1 10 0 0 ;
    assert.false version-less  3 1 10 0   : 03 1 10 0 0 ;
    assert.false version-less 03 1 10 0   :  3 1 10 0 0 ;

    # TODO: Add tests for invalid input data being sent to version-less.
}