OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/ninja_action_target_writer.h" | 10 #include "tools/gn/ninja_action_target_writer.h" |
11 #include "tools/gn/pool.h" | 11 #include "tools/gn/pool.h" |
12 #include "tools/gn/substitution_list.h" | 12 #include "tools/gn/substitution_list.h" |
13 #include "tools/gn/target.h" | 13 #include "tools/gn/target.h" |
14 #include "tools/gn/test_with_scope.h" | 14 #include "tools/gn/test_with_scope.h" |
15 | 15 |
16 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLine) { | 16 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLine) { |
17 Err err; | 17 Err err; |
18 TestWithScope setup; | 18 TestWithScope setup; |
19 | 19 |
20 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 20 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
21 target.set_output_type(Target::ACTION_FOREACH); | 21 target.set_output_type(Target::ACTION_FOREACH); |
22 target.action_values().outputs() = SubstitutionList::MakeForTest( | 22 target.action_values().outputs() = SubstitutionList::MakeForTest( |
23 "//out/Debug/gen/a b{{source_name_part}}.h", | 23 "//out/Debug/gen/a b{{source_name_part}}.h", |
24 "//out/Debug/gen/{{source_name_part}}.cc"); | 24 "//out/Debug/gen/{{source_name_part}}.cc"); |
25 | 25 |
26 target.SetToolchain(setup.toolchain()); | 26 target.SetToolchain(setup.toolchain()); |
27 ASSERT_TRUE(target.OnResolved(&err)); | 27 ASSERT_TRUE(target.OnResolved(&err)); |
28 | 28 |
29 std::ostringstream out; | 29 std::ostringstream out; |
30 NinjaActionTargetWriter writer(&target, out); | 30 NinjaActionTargetWriter writer(&target, out); |
31 | 31 |
32 SourceFile source("//foo/bar.in"); | 32 SourceFile source("//foo/bar.in"); |
33 std::vector<OutputFile> output_files; | 33 std::vector<OutputFile> output_files; |
34 writer.WriteOutputFilesForBuildLine(source, &output_files); | 34 writer.WriteOutputFilesForBuildLine(source, &output_files); |
35 | 35 |
36 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); | 36 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); |
37 } | 37 } |
38 | 38 |
39 // Tests an action with no sources. | 39 // Tests an action with no sources. |
40 TEST(NinjaActionTargetWriter, ActionNoSources) { | 40 TEST(NinjaActionTargetWriter, ActionNoSources) { |
41 Err err; | 41 Err err; |
42 TestWithScope setup; | 42 TestWithScope setup; |
43 | 43 |
44 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 44 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
45 target.set_output_type(Target::ACTION); | 45 target.set_output_type(Target::ACTION); |
46 | 46 |
47 target.action_values().set_script(SourceFile("//foo/script.py")); | 47 target.action_values().set_script(SourceFile("//foo/script.py")); |
48 target.inputs().push_back(SourceFile("//foo/included.txt")); | 48 target.inputs().push_back(SourceFile("//foo/included.txt")); |
49 | 49 |
50 target.action_values().outputs() = | 50 target.action_values().outputs() = |
51 SubstitutionList::MakeForTest("//out/Debug/foo.out"); | 51 SubstitutionList::MakeForTest("//out/Debug/foo.out"); |
52 | 52 |
53 target.SetToolchain(setup.toolchain()); | 53 target.SetToolchain(setup.toolchain()); |
54 ASSERT_TRUE(target.OnResolved(&err)); | 54 ASSERT_TRUE(target.OnResolved(&err)); |
(...skipping 18 matching lines...) Expand all Loading... |
73 "build obj/foo/bar.stamp: stamp foo.out\n"; | 73 "build obj/foo/bar.stamp: stamp foo.out\n"; |
74 EXPECT_EQ(expected, out.str()); | 74 EXPECT_EQ(expected, out.str()); |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 // Tests an action with no sources and console = true | 78 // Tests an action with no sources and console = true |
79 TEST(NinjaActionTargetWriter, ActionNoSourcesConsole) { | 79 TEST(NinjaActionTargetWriter, ActionNoSourcesConsole) { |
80 Err err; | 80 Err err; |
81 TestWithScope setup; | 81 TestWithScope setup; |
82 | 82 |
83 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 83 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
84 target.set_output_type(Target::ACTION); | 84 target.set_output_type(Target::ACTION); |
85 | 85 |
86 target.action_values().set_script(SourceFile("//foo/script.py")); | 86 target.action_values().set_script(SourceFile("//foo/script.py")); |
87 target.inputs().push_back(SourceFile("//foo/included.txt")); | 87 target.inputs().push_back(SourceFile("//foo/included.txt")); |
88 | 88 |
89 target.action_values().outputs() = | 89 target.action_values().outputs() = |
90 SubstitutionList::MakeForTest("//out/Debug/foo.out"); | 90 SubstitutionList::MakeForTest("//out/Debug/foo.out"); |
91 | 91 |
92 Pool pool(setup.settings(), Label(SourceDir("//foo/"), "pool")); | 92 Pool pool(setup.settings(), Label(SourceDir("//foo/"), "pool"), {}); |
93 pool.set_console(true); | 93 pool.set_console(true); |
94 target.action_values().set_pool(LabelPtrPair<Pool>(&pool)); | 94 target.action_values().set_pool(LabelPtrPair<Pool>(&pool)); |
95 | 95 |
96 target.SetToolchain(setup.toolchain()); | 96 target.SetToolchain(setup.toolchain()); |
97 ASSERT_TRUE(target.OnResolved(&err)); | 97 ASSERT_TRUE(target.OnResolved(&err)); |
98 | 98 |
99 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( | 99 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( |
100 "/usr/bin/python"))); | 100 "/usr/bin/python"))); |
101 | 101 |
102 std::ostringstream out; | 102 std::ostringstream out; |
(...skipping 14 matching lines...) Expand all Loading... |
117 "build obj/foo/bar.stamp: stamp foo.out\n"; | 117 "build obj/foo/bar.stamp: stamp foo.out\n"; |
118 EXPECT_EQ(expected, out.str()); | 118 EXPECT_EQ(expected, out.str()); |
119 } | 119 } |
120 | 120 |
121 // Makes sure that we write sources as input dependencies for actions with | 121 // Makes sure that we write sources as input dependencies for actions with |
122 // both sources and inputs (ACTION_FOREACH treats the sources differently). | 122 // both sources and inputs (ACTION_FOREACH treats the sources differently). |
123 TEST(NinjaActionTargetWriter, ActionWithSources) { | 123 TEST(NinjaActionTargetWriter, ActionWithSources) { |
124 Err err; | 124 Err err; |
125 TestWithScope setup; | 125 TestWithScope setup; |
126 | 126 |
127 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 127 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
128 target.set_output_type(Target::ACTION); | 128 target.set_output_type(Target::ACTION); |
129 | 129 |
130 target.action_values().set_script(SourceFile("//foo/script.py")); | 130 target.action_values().set_script(SourceFile("//foo/script.py")); |
131 | 131 |
132 target.sources().push_back(SourceFile("//foo/source.txt")); | 132 target.sources().push_back(SourceFile("//foo/source.txt")); |
133 target.inputs().push_back(SourceFile("//foo/included.txt")); | 133 target.inputs().push_back(SourceFile("//foo/included.txt")); |
134 | 134 |
135 target.action_values().outputs() = | 135 target.action_values().outputs() = |
136 SubstitutionList::MakeForTest("//out/Debug/foo.out"); | 136 SubstitutionList::MakeForTest("//out/Debug/foo.out"); |
137 | 137 |
(...skipping 22 matching lines...) Expand all Loading... |
160 } | 160 } |
161 | 161 |
162 TEST(NinjaActionTargetWriter, ForEach) { | 162 TEST(NinjaActionTargetWriter, ForEach) { |
163 Err err; | 163 Err err; |
164 TestWithScope setup; | 164 TestWithScope setup; |
165 | 165 |
166 // Some dependencies that the action can depend on. Use actions for these | 166 // Some dependencies that the action can depend on. Use actions for these |
167 // so they have a nice platform-independent stamp file that can appear in the | 167 // so they have a nice platform-independent stamp file that can appear in the |
168 // output (rather than having to worry about how the current platform names | 168 // output (rather than having to worry about how the current platform names |
169 // binaries). | 169 // binaries). |
170 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep")); | 170 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"), {}); |
171 dep.set_output_type(Target::ACTION); | 171 dep.set_output_type(Target::ACTION); |
172 dep.visibility().SetPublic(); | 172 dep.visibility().SetPublic(); |
173 dep.SetToolchain(setup.toolchain()); | 173 dep.SetToolchain(setup.toolchain()); |
174 ASSERT_TRUE(dep.OnResolved(&err)); | 174 ASSERT_TRUE(dep.OnResolved(&err)); |
175 | 175 |
176 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep")); | 176 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"), {}); |
177 datadep.set_output_type(Target::ACTION); | 177 datadep.set_output_type(Target::ACTION); |
178 datadep.visibility().SetPublic(); | 178 datadep.visibility().SetPublic(); |
179 datadep.SetToolchain(setup.toolchain()); | 179 datadep.SetToolchain(setup.toolchain()); |
180 ASSERT_TRUE(datadep.OnResolved(&err)); | 180 ASSERT_TRUE(datadep.OnResolved(&err)); |
181 | 181 |
182 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 182 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
183 target.set_output_type(Target::ACTION_FOREACH); | 183 target.set_output_type(Target::ACTION_FOREACH); |
184 target.private_deps().push_back(LabelTargetPair(&dep)); | 184 target.private_deps().push_back(LabelTargetPair(&dep)); |
185 target.data_deps().push_back(LabelTargetPair(&datadep)); | 185 target.data_deps().push_back(LabelTargetPair(&datadep)); |
186 | 186 |
187 target.sources().push_back(SourceFile("//foo/input1.txt")); | 187 target.sources().push_back(SourceFile("//foo/input1.txt")); |
188 target.sources().push_back(SourceFile("//foo/input2.txt")); | 188 target.sources().push_back(SourceFile("//foo/input2.txt")); |
189 | 189 |
190 target.action_values().set_script(SourceFile("//foo/script.py")); | 190 target.action_values().set_script(SourceFile("//foo/script.py")); |
191 | 191 |
192 target.action_values().args() = SubstitutionList::MakeForTest( | 192 target.action_values().args() = SubstitutionList::MakeForTest( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
237 std::replace(out_str.begin(), out_str.end(), '\\', '/'); | 237 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
238 #endif | 238 #endif |
239 EXPECT_EQ(expected_linux, out_str); | 239 EXPECT_EQ(expected_linux, out_str); |
240 } | 240 } |
241 | 241 |
242 TEST(NinjaActionTargetWriter, ForEachWithDepfile) { | 242 TEST(NinjaActionTargetWriter, ForEachWithDepfile) { |
243 Err err; | 243 Err err; |
244 TestWithScope setup; | 244 TestWithScope setup; |
245 | 245 |
246 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 246 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
247 target.set_output_type(Target::ACTION_FOREACH); | 247 target.set_output_type(Target::ACTION_FOREACH); |
248 | 248 |
249 target.sources().push_back(SourceFile("//foo/input1.txt")); | 249 target.sources().push_back(SourceFile("//foo/input1.txt")); |
250 target.sources().push_back(SourceFile("//foo/input2.txt")); | 250 target.sources().push_back(SourceFile("//foo/input2.txt")); |
251 | 251 |
252 target.action_values().set_script(SourceFile("//foo/script.py")); | 252 target.action_values().set_script(SourceFile("//foo/script.py")); |
253 | 253 |
254 target.SetToolchain(setup.toolchain()); | 254 target.SetToolchain(setup.toolchain()); |
255 ASSERT_TRUE(target.OnResolved(&err)); | 255 ASSERT_TRUE(target.OnResolved(&err)); |
256 | 256 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 " depfile = gen/input2.d\n" | 298 " depfile = gen/input2.d\n" |
299 "\n" | 299 "\n" |
300 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 300 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
301 EXPECT_EQ(expected_linux, out.str()); | 301 EXPECT_EQ(expected_linux, out.str()); |
302 } | 302 } |
303 | 303 |
304 TEST(NinjaActionTargetWriter, ForEachWithResponseFile) { | 304 TEST(NinjaActionTargetWriter, ForEachWithResponseFile) { |
305 Err err; | 305 Err err; |
306 TestWithScope setup; | 306 TestWithScope setup; |
307 | 307 |
308 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 308 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
309 target.set_output_type(Target::ACTION_FOREACH); | 309 target.set_output_type(Target::ACTION_FOREACH); |
310 | 310 |
311 target.sources().push_back(SourceFile("//foo/input1.txt")); | 311 target.sources().push_back(SourceFile("//foo/input1.txt")); |
312 target.action_values().set_script(SourceFile("//foo/script.py")); | 312 target.action_values().set_script(SourceFile("//foo/script.py")); |
313 | 313 |
314 target.SetToolchain(setup.toolchain()); | 314 target.SetToolchain(setup.toolchain()); |
315 ASSERT_TRUE(target.OnResolved(&err)); | 315 ASSERT_TRUE(target.OnResolved(&err)); |
316 | 316 |
317 // Make sure we get interesting substitutions for both the args and the | 317 // Make sure we get interesting substitutions for both the args and the |
318 // response file contents. | 318 // response file contents. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Necessary for the rspfile defined in the rule. | 350 // Necessary for the rspfile defined in the rule. |
351 " unique_name = 0\n" | 351 " unique_name = 0\n" |
352 // Substitution for the args. | 352 // Substitution for the args. |
353 " source_file_part = input1.txt\n" | 353 " source_file_part = input1.txt\n" |
354 // Substitution for the rspfile contents. | 354 // Substitution for the rspfile contents. |
355 " source_name_part = input1\n" | 355 " source_name_part = input1\n" |
356 "\n" | 356 "\n" |
357 "build obj/foo/bar.stamp: stamp input1.out\n"; | 357 "build obj/foo/bar.stamp: stamp input1.out\n"; |
358 EXPECT_EQ(expected_linux, out.str()); | 358 EXPECT_EQ(expected_linux, out.str()); |
359 } | 359 } |
OLD | NEW |