summaryrefslogtreecommitdiff
path: root/tools/build/test/generator_selection.py
blob: 87f0df33a987f8163edb7e47fe332e81159a15e1 (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
#!/usr/bin/python

# Copyright 2008, 2012 Jurko Gospodnetic
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

# Tests that generators get selected correctly.
#
# We do not use the internal C++-compiler CPP --> OBJ generator to avoid
# problems with specific compilers or their configurations, e.g. IBM's AIX test
# runner 'AIX Version 5.3 TL7 SP5 (5300-07-05-0831)' using the 'IBM XL C/C++
# for AIX, V12.1 (Version: 12.01.0000.0000)' reporting errors when run with a
# source file whose suffix is not '.cpp'.

import BoostBuild


###############################################################################
#
# test_generator_added_after_already_building_a_target_of_its_target_type()
# -------------------------------------------------------------------------
#
###############################################################################

def test_generator_added_after_already_building_a_target_of_its_target_type():
    """
      Regression test for a Boost Build bug causing it to not use a generator
    if it got added after already building a target of its target type.

    """
    t = BoostBuild.Tester()

    t.write("dummy.cpp", "void f() {}\n")

    t.write("jamroot.jam", """\
import common ;
import generators ;
import type ;
type.register MY_OBJ : my_obj ;
generators.register-standard common.copy : CPP : MY_OBJ ;

# Building this dummy target must not cause a later defined CPP target type
# generator not to be recognized as viable.
my-obj dummy : dummy.cpp ;
alias the-other-obj : Other//other-obj ;
""")

    t.write("Other/source.extension", "A dummy source file.")

    t.write("Other/mygen.jam", """\
import common ;
import generators ;
import type ;
type.register MY_TYPE : extension ;
generators.register-standard $(__name__).generate-a-cpp-file : MY_TYPE : CPP ;
rule generate-a-cpp-file { ECHO Generating a CPP file... ; }
CREATE-FILE = [ common.file-creation-command ] ;
actions generate-a-cpp-file { $(CREATE-FILE) "$(<)" }
""")

    t.write("Other/mygen.py", """\
import b2.build.generators as generators
import b2.build.type as type

from b2.manager import get_manager

import os

type.register('MY_TYPE', ['extension'])
generators.register_standard('mygen.generate-a-cpp-file', ['MY_TYPE'], ['CPP'])
if os.name == 'nt':
    action = 'echo void g() {} > "$(<)"'
else:
    action = 'echo "void g() {}" > "$(<)"'
def f(*args):
    print "Generating a CPP file..."

get_manager().engine().register_action("mygen.generate-a-cpp-file", action,
    function=f)
""")

    t.write("Other/jamfile.jam", """\
import mygen ;
my-obj other-obj : source.extension ;
""")

    t.run_build_system()
    t.expect_output_lines("Generating a CPP file...")
    t.expect_addition("bin/$toolset/debug/dummy.my_obj")
    t.expect_addition("Other/bin/$toolset/debug/other-obj.cpp")
    t.expect_addition("Other/bin/$toolset/debug/other-obj.my_obj")
    t.expect_nothing_more()

    t.cleanup()


###############################################################################
#
# test_using_a_derived_source_type_created_after_generator_already_used()
# -----------------------------------------------------------------------
#
###############################################################################

def test_using_a_derived_source_type_created_after_generator_already_used():
    """
      Regression test for a Boost Build bug causing it to not use a generator
    with a source type derived from one of the generator's sources but created
    only after already using the generateor.

    """
    t = BoostBuild.Tester()

    t.write("dummy.xxx", "Hello. My name is Peter Pan.\n")

    t.write("jamroot.jam", """\
import common ;
import generators ;
import type ;
type.register XXX : xxx ;
type.register YYY : yyy ;
generators.register-standard common.copy : XXX : YYY ;

# Building this dummy target must not cause a later defined XXX2 target type not
# to be recognized as a viable source type for building YYY targets.
yyy dummy : dummy.xxx ;
alias the-test-output : Other//other ;
""")

    t.write("Other/source.xxx2", "Hello. My name is Tinkerbell.\n")

    t.write("Other/jamfile.jam", """\
import type ;
type.register XXX2 : xxx2 : XXX ;
# We are careful not to do anything between defining our new XXX2 target type
# and using the XXX --> YYY generator that could potentially cover the Boost
# Build bug by clearing its internal viable source target type state.
yyy other : source.xxx2 ;
""")

    t.run_build_system()
    t.expect_addition("bin/$toolset/debug/dummy.yyy")
    t.expect_addition("Other/bin/$toolset/debug/other.yyy")
    t.expect_nothing_more()

    t.cleanup()


###############################################################################
#
# main()
# ------
#
###############################################################################

test_generator_added_after_already_building_a_target_of_its_target_type()
test_using_a_derived_source_type_created_after_generator_already_used()