1#!/usr/bin/python
2
3# Copyright 2012 Jurko Gospodnetic
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or copy at
6# http://www.boost.org/LICENSE_1_0.txt)
7
8# Tests rc toolset behaviour.
9
10import BoostBuild
11
12
13def included_resource_newer_than_rc_script():
14    """
15      When a .rc script file includes another resource file - the resource file
16    being newer than the .rc script file should not cause the .rc script file
17    to be considered old and force all of its dependents to rebuild.
18
19    """
20    toolsetName = "__myDummyResourceCompilerToolset__"
21
22    # Used options rationale:
23    #
24    # -d4 & --debug-configuration
25    #     Display additional information in case of test failure. In the past
26    #   we have had testing system issues  causing this test to fail
27    #   sporadically for which -d+3 output had been instrumental in getting to
28    #   the root cause (a touched file's timestamp was not as new as it should
29    #   have been).
30    #
31    # --ignore-site-config --user-config=
32    #     Disable reading any external Boost Build configuration. This test is
33    #   self sufficient so these options protect it from being adversly
34    #   affected by any local (mis)configuration..
35    t = BoostBuild.Tester(["-d4", "--debug-configuration",
36        "--ignore-site-config", "--user-config=", "toolset=%s" % toolsetName],
37        pass_d0=False, pass_toolset=False, use_test_config=False,
38        translate_suffixes=False)
39
40    # Prepare a dummy toolset so we do not get errors in case the default one
41    # is not found and that we can test rc.jam functionality without having to
42    # depend on the externally specified toolset actually supporting it exactly
43    # the way it is required for this test, e.g. gcc toolset, under some
44    # circumstances, uses a quiet action for generating its null RC targets.
45    t.write(toolsetName + ".jam", """\
46import feature ;
47import rc ;
48import type ;
49local toolset-name = "%s" ;
50feature.extend toolset : $(toolset-name) ;
51rule init ( ) { }
52rc.configure dummy-rc-command : <toolset>$(toolset-name) : <rc-type>dummy ;
53module rc
54{
55    rule compile.resource.dummy ( targets * : sources * : properties * )
56    {
57        import common ;
58        .TOUCH on $(targets) = [ common.file-touch-command ] ;
59    }
60    actions compile.resource.dummy { $(.TOUCH) "$(<)" }
61}
62# Make OBJ files generated by our toolset use the "obj" suffix on all
63# platforms. We need to do this explicitly for <target-os> windows & cygwin to
64# override the default OBJ type configuration (otherwise we would get
65# 'ambiguous key' errors on those platforms).
66local rule set-generated-obj-suffix ( target-os ? )
67{
68    type.set-generated-target-suffix OBJ : <toolset>$(toolset-name)
69        <target-os>$(target-os) : obj ;
70}
71set-generated-obj-suffix ;
72set-generated-obj-suffix windows ;
73set-generated-obj-suffix cygwin ;
74""" % toolsetName)
75
76    # Prepare project source files.
77    t.write("jamroot.jam", """\
78ECHO {{{ [ modules.peek : XXX ] [ modules.peek : NOEXEC ] }}} ;
79obj xxx : xxx.rc ;
80""")
81    t.write("xxx.rc", '1 MESSAGETABLE "xxx.bin"\n')
82    t.write("xxx.bin", "foo")
83
84    def test1(n, expect, noexec=False):
85        params = ["-sXXX=%d" % n]
86        if noexec:
87            params.append("-n")
88            params.append("-sNOEXEC=NOEXEC")
89        t.run_build_system(params)
90        t.expect_output_lines("*NOEXEC*", noexec)
91        obj_file = "xxx_res.obj"
92        t.expect_output_lines("compile.resource.dummy *%s" % obj_file, expect)
93        if expect and not noexec:
94            expect("bin/%s/debug/%s" % (toolsetName, obj_file))
95        t.expect_nothing_more()
96
97    def test(n, expect):
98        test1(n, expect, noexec=True)
99        test1(n, expect)
100
101    test(1, t.expect_addition)
102    test(2, None)
103    t.touch("xxx.bin")
104    test(3, t.expect_touch)
105    test(4, None)
106
107    t.cleanup()
108
109
110included_resource_newer_than_rc_script()
111