summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/test/flags.py
blob: 3a12c94d952d3b011c99b9405936e93eff8e3d51 (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
#!/usr/bin/python

# Copyright (C) Steven Watanabe 2018
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE.txt or copy at
# https://www.bfgroup.xyz/b2/LICENSE.txt)

# Tests the check-has-flag rule

import BoostBuild

t = BoostBuild.Tester(use_test_config=False)

# We need an object file before we can run the actual test.
t.write('input.cpp', 'void f() {}\n')
t.write('Jamroot.jam', 'obj input : input.cpp ;')
t.run_build_system()

linker_input = t.glob_file('bin/$toolset/debug*/input.obj')

# Check every possible result of pass or fail.
t.write('Jamroot.jam', '''
import flags ;
import modules ;
OBJECT_FILE = [ modules.peek : OBJECT_FILE ] ;
obj fail_cpp : test.cpp : [ check-has-flag <cxxflags>--illegal-flag-cpp
                            : <define>ERROR : <define>OK ] ;
obj pass_cpp : test.cpp : [ check-has-flag <cxxflags>-DMACRO_CPP
                            : <define>OK : <define>ERROR ] ;
obj fail_c : test.cpp : [ check-has-flag <cflags>--illegal-flag-c
                         : <define>ERROR : <define>OK ] ;
obj pass_c : test.cpp : [ check-has-flag <cflags>-DMACRO_C
                          : <define>OK : <define>ERROR ] ;
obj fail_link : test.cpp : [ check-has-flag <linkflags>--illegal-flag-link
                             : <define>ERROR : <define>OK ] ;
# The only thing that we can be certain the linker
# will accept is the name of an object file.
obj pass_link : test.cpp : [ check-has-flag <linkflags>$(OBJECT_FILE)
                             : <define>OK : <define>ERROR ] ;
''')

t.write('test.cpp', '''
#ifdef ERROR
#error ERROR defined
#endif
#ifndef OK
#error ERROR not defined
#endif
''')

# Don't check the status immediately, so that we have a chance
# to print config.log.  Also, we need a minimum of d2 to make
# sure that we always see the commands and output.
t.run_build_system(['-sOBJECT_FILE=' + linker_input, '-d2'], status=None)

if t.status != 0:
    log_file = t.read('bin/config.log')
    BoostBuild.annotation("config.log", log_file)
    t.fail_test(True)

t.expect_output_lines(['    - has --illegal-flag-cpp   : no*',
                       '    - has -DMACRO_CPP          : yes*',
                       '    - has --illegal-flag-c     : no*',
                       '    - has -DMACRO_C            : yes*',
                       '    - has --illegal-flag-link  : no*',
                       '    - has *bin*/input.* : yes*'])
t.expect_addition('bin/$toolset/debug*/fail_cpp.obj')
t.expect_addition('bin/$toolset/debug*/pass_cpp.obj')
t.expect_addition('bin/$toolset/debug*/fail_c.obj')
t.expect_addition('bin/$toolset/debug*/pass_c.obj')
t.expect_addition('bin/$toolset/debug*/fail_link.obj')
t.expect_addition('bin/$toolset/debug*/pass_link.obj')

t.cleanup()