Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: tools/gn/ninja_build_writer_unittest.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Fix compilation after rebase. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/pool.h"
10 #include "tools/gn/scheduler.h" 10 #include "tools/gn/scheduler.h"
11 #include "tools/gn/target.h" 11 #include "tools/gn/target.h"
12 #include "tools/gn/test_with_scope.h" 12 #include "tools/gn/test_with_scope.h"
13 13
14 TEST(NinjaBuildWriter, TwoTargets) { 14 TEST(NinjaBuildWriter, TwoTargets) {
15 Scheduler scheduler; 15 Scheduler scheduler;
16 TestWithScope setup; 16 TestWithScope setup;
17 Err err; 17 Err err;
18 18
19 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); 19 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar"), {});
20 target_foo.set_output_type(Target::ACTION); 20 target_foo.set_output_type(Target::ACTION);
21 target_foo.action_values().set_script(SourceFile("//foo/script.py")); 21 target_foo.action_values().set_script(SourceFile("//foo/script.py"));
22 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( 22 target_foo.action_values().outputs() = SubstitutionList::MakeForTest(
23 "//out/Debug/out1.out", "//out/Debug/out2.out"); 23 "//out/Debug/out1.out", "//out/Debug/out2.out");
24 target_foo.SetToolchain(setup.toolchain()); 24 target_foo.SetToolchain(setup.toolchain());
25 ASSERT_TRUE(target_foo.OnResolved(&err)); 25 ASSERT_TRUE(target_foo.OnResolved(&err));
26 26
27 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); 27 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar"), {});
28 target_bar.set_output_type(Target::ACTION); 28 target_bar.set_output_type(Target::ACTION);
29 target_bar.action_values().set_script(SourceFile("//bar/script.py")); 29 target_bar.action_values().set_script(SourceFile("//bar/script.py"));
30 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( 30 target_bar.action_values().outputs() = SubstitutionList::MakeForTest(
31 "//out/Debug/out3.out", "//out/Debug/out4.out"); 31 "//out/Debug/out3.out", "//out/Debug/out4.out");
32 target_bar.SetToolchain(setup.toolchain()); 32 target_bar.SetToolchain(setup.toolchain());
33 ASSERT_TRUE(target_bar.OnResolved(&err)); 33 ASSERT_TRUE(target_bar.OnResolved(&err));
34 34
35 // Make a secondary toolchain that references a pool. 35 // Make a secondary toolchain that references a pool.
36 Label other_toolchain_label(SourceDir("//other/"), "toolchain"); 36 Label other_toolchain_label(SourceDir("//other/"), "toolchain");
37 Pool other_pool(setup.settings(), 37 Pool other_pool(
38 Label(SourceDir("//other/"), "pool", 38 setup.settings(),
39 other_toolchain_label.dir(), 39 Label(SourceDir("//other/"), "pool", other_toolchain_label.dir(),
40 other_toolchain_label.name())); 40 other_toolchain_label.name()),
41 {});
41 other_pool.set_depth(42); 42 other_pool.set_depth(42);
42 Toolchain other_toolchain(setup.settings(), other_toolchain_label); 43 Toolchain other_toolchain(setup.settings(), other_toolchain_label, {});
43 TestWithScope::SetupToolchain(&other_toolchain); 44 TestWithScope::SetupToolchain(&other_toolchain);
44 other_toolchain.GetTool(Toolchain::TYPE_LINK)->set_pool( 45 other_toolchain.GetTool(Toolchain::TYPE_LINK)->set_pool(
45 LabelPtrPair<Pool>(&other_pool)); 46 LabelPtrPair<Pool>(&other_pool));
46 47
47 // Settings to go with the other toolchain. 48 // Settings to go with the other toolchain.
48 Settings other_settings(setup.build_settings(), "toolchain/"); 49 Settings other_settings(setup.build_settings(), "toolchain/");
49 other_settings.set_toolchain_label(other_toolchain_label); 50 other_settings.set_toolchain_label(other_toolchain_label);
50 51
51 std::unordered_map<const Settings*, const Toolchain*> used_toolchains; 52 std::unordered_map<const Settings*, const Toolchain*> used_toolchains;
52 used_toolchains[setup.settings()] = setup.toolchain(); 53 used_toolchains[setup.settings()] = setup.toolchain();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 EXPECT_SNIPPET(expected_root_target); 95 EXPECT_SNIPPET(expected_root_target);
95 EXPECT_SNIPPET(expected_default); 96 EXPECT_SNIPPET(expected_default);
96 #undef EXPECT_SNIPPET 97 #undef EXPECT_SNIPPET
97 } 98 }
98 99
99 TEST(NinjaBuildWriter, DuplicateOutputs) { 100 TEST(NinjaBuildWriter, DuplicateOutputs) {
100 Scheduler scheduler; 101 Scheduler scheduler;
101 TestWithScope setup; 102 TestWithScope setup;
102 Err err; 103 Err err;
103 104
104 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); 105 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar"), {});
105 target_foo.set_output_type(Target::ACTION); 106 target_foo.set_output_type(Target::ACTION);
106 target_foo.action_values().set_script(SourceFile("//foo/script.py")); 107 target_foo.action_values().set_script(SourceFile("//foo/script.py"));
107 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( 108 target_foo.action_values().outputs() = SubstitutionList::MakeForTest(
108 "//out/Debug/out1.out", "//out/Debug/out2.out"); 109 "//out/Debug/out1.out", "//out/Debug/out2.out");
109 target_foo.SetToolchain(setup.toolchain()); 110 target_foo.SetToolchain(setup.toolchain());
110 ASSERT_TRUE(target_foo.OnResolved(&err)); 111 ASSERT_TRUE(target_foo.OnResolved(&err));
111 112
112 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); 113 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar"), {});
113 target_bar.set_output_type(Target::ACTION); 114 target_bar.set_output_type(Target::ACTION);
114 target_bar.action_values().set_script(SourceFile("//bar/script.py")); 115 target_bar.action_values().set_script(SourceFile("//bar/script.py"));
115 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( 116 target_bar.action_values().outputs() = SubstitutionList::MakeForTest(
116 "//out/Debug/out3.out", "//out/Debug/out2.out"); 117 "//out/Debug/out3.out", "//out/Debug/out2.out");
117 target_bar.SetToolchain(setup.toolchain()); 118 target_bar.SetToolchain(setup.toolchain());
118 ASSERT_TRUE(target_bar.OnResolved(&err)); 119 ASSERT_TRUE(target_bar.OnResolved(&err));
119 120
120 std::unordered_map<const Settings*, const Toolchain*> used_toolchains; 121 std::unordered_map<const Settings*, const Toolchain*> used_toolchains;
121 used_toolchains[setup.settings()] = setup.toolchain(); 122 used_toolchains[setup.settings()] = setup.toolchain();
122 std::vector<const Target*> targets = { &target_foo, &target_bar }; 123 std::vector<const Target*> targets = { &target_foo, &target_bar };
123 std::ostringstream ninja_out; 124 std::ostringstream ninja_out;
124 std::ostringstream depfile_out; 125 std::ostringstream depfile_out;
125 NinjaBuildWriter writer(setup.build_settings(), used_toolchains, 126 NinjaBuildWriter writer(setup.build_settings(), used_toolchains,
126 setup.toolchain(), targets, ninja_out, depfile_out); 127 setup.toolchain(), targets, ninja_out, depfile_out);
127 ASSERT_FALSE(writer.Run(&err)); 128 ASSERT_FALSE(writer.Run(&err));
128 129
129 const char expected_help_test[] = 130 const char expected_help_test[] =
130 "Two or more targets generate the same output:\n" 131 "Two or more targets generate the same output:\n"
131 " out2.out\n" 132 " out2.out\n"
132 "\n" 133 "\n"
133 "This is can often be fixed by changing one of the target names, or by \n" 134 "This is can often be fixed by changing one of the target names, or by \n"
134 "setting an output_name on one of them.\n" 135 "setting an output_name on one of them.\n"
135 "\n" 136 "\n"
136 "Collisions:\n" 137 "Collisions:\n"
137 " //foo:bar\n" 138 " //foo:bar\n"
138 " //bar:bar\n"; 139 " //bar:bar\n";
139 140
140 EXPECT_EQ(expected_help_test, err.help_text()); 141 EXPECT_EQ(expected_help_test, err.help_text());
141 } 142 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_binary_target_writer_unittest.cc ('k') | tools/gn/ninja_bundle_data_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698