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

# Copyright 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 rc toolset behaviour.

import BoostBuild


def included_resource_newer_than_rc_script():
    """
      When a .rc script file includes another resource file - the resource file
    being newer than the .rc script file should not cause the .rc script file
    to be considered old and force all of its dependents to rebuild.

    """
    toolsetName = "__myDummyResourceCompilerToolset__"

    # Used options rationale:
    #
    # -d4 & --debug-configuration
    #     Display additional information in case of test failure. In the past
    #   we have had testing system issues  causing this test to fail
    #   sporadically for which -d+3 output had been instrumental in getting to
    #   the root cause (a touched file's timestamp was not as new as it should
    #   have been).
    #
    # --ignore-site-config --user-config=
    #     Disable reading any external Boost Build configuration. This test is
    #   self sufficient so these options protect it from being adversly
    #   affected by any local (mis)configuration..
    t = BoostBuild.Tester(["-d4", "--debug-configuration",
        "--ignore-site-config", "--user-config=", "toolset=%s" % toolsetName],
        pass_toolset=False, use_test_config=False,
        translate_suffixes=False)

    # Prepare a dummy toolset so we do not get errors in case the default one
    # is not found and that we can test rc.jam functionality without having to
    # depend on the externally specified toolset actually supporting it exactly
    # the way it is required for this test, e.g. gcc toolset, under some
    # circumstances, uses a quiet action for generating its null RC targets.
    t.write(toolsetName + ".jam", """\
import feature ;
import rc ;
import type ;
local toolset-name = "%s" ;
feature.extend toolset : $(toolset-name) ;
rule init ( ) { }
rc.configure dummy-rc-command : <toolset>$(toolset-name) : <rc-type>dummy ;
module rc
{
    rule compile.resource.dummy ( targets * : sources * : properties * )
    {
        import common ;
        .TOUCH on $(targets) = [ common.file-touch-command ] ;
    }
    actions compile.resource.dummy { $(.TOUCH) "$(<)" }
}
# Make OBJ files generated by our toolset use the "obj" suffix on all
# platforms. We need to do this explicitly for <target-os> windows & cygwin to
# override the default OBJ type configuration (otherwise we would get
# 'ambiguous key' errors on those platforms).
local rule set-generated-obj-suffix ( target-os ? )
{
    type.set-generated-target-suffix OBJ : <toolset>$(toolset-name)
        <target-os>$(target-os) : obj ;
}
set-generated-obj-suffix ;
set-generated-obj-suffix windows ;
set-generated-obj-suffix cygwin ;
""" % toolsetName)

    t.write(
        toolsetName + '.py',
"""
from b2.build import feature, type as type_
from b2.manager import get_manager
from b2.tools import rc, common

MANAGER = get_manager()
ENGINE = MANAGER.engine()

toolset_name = "{0}"

feature.extend('toolset', [toolset_name])

def init(*args):
    pass

rc.configure(['dummy-rc-command'], ['<toolset>' + toolset_name], ['<rc-type>dummy'])

ENGINE.register_action(
    'rc.compile.resource.dummy',
    '''
    %s "$(<)"
    ''' % common.file_creation_command()
)

def set_generated_obj_suffix(target_os=''):
    requirements = ['<toolset>' + toolset_name]
    if target_os:
        requirements.append('<target-os>' + target_os)
    type_.set_generated_target_suffix('OBJ', requirements, 'obj')

set_generated_obj_suffix()
set_generated_obj_suffix('windows')
set_generated_obj_suffix('cygwin')
""".format(toolsetName)
    )

    # Prepare project source files.
    t.write("jamroot.jam", """\
ECHO "{{{" [ modules.peek : XXX ] [ modules.peek : NOEXEC ] "}}}" ;
obj xxx : xxx.rc ;
""")
    t.write("xxx.rc", '1 MESSAGETABLE "xxx.bin"\n')
    t.write("xxx.bin", "foo")

    def test1(n, expect, noexec=False):
        params = ["-sXXX=%d" % n]
        if noexec:
            params.append("-n")
            params.append("-sNOEXEC=NOEXEC")
        t.run_build_system(params)
        t.expect_output_lines("*NOEXEC*", noexec)
        obj_file = "xxx_res.obj"
        t.expect_output_lines("compile.resource.dummy *%s" % obj_file, expect)
        if expect and not noexec:
            expect("bin/%s/debug/%s" % (toolsetName, obj_file))
        t.expect_nothing_more()

    def test(n, expect):
        test1(n, expect, noexec=True)
        test1(n, expect)

    test(1, t.expect_addition)
    test(2, None)
    t.touch("xxx.bin")
    test(3, t.expect_touch)
    test(4, None)

    t.cleanup()


included_resource_newer_than_rc_script()