1 | # Copyright 2001, 2002 Dave Abrahams |
---|
2 | # Copyright 2005 Rene Rivera |
---|
3 | # Distributed under the Boost Software License, Version 1.0. |
---|
4 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | ############################################################## |
---|
7 | # Rules and actions that test Jam by invoking it recursively # |
---|
8 | # # |
---|
9 | # This is necessary for testing anything that requires Jam # |
---|
10 | # to execute build actions whose results must be checked, # |
---|
11 | # and anything which exits Jam with a failure code (e.g. a # |
---|
12 | # failed assertion). # |
---|
13 | ############################################################## |
---|
14 | |
---|
15 | # Creates a fake target, always built, which succeeds in building if Invoking a |
---|
16 | # Jamfile containing the given string succeeds. If optional-expected-output is |
---|
17 | # supplied, creates another fake target which succeeds in building if |
---|
18 | # optional-expected-output is in the Jam output. |
---|
19 | # |
---|
20 | # RETURNS: the target name of the Jam command. |
---|
21 | rule Jam ( command : expected-output ? ) |
---|
22 | { |
---|
23 | local jam-cmd = "$(command:G=jam_command)" ; |
---|
24 | |
---|
25 | NOTFILE "$(jam-cmd)" ; |
---|
26 | ALWAYS "$(jam-cmd)" ; |
---|
27 | DEPENDS all : "$(jam-cmd)" ; |
---|
28 | |
---|
29 | if ($NT) |
---|
30 | { |
---|
31 | redirect on $(jam-cmd) = "nul" ; |
---|
32 | } |
---|
33 | else if $(UNIX) |
---|
34 | { |
---|
35 | redirect on $(jam-cmd) = "/dev/null" ; |
---|
36 | } |
---|
37 | |
---|
38 | if $(VERBOSE) |
---|
39 | { |
---|
40 | redirect on $(jam-cmd) = ; |
---|
41 | } |
---|
42 | |
---|
43 | invoke-Jam "$(jam-cmd)" ; |
---|
44 | |
---|
45 | if $(expected-output) |
---|
46 | { |
---|
47 | redirect on $(jam-cmd) = "scratch-output.txt" ; |
---|
48 | local output-target = "$(expected-output:G=$(command))" ; |
---|
49 | NOTFILE "$(output-target)" ; |
---|
50 | ALWAYS "$(output-target)" ; |
---|
51 | DEPENDS all : "$(output-target)" ; |
---|
52 | Expect-in-output "$(output-target)" ; |
---|
53 | |
---|
54 | if $(VERBOSE) |
---|
55 | { |
---|
56 | if $(NT) { VERBOSE on $(output-target) = "type " ; } |
---|
57 | else { VERBOSE on $(output-target) = "cat " ; } |
---|
58 | } |
---|
59 | } |
---|
60 | return $(jam-cmd) ; |
---|
61 | } |
---|
62 | |
---|
63 | # Just like the "Jam" rule, above, but only succeeds if the Jam command /fails/. |
---|
64 | rule Jam-fail ( command : expected-output ? ) |
---|
65 | { |
---|
66 | local target = [ Jam $(command) : $(expected-output) ] ; |
---|
67 | FAIL_EXPECTED $(target) ; |
---|
68 | return $(target) ; |
---|
69 | } |
---|
70 | |
---|
71 | # The temporary jamfile we write is called "temp.jam". If the user has set |
---|
72 | # BOOST_BUILD_ROOT, it will be built there. |
---|
73 | gBOOST_TEST_JAMFILE = temp.jam ; |
---|
74 | LOCATE on gBOOST_TEST_JAMFILE ?= $(BOOST_BUILD_ROOT) ; |
---|
75 | |
---|
76 | # Runs Jam on a temporary Jamfile which contains the string in $(command:G=) |
---|
77 | # and redirects the results into a file whose name is given by $(redirect) on |
---|
78 | # command |
---|
79 | rule invoke-Jam ( command ) |
---|
80 | { |
---|
81 | PREFIX on $(command) = "actions unbuilt { } unbuilt all ;" ; |
---|
82 | if $(NT) |
---|
83 | { |
---|
84 | REMOVE on $(command) = $(SystemRoot)\System32\find ; |
---|
85 | } |
---|
86 | REMOVE on $(command) ?= rm ; |
---|
87 | } |
---|
88 | actions invoke-Jam |
---|
89 | { |
---|
90 | echo $(PREFIX) $(<:G=) > $(gBOOST_TEST_JAMFILE) |
---|
91 | jam -sBOOST_ROOT=../../.. -sJAMFILE=$(gBOOST_TEST_JAMFILE) $(JAMARGS) >$(redirect) |
---|
92 | } |
---|
93 | # $(REMOVE) $(gBOOST_TEST_JAMFILE) |
---|
94 | |
---|
95 | |
---|
96 | # These actions expect to find the ungristed part of $(<) in scratch-output.txt |
---|
97 | # and return a nonzero exit code otherwise |
---|
98 | if $(NT) |
---|
99 | { |
---|
100 | # Explicitly get the NT find command in case someone has another find in their path. |
---|
101 | actions quietly Expect-in-output |
---|
102 | { |
---|
103 | $(VERBOSE)scratch-output.txt ; |
---|
104 | $(SystemRoot)\System32\find /C "$(<:G=)" scratch-output.txt >nul |
---|
105 | } |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | # Not really the right actions for Unix; the argument will be interpreted as |
---|
110 | # a regular expression. Is there a simpler find? |
---|
111 | actions quietly Expect-in-output |
---|
112 | { |
---|
113 | $(VERBOSE)scratch-output.txt; |
---|
114 | grep "$(<:G=)" scratch-output.txt |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|