Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / test / startup_v2.py
1 #!/usr/bin/python
2
3 # Copyright 2002 Dave Abrahams
4 # Copyright 2003, 2004 Vladimir Prus
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7
8 import BoostBuild
9 import os.path
10 import re
11
12
13 def check_for_existing_boost_build_jam(t):
14     """
15       This test depends on no boost-build.jam file existing in any of the
16     folders along the current folder's path. If it does exist, not only would
17     this test fail but it could point to a completely wrong Boost Build
18     installation, thus causing headaches when attempting to diagnose the
19     problem. That is why we explicitly check for this scenario.
20
21     """
22     problem = find_up_to_root(t.workdir, "boost-build.jam")
23     if problem:
24         BoostBuild.annotation("misconfiguration", """\
25 This test expects to be run from a folder with no 'boost-build.jam' file in any
26 of the folders along its path.
27
28 Working folder:
29   '%s'
30
31 Problematic boost-build.jam found at:
32   '%s'
33
34 Please remove this file or change the test's working folder and rerun the test.
35 """ % (t.workdir, problem))
36         t.fail_test(1, dump_stdio=False, dump_stack=False)
37
38
39 def find_up_to_root(folder, name):
40     last = ""
41     while last != folder:
42         candidate = os.path.join(folder, name)
43         if os.path.exists(candidate):
44             return candidate
45         last = folder
46         folder = os.path.dirname(folder)
47
48
49 def match_re(actual, expected):
50     return re.match(expected, actual, re.DOTALL) != None
51
52
53 t = BoostBuild.Tester(match=match_re, boost_build_path="", pass_toolset=0)
54 t.set_tree("startup")
55 check_for_existing_boost_build_jam(t)
56
57 t.run_build_system(status=1, stdout=
58 r"""Unable to load Boost\.Build: could not find "boost-build\.jam"
59 .*Attempted search from .* up to the root""")
60
61 t.run_build_system(status=1, subdir="no-bootstrap1",
62     stdout=r"Unable to load Boost\.Build: could not find build system\."
63     r".*attempted to load the build system by invoking"
64     r".*'boost-build ;'"
65     r'.*but we were unable to find "bootstrap\.jam"')
66
67 # Descend to a subdirectory which /does not/ contain a boost-build.jam file,
68 # and try again to test the crawl-up behavior.
69 t.run_build_system(status=1, subdir=os.path.join("no-bootstrap1", "subdir"),
70     stdout=r"Unable to load Boost\.Build: could not find build system\."
71     r".*attempted to load the build system by invoking"
72     r".*'boost-build ;'"
73     r'.*but we were unable to find "bootstrap\.jam"')
74
75 t.run_build_system(status=1, subdir="no-bootstrap2",
76     stdout=r"Unable to load Boost\.Build: could not find build system\."
77     r".*attempted to load the build system by invoking"
78     r".*'boost-build \. ;'"
79     r'.*but we were unable to find "bootstrap\.jam"')
80
81 t.run_build_system(status=1, subdir='no-bootstrap3', stdout=
82 r"""Unable to load Boost.Build
83 .*boost-build\.jam" was found.*
84 However, it failed to call the "boost-build" rule""")
85
86 # Test bootstrapping based on BOOST_BUILD_PATH.
87 t.run_build_system(["-sBOOST_BUILD_PATH=../boost-root/build"],
88     subdir="bootstrap-env", stdout="build system bootstrapped")
89
90 # Test bootstrapping based on an explicit path in boost-build.jam.
91 t.run_build_system(subdir="bootstrap-explicit",
92     stdout="build system bootstrapped")
93
94 t.cleanup()