1# Copyright 2002, 2003, 2004, 2006 Vladimir Prus 2# Copyright 2008, 2012 Jurko Gospodnetic 3# Distributed under the Boost Software License, Version 1.0. 4# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 6import numbers ; 7 8 9# Mirror engine JAM_VERSION 10.major = "4" ; 11.minor = "4" ; 12 13 14rule boost-build ( ) 15{ 16 return "$(.major).$(.minor)-git" ; 17} 18 19 20rule print ( ) 21{ 22 if [ verify-engine-version ] 23 { 24 ECHO "B2" [ boost-build ] ; 25 } 26} 27 28 29rule verify-engine-version ( ) 30{ 31 local v = [ modules.peek : JAM_VERSION ] ; 32 33 if $(v[1]) != $(.major) || $(v[2]) != $(.minor) 34 { 35 local argv = [ modules.peek : ARGV ] ; 36 local e = $(argv[1]) ; 37 local l = [ modules.binding version ] ; 38 l = $(l:D) ; 39 l = $(l:D) ; 40 ECHO "warning: mismatched versions of B2 engine and core" ; 41 ECHO "warning: B2 engine ($(e)) is $(v:J=.)" ; 42 ECHO "warning: B2 core (at $(l)) is" [ boost-build ] ; 43 } 44 else 45 { 46 return true ; 47 } 48} 49 50 51# Utility rule for testing whether all elements in a sequence are equal to 0. 52# 53local rule is-all-zeroes ( sequence * ) 54{ 55 local result = "true" ; 56 for local e in $(sequence) 57 { 58 if $(e) != "0" 59 { 60 result = "" ; 61 } 62 } 63 return $(result) ; 64} 65 66 67# Returns "true" if the first version is less than the second one. 68# 69rule version-less ( lhs + : rhs + ) 70{ 71 numbers.check $(lhs) ; 72 numbers.check $(rhs) ; 73 74 local done ; 75 local result ; 76 77 while ! $(done) && $(lhs) && $(rhs) 78 { 79 if [ numbers.less $(lhs[1]) $(rhs[1]) ] 80 { 81 done = "true" ; 82 result = "true" ; 83 } 84 else if [ numbers.less $(rhs[1]) $(lhs[1]) ] 85 { 86 done = "true" ; 87 } 88 else 89 { 90 lhs = $(lhs[2-]) ; 91 rhs = $(rhs[2-]) ; 92 } 93 } 94 if ( ! $(done) && ! $(lhs) && ! [ is-all-zeroes $(rhs) ] ) 95 { 96 result = "true" ; 97 } 98 99 return $(result) ; 100} 101 102 103# Returns "true" if the current JAM version version is at least the given 104# version. 105# 106rule check-jam-version ( version + ) 107{ 108 local version-tag = $(version:J=.) ; 109 if ! $(version-tag) 110 { 111 import errors ; 112 errors.error Invalid version "specifier:" : $(version:E="(undefined)") ; 113 } 114 115 if ! $(.jam-version-check.$(version-tag))-is-defined 116 { 117 local jam-version = [ modules.peek : JAM_VERSION ] ; 118 if ! $(jam-version) 119 { 120 import errors ; 121 errors.error "Unable to deduce Boost Jam version. Your Boost Jam" 122 "installation is most likely terribly outdated." ; 123 } 124 .jam-version-check.$(version-tag) = "true" ; 125 if [ version-less [ modules.peek : JAM_VERSION ] : $(version) ] 126 { 127 .jam-version-check.$(version-tag) = "" ; 128 } 129 } 130 return $(.jam-version-check.$(version-tag)) ; 131} 132 133 134rule __test__ ( ) 135{ 136 import assert ; 137 138 local jam-version = [ modules.peek : JAM_VERSION ] ; 139 local future-version = $(jam-version) ; 140 future-version += "1" ; 141 142 assert.true check-jam-version $(jam-version) ; 143 assert.false check-jam-version $(future-version) ; 144 145 assert.true version-less 0 : 1 ; 146 assert.false version-less 0 : 0 ; 147 assert.true version-less 1 : 2 ; 148 assert.false version-less 1 : 1 ; 149 assert.false version-less 2 : 1 ; 150 assert.true version-less 3 1 20 : 3 4 10 ; 151 assert.false version-less 3 1 10 : 3 1 10 ; 152 assert.false version-less 3 4 10 : 3 1 20 ; 153 assert.true version-less 3 1 20 5 1 : 3 4 10 ; 154 assert.false version-less 3 1 10 5 1 : 3 1 10 ; 155 assert.false version-less 3 4 10 5 1 : 3 1 20 ; 156 assert.true version-less 3 1 20 : 3 4 10 5 1 ; 157 assert.true version-less 3 1 10 : 3 1 10 5 1 ; 158 assert.false version-less 3 4 10 : 3 1 20 5 1 ; 159 assert.false version-less 3 1 10 : 3 1 10 0 0 ; 160 assert.false version-less 3 1 10 0 0 : 3 1 10 ; 161 assert.false version-less 3 1 10 0 : 3 1 10 0 0 ; 162 assert.false version-less 3 1 10 0 : 03 1 10 0 0 ; 163 assert.false version-less 03 1 10 0 : 3 1 10 0 0 ; 164 165 # TODO: Add tests for invalid input data being sent to version-less. 166} 167