OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/ninja_build_writer.h" | 8 #include "tools/gn/ninja_build_writer.h" |
| 9 #include "tools/gn/pool.h" |
9 #include "tools/gn/scheduler.h" | 10 #include "tools/gn/scheduler.h" |
10 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
11 #include "tools/gn/test_with_scope.h" | 12 #include "tools/gn/test_with_scope.h" |
12 | 13 |
13 TEST(NinjaBuildWriter, TwoTargets) { | 14 TEST(NinjaBuildWriter, TwoTargets) { |
14 Scheduler scheduler; | 15 Scheduler scheduler; |
15 TestWithScope setup; | 16 TestWithScope setup; |
16 Err err; | 17 Err err; |
17 | 18 |
18 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 19 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
19 target_foo.set_output_type(Target::ACTION); | 20 target_foo.set_output_type(Target::ACTION); |
20 target_foo.action_values().set_script(SourceFile("//foo/script.py")); | 21 target_foo.action_values().set_script(SourceFile("//foo/script.py")); |
21 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( | 22 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( |
22 "//out/Debug/out1.out", "//out/Debug/out2.out"); | 23 "//out/Debug/out1.out", "//out/Debug/out2.out"); |
23 target_foo.SetToolchain(setup.toolchain()); | 24 target_foo.SetToolchain(setup.toolchain()); |
24 ASSERT_TRUE(target_foo.OnResolved(&err)); | 25 ASSERT_TRUE(target_foo.OnResolved(&err)); |
25 | 26 |
26 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); | 27 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); |
27 target_bar.set_output_type(Target::ACTION); | 28 target_bar.set_output_type(Target::ACTION); |
28 target_bar.action_values().set_script(SourceFile("//bar/script.py")); | 29 target_bar.action_values().set_script(SourceFile("//bar/script.py")); |
29 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( | 30 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( |
30 "//out/Debug/out3.out", "//out/Debug/out4.out"); | 31 "//out/Debug/out3.out", "//out/Debug/out4.out"); |
31 target_bar.SetToolchain(setup.toolchain()); | 32 target_bar.SetToolchain(setup.toolchain()); |
32 ASSERT_TRUE(target_bar.OnResolved(&err)); | 33 ASSERT_TRUE(target_bar.OnResolved(&err)); |
33 | 34 |
| 35 Pool swiming_pool(setup.settings(), |
| 36 Label(SourceDir("//swiming/"), "pool", |
| 37 SourceDir("//other/"), "toolchain")); |
| 38 swiming_pool.set_depth(42); |
| 39 |
34 std::ostringstream ninja_out; | 40 std::ostringstream ninja_out; |
35 std::ostringstream depfile_out; | 41 std::ostringstream depfile_out; |
36 std::vector<const Settings*> all_settings = {setup.settings()}; | 42 std::vector<const Settings*> all_settings = {setup.settings()}; |
37 std::vector<const Target*> targets = {&target_foo, &target_bar}; | 43 std::vector<const Target*> targets = {&target_foo, &target_bar}; |
| 44 std::vector<const Pool*> all_pools = {&swiming_pool}; |
38 NinjaBuildWriter writer(setup.build_settings(), all_settings, | 45 NinjaBuildWriter writer(setup.build_settings(), all_settings, |
39 setup.toolchain(), targets, ninja_out, depfile_out); | 46 setup.toolchain(), targets, all_pools, ninja_out, |
| 47 depfile_out); |
40 ASSERT_TRUE(writer.Run(&err)); | 48 ASSERT_TRUE(writer.Run(&err)); |
41 | 49 |
42 const char expected_rule_gn[] = "rule gn\n"; | 50 const char expected_rule_gn[] = "rule gn\n"; |
43 const char expected_build_ninja[] = | 51 const char expected_build_ninja[] = |
44 "build build.ninja: gn\n" | 52 "build build.ninja: gn\n" |
45 " generator = 1\n" | 53 " generator = 1\n" |
46 " depfile = build.ninja.d\n" | 54 " depfile = build.ninja.d\n" |
47 "\n"; | 55 "\n"; |
48 const char expected_link_pool[] = | 56 const char expected_link_pool[] = |
49 "pool link_pool\n" | 57 "pool link_pool\n" |
50 " depth = 0\n" | 58 " depth = 0\n" |
| 59 "\n" |
| 60 "pool other_toolchain_swiming_pool\n" |
| 61 " depth = 42\n" |
51 "\n"; | 62 "\n"; |
52 const char expected_toolchain[] = | 63 const char expected_toolchain[] = |
53 "subninja toolchain.ninja\n" | 64 "subninja toolchain.ninja\n" |
54 "\n"; | 65 "\n"; |
55 const char expected_targets[] = | 66 const char expected_targets[] = |
56 "build bar: phony obj/bar/bar.stamp\n" | 67 "build bar: phony obj/bar/bar.stamp\n" |
57 "build foo$:bar: phony obj/foo/bar.stamp\n" | 68 "build foo$:bar: phony obj/foo/bar.stamp\n" |
58 "build bar$:bar: phony obj/bar/bar.stamp\n" | 69 "build bar$:bar: phony obj/bar/bar.stamp\n" |
59 "\n"; | 70 "\n"; |
60 const char expected_root_target[] = | 71 const char expected_root_target[] = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 target_bar.action_values().set_script(SourceFile("//bar/script.py")); | 106 target_bar.action_values().set_script(SourceFile("//bar/script.py")); |
96 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( | 107 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( |
97 "//out/Debug/out3.out", "//out/Debug/out2.out"); | 108 "//out/Debug/out3.out", "//out/Debug/out2.out"); |
98 target_bar.SetToolchain(setup.toolchain()); | 109 target_bar.SetToolchain(setup.toolchain()); |
99 ASSERT_TRUE(target_bar.OnResolved(&err)); | 110 ASSERT_TRUE(target_bar.OnResolved(&err)); |
100 | 111 |
101 std::ostringstream ninja_out; | 112 std::ostringstream ninja_out; |
102 std::ostringstream depfile_out; | 113 std::ostringstream depfile_out; |
103 std::vector<const Settings*> all_settings = { setup.settings() }; | 114 std::vector<const Settings*> all_settings = { setup.settings() }; |
104 std::vector<const Target*> targets = { &target_foo, &target_bar }; | 115 std::vector<const Target*> targets = { &target_foo, &target_bar }; |
| 116 std::vector<const Pool*> all_pools; |
105 NinjaBuildWriter writer(setup.build_settings(), all_settings, | 117 NinjaBuildWriter writer(setup.build_settings(), all_settings, |
106 setup.toolchain(), targets, ninja_out, depfile_out); | 118 setup.toolchain(), targets, all_pools, ninja_out, |
| 119 depfile_out); |
107 ASSERT_FALSE(writer.Run(&err)); | 120 ASSERT_FALSE(writer.Run(&err)); |
108 | 121 |
109 const char expected_help_test[] = | 122 const char expected_help_test[] = |
110 "Two or more targets generate the same output:\n" | 123 "Two or more targets generate the same output:\n" |
111 " out2.out\n" | 124 " out2.out\n" |
112 "\n" | 125 "\n" |
113 "This is can often be fixed by changing one of the target names, or by \n" | 126 "This is can often be fixed by changing one of the target names, or by \n" |
114 "setting an output_name on one of them.\n" | 127 "setting an output_name on one of them.\n" |
115 "\n" | 128 "\n" |
116 "Collisions:\n" | 129 "Collisions:\n" |
117 " //foo:bar\n" | 130 " //foo:bar\n" |
118 " //bar:bar\n"; | 131 " //bar:bar\n"; |
119 | 132 |
120 EXPECT_EQ(expected_help_test, err.help_text()); | 133 EXPECT_EQ(expected_help_test, err.help_text()); |
121 } | 134 } |
OLD | NEW |