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

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

Issue 48523006: GN: Separately track labels and origins for lists of stuff (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/target_generator.cc ('k') | tools/gn/value_extractors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/build_settings.h" 6 #include "tools/gn/build_settings.h"
7 #include "tools/gn/config.h" 7 #include "tools/gn/config.h"
8 #include "tools/gn/settings.h" 8 #include "tools/gn/settings.h"
9 #include "tools/gn/target.h" 9 #include "tools/gn/target.h"
10 #include "tools/gn/toolchain.h" 10 #include "tools/gn/toolchain.h"
(...skipping 21 matching lines...) Expand all
32 // Tests that depending on a group is like depending directly on the group's 32 // Tests that depending on a group is like depending directly on the group's
33 // deps. 33 // deps.
34 TEST_F(TargetTest, GroupDeps) { 34 TEST_F(TargetTest, GroupDeps) {
35 // Two low-level targets. 35 // Two low-level targets.
36 Target x(&settings_, Label(SourceDir("//component/"), "x")); 36 Target x(&settings_, Label(SourceDir("//component/"), "x"));
37 Target y(&settings_, Label(SourceDir("//component/"), "y")); 37 Target y(&settings_, Label(SourceDir("//component/"), "y"));
38 38
39 // Make a group for both x and y. 39 // Make a group for both x and y.
40 Target g(&settings_, Label(SourceDir("//group/"), "g")); 40 Target g(&settings_, Label(SourceDir("//group/"), "g"));
41 g.set_output_type(Target::GROUP); 41 g.set_output_type(Target::GROUP);
42 g.deps().push_back(&x); 42 g.deps().push_back(LabelTargetPair(&x));
43 g.deps().push_back(&y); 43 g.deps().push_back(LabelTargetPair(&y));
44 44
45 // Random placeholder target so we can see the group's deps get inserted at 45 // Random placeholder target so we can see the group's deps get inserted at
46 // the right place. 46 // the right place.
47 Target b(&settings_, Label(SourceDir("//app/"), "b")); 47 Target b(&settings_, Label(SourceDir("//app/"), "b"));
48 48
49 // Make a target depending on the group and "b". OnResolved will expand. 49 // Make a target depending on the group and "b". OnResolved will expand.
50 Target a(&settings_, Label(SourceDir("//app/"), "a")); 50 Target a(&settings_, Label(SourceDir("//app/"), "a"));
51 a.set_output_type(Target::EXECUTABLE); 51 a.set_output_type(Target::EXECUTABLE);
52 a.deps().push_back(&g); 52 a.deps().push_back(LabelTargetPair(&g));
53 a.deps().push_back(&b); 53 a.deps().push_back(LabelTargetPair(&b));
54 a.OnResolved(); 54 a.OnResolved();
55 55
56 // The group's deps should be inserted after the group itself in the deps 56 // The group's deps should be inserted after the group itself in the deps
57 // list, so we should get "g, x, y, b" 57 // list, so we should get "g, x, y, b"
58 ASSERT_EQ(4u, a.deps().size()); 58 ASSERT_EQ(4u, a.deps().size());
59 EXPECT_EQ(&g, a.deps()[0]); 59 EXPECT_EQ(&g, a.deps()[0].ptr);
60 EXPECT_EQ(&x, a.deps()[1]); 60 EXPECT_EQ(&x, a.deps()[1].ptr);
61 EXPECT_EQ(&y, a.deps()[2]); 61 EXPECT_EQ(&y, a.deps()[2].ptr);
62 EXPECT_EQ(&b, a.deps()[3]); 62 EXPECT_EQ(&b, a.deps()[3].ptr);
63 } 63 }
64 64
65 // Tests that lib[_dir]s are inherited across deps boundaries for static 65 // Tests that lib[_dir]s are inherited across deps boundaries for static
66 // libraries but not executables. 66 // libraries but not executables.
67 TEST_F(TargetTest, LibInheritance) { 67 TEST_F(TargetTest, LibInheritance) {
68 const std::string lib("foo"); 68 const std::string lib("foo");
69 const SourceDir libdir("/foo_dir/"); 69 const SourceDir libdir("/foo_dir/");
70 70
71 // Leaf target with ldflags set. 71 // Leaf target with ldflags set.
72 Target z(&settings_, Label(SourceDir("//foo/"), "z")); 72 Target z(&settings_, Label(SourceDir("//foo/"), "z"));
73 z.set_output_type(Target::STATIC_LIBRARY); 73 z.set_output_type(Target::STATIC_LIBRARY);
74 z.config_values().libs().push_back(lib); 74 z.config_values().libs().push_back(lib);
75 z.config_values().lib_dirs().push_back(libdir); 75 z.config_values().lib_dirs().push_back(libdir);
76 z.OnResolved(); 76 z.OnResolved();
77 77
78 // All lib[_dir]s should be set when target is resolved. 78 // All lib[_dir]s should be set when target is resolved.
79 ASSERT_EQ(1u, z.all_libs().size()); 79 ASSERT_EQ(1u, z.all_libs().size());
80 EXPECT_EQ(lib, z.all_libs()[0]); 80 EXPECT_EQ(lib, z.all_libs()[0]);
81 ASSERT_EQ(1u, z.all_lib_dirs().size()); 81 ASSERT_EQ(1u, z.all_lib_dirs().size());
82 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); 82 EXPECT_EQ(libdir, z.all_lib_dirs()[0]);
83 83
84 // Shared library target should inherit the libs from the static library 84 // Shared library target should inherit the libs from the static library
85 // and its own. Its own flag should be before the inherited one. 85 // and its own. Its own flag should be before the inherited one.
86 const std::string second_lib("bar"); 86 const std::string second_lib("bar");
87 const SourceDir second_libdir("/bar_dir/"); 87 const SourceDir second_libdir("/bar_dir/");
88 Target shared(&settings_, Label(SourceDir("//foo/"), "shared")); 88 Target shared(&settings_, Label(SourceDir("//foo/"), "shared"));
89 shared.set_output_type(Target::SHARED_LIBRARY); 89 shared.set_output_type(Target::SHARED_LIBRARY);
90 shared.config_values().libs().push_back(second_lib); 90 shared.config_values().libs().push_back(second_lib);
91 shared.config_values().lib_dirs().push_back(second_libdir); 91 shared.config_values().lib_dirs().push_back(second_libdir);
92 shared.deps().push_back(&z); 92 shared.deps().push_back(LabelTargetPair(&z));
93 shared.OnResolved(); 93 shared.OnResolved();
94 94
95 ASSERT_EQ(2u, shared.all_libs().size()); 95 ASSERT_EQ(2u, shared.all_libs().size());
96 EXPECT_EQ(second_lib, shared.all_libs()[0]); 96 EXPECT_EQ(second_lib, shared.all_libs()[0]);
97 EXPECT_EQ(lib, shared.all_libs()[1]); 97 EXPECT_EQ(lib, shared.all_libs()[1]);
98 ASSERT_EQ(2u, shared.all_lib_dirs().size()); 98 ASSERT_EQ(2u, shared.all_lib_dirs().size());
99 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]); 99 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]);
100 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]); 100 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]);
101 101
102 // Executable target shouldn't get either by depending on shared. 102 // Executable target shouldn't get either by depending on shared.
103 Target exec(&settings_, Label(SourceDir("//foo/"), "exec")); 103 Target exec(&settings_, Label(SourceDir("//foo/"), "exec"));
104 exec.set_output_type(Target::EXECUTABLE); 104 exec.set_output_type(Target::EXECUTABLE);
105 exec.deps().push_back(&shared); 105 exec.deps().push_back(LabelTargetPair(&shared));
106 exec.OnResolved(); 106 exec.OnResolved();
107 EXPECT_EQ(0u, exec.all_libs().size()); 107 EXPECT_EQ(0u, exec.all_libs().size());
108 EXPECT_EQ(0u, exec.all_lib_dirs().size()); 108 EXPECT_EQ(0u, exec.all_lib_dirs().size());
109 } 109 }
110 110
111 // Test all/direct_dependent_configs inheritance, and 111 // Test all/direct_dependent_configs inheritance, and
112 // forward_dependent_configs_from 112 // forward_dependent_configs_from
113 TEST_F(TargetTest, DependentConfigs) { 113 TEST_F(TargetTest, DependentConfigs) {
114 // Set up a dependency chain of a -> b -> c 114 // Set up a dependency chain of a -> b -> c
115 Target a(&settings_, Label(SourceDir("//foo/"), "a")); 115 Target a(&settings_, Label(SourceDir("//foo/"), "a"));
116 a.set_output_type(Target::EXECUTABLE); 116 a.set_output_type(Target::EXECUTABLE);
117 Target b(&settings_, Label(SourceDir("//foo/"), "b")); 117 Target b(&settings_, Label(SourceDir("//foo/"), "b"));
118 b.set_output_type(Target::STATIC_LIBRARY); 118 b.set_output_type(Target::STATIC_LIBRARY);
119 Target c(&settings_, Label(SourceDir("//foo/"), "c")); 119 Target c(&settings_, Label(SourceDir("//foo/"), "c"));
120 c.set_output_type(Target::STATIC_LIBRARY); 120 c.set_output_type(Target::STATIC_LIBRARY);
121 a.deps().push_back(&b); 121 a.deps().push_back(LabelTargetPair(&b));
122 b.deps().push_back(&c); 122 b.deps().push_back(LabelTargetPair(&c));
123 123
124 // Normal non-inherited config. 124 // Normal non-inherited config.
125 Config config(Label(SourceDir("//foo/"), "config")); 125 Config config(Label(SourceDir("//foo/"), "config"));
126 c.configs().push_back(&config); 126 c.configs().push_back(LabelConfigPair(&config));
127 127
128 // All dependent config. 128 // All dependent config.
129 Config all(Label(SourceDir("//foo/"), "all")); 129 Config all(Label(SourceDir("//foo/"), "all"));
130 c.all_dependent_configs().push_back(&all); 130 c.all_dependent_configs().push_back(LabelConfigPair(&all));
131 131
132 // Direct dependent config. 132 // Direct dependent config.
133 Config direct(Label(SourceDir("//foo/"), "direct")); 133 Config direct(Label(SourceDir("//foo/"), "direct"));
134 c.direct_dependent_configs().push_back(&direct); 134 c.direct_dependent_configs().push_back(LabelConfigPair(&direct));
135 135
136 c.OnResolved(); 136 c.OnResolved();
137 b.OnResolved(); 137 b.OnResolved();
138 a.OnResolved(); 138 a.OnResolved();
139 139
140 // B should have gotten both dependent configs from C. 140 // B should have gotten both dependent configs from C.
141 ASSERT_EQ(2u, b.configs().size()); 141 ASSERT_EQ(2u, b.configs().size());
142 EXPECT_EQ(&all, b.configs()[0]); 142 EXPECT_EQ(&all, b.configs()[0].ptr);
143 EXPECT_EQ(&direct, b.configs()[1]); 143 EXPECT_EQ(&direct, b.configs()[1].ptr);
144 ASSERT_EQ(1u, b.all_dependent_configs().size()); 144 ASSERT_EQ(1u, b.all_dependent_configs().size());
145 EXPECT_EQ(&all, b.all_dependent_configs()[0]); 145 EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr);
146 146
147 // A should have just gotten the "all" dependent config from C. 147 // A should have just gotten the "all" dependent config from C.
148 ASSERT_EQ(1u, a.configs().size()); 148 ASSERT_EQ(1u, a.configs().size());
149 EXPECT_EQ(&all, a.configs()[0]); 149 EXPECT_EQ(&all, a.configs()[0].ptr);
150 EXPECT_EQ(&all, a.all_dependent_configs()[0]); 150 EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr);
151 151
152 // Making an an alternate A and B with B forwarding the direct dependents. 152 // Making an an alternate A and B with B forwarding the direct dependents.
153 Target a_fwd(&settings_, Label(SourceDir("//foo/"), "a_fwd")); 153 Target a_fwd(&settings_, Label(SourceDir("//foo/"), "a_fwd"));
154 a_fwd.set_output_type(Target::EXECUTABLE); 154 a_fwd.set_output_type(Target::EXECUTABLE);
155 Target b_fwd(&settings_, Label(SourceDir("//foo/"), "b_fwd")); 155 Target b_fwd(&settings_, Label(SourceDir("//foo/"), "b_fwd"));
156 b_fwd.set_output_type(Target::STATIC_LIBRARY); 156 b_fwd.set_output_type(Target::STATIC_LIBRARY);
157 a_fwd.deps().push_back(&b_fwd); 157 a_fwd.deps().push_back(LabelTargetPair(&b_fwd));
158 b_fwd.deps().push_back(&c); 158 b_fwd.deps().push_back(LabelTargetPair(&c));
159 b_fwd.forward_dependent_configs().push_back(&c); 159 b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c));
160 160
161 b_fwd.OnResolved(); 161 b_fwd.OnResolved();
162 a_fwd.OnResolved(); 162 a_fwd.OnResolved();
163 163
164 // A_fwd should now have both configs. 164 // A_fwd should now have both configs.
165 ASSERT_EQ(2u, a_fwd.configs().size()); 165 ASSERT_EQ(2u, a_fwd.configs().size());
166 EXPECT_EQ(&all, a_fwd.configs()[0]); 166 EXPECT_EQ(&all, a_fwd.configs()[0].ptr);
167 EXPECT_EQ(&direct, a_fwd.configs()[1]); 167 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr);
168 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); 168 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size());
169 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0]); 169 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr);
170 } 170 }
OLDNEW
« no previous file with comments | « tools/gn/target_generator.cc ('k') | tools/gn/value_extractors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698