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

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

Issue 1155303008: Allow directories for GN data lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@path
Patch Set: add dir test Created 5 years, 6 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
« no previous file with comments | « tools/gn/runtime_deps.cc ('k') | tools/gn/target.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "tools/gn/runtime_deps.h" 8 #include "tools/gn/runtime_deps.h"
9 #include "tools/gn/target.h" 9 #include "tools/gn/target.h"
10 #include "tools/gn/test_with_scope.h" 10 #include "tools/gn/test_with_scope.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 TEST(RuntimeDeps, Libs) { 42 TEST(RuntimeDeps, Libs) {
43 TestWithScope setup; 43 TestWithScope setup;
44 Err err; 44 Err err;
45 45
46 // Dependency hierarchy: main(exe) -> stat 46 // Dependency hierarchy: main(exe) -> stat
47 // -> shared 47 // -> shared
48 // -> set 48 // -> set
49 49
50 Target stat(setup.settings(), Label(SourceDir("//"), "stat")); 50 Target stat(setup.settings(), Label(SourceDir("//"), "stat"));
51 InitTargetWithType(setup, &stat, Target::STATIC_LIBRARY); 51 InitTargetWithType(setup, &stat, Target::STATIC_LIBRARY);
52 stat.data().push_back(SourceFile("//stat.dat")); 52 stat.data().push_back("//stat.dat");
53 ASSERT_TRUE(stat.OnResolved(&err)); 53 ASSERT_TRUE(stat.OnResolved(&err));
54 54
55 Target shared(setup.settings(), Label(SourceDir("//"), "shared")); 55 Target shared(setup.settings(), Label(SourceDir("//"), "shared"));
56 InitTargetWithType(setup, &shared, Target::SHARED_LIBRARY); 56 InitTargetWithType(setup, &shared, Target::SHARED_LIBRARY);
57 shared.data().push_back(SourceFile("//shared.dat")); 57 shared.data().push_back("//shared.dat");
58 ASSERT_TRUE(shared.OnResolved(&err)); 58 ASSERT_TRUE(shared.OnResolved(&err));
59 59
60 Target set(setup.settings(), Label(SourceDir("//"), "set")); 60 Target set(setup.settings(), Label(SourceDir("//"), "set"));
61 InitTargetWithType(setup, &set, Target::SOURCE_SET); 61 InitTargetWithType(setup, &set, Target::SOURCE_SET);
62 set.data().push_back(SourceFile("//set.dat")); 62 set.data().push_back("//set.dat");
63 ASSERT_TRUE(set.OnResolved(&err)); 63 ASSERT_TRUE(set.OnResolved(&err));
64 64
65 Target main(setup.settings(), Label(SourceDir("//"), "main")); 65 Target main(setup.settings(), Label(SourceDir("//"), "main"));
66 InitTargetWithType(setup, &main, Target::EXECUTABLE); 66 InitTargetWithType(setup, &main, Target::EXECUTABLE);
67 main.private_deps().push_back(LabelTargetPair(&stat)); 67 main.private_deps().push_back(LabelTargetPair(&stat));
68 main.private_deps().push_back(LabelTargetPair(&shared)); 68 main.private_deps().push_back(LabelTargetPair(&shared));
69 main.private_deps().push_back(LabelTargetPair(&set)); 69 main.private_deps().push_back(LabelTargetPair(&set));
70 main.data().push_back(SourceFile("//main.dat")); 70 main.data().push_back("//main.dat");
71 ASSERT_TRUE(main.OnResolved(&err)); 71 ASSERT_TRUE(main.OnResolved(&err));
72 72
73 std::vector<std::pair<OutputFile, const Target*>> result = 73 std::vector<std::pair<OutputFile, const Target*>> result =
74 ComputeRuntimeDeps(&main); 74 ComputeRuntimeDeps(&main);
75 75
76 // The result should have deps of main, all 4 dat files, and libshared.so 76 // The result should have deps of main, all 4 dat files, and libshared.so
77 ASSERT_EQ(6u, result.size()) << GetVectorDescription(result); 77 ASSERT_EQ(6u, result.size()) << GetVectorDescription(result);
78 78
79 // The first one should always be the main exe. 79 // The first one should always be the main exe.
80 EXPECT_TRUE(MakePair("./main", &main) == result[0]); 80 EXPECT_TRUE(MakePair("./main", &main) == result[0]);
(...skipping 24 matching lines...) Expand all
105 TestWithScope setup; 105 TestWithScope setup;
106 Err err; 106 Err err;
107 107
108 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set) 108 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set)
109 // -> dep(exe) -> final_out(source set) 109 // -> dep(exe) -> final_out(source set)
110 // The final_in/out targets each have data files. final_in's should be 110 // The final_in/out targets each have data files. final_in's should be
111 // included, final_out's should not be. 111 // included, final_out's should not be.
112 112
113 Target final_in(setup.settings(), Label(SourceDir("//"), "final_in")); 113 Target final_in(setup.settings(), Label(SourceDir("//"), "final_in"));
114 InitTargetWithType(setup, &final_in, Target::SOURCE_SET); 114 InitTargetWithType(setup, &final_in, Target::SOURCE_SET);
115 final_in.data().push_back(SourceFile("//final_in.dat")); 115 final_in.data().push_back("//final_in.dat");
116 ASSERT_TRUE(final_in.OnResolved(&err)); 116 ASSERT_TRUE(final_in.OnResolved(&err));
117 117
118 Target datadep(setup.settings(), Label(SourceDir("//"), "datadep")); 118 Target datadep(setup.settings(), Label(SourceDir("//"), "datadep"));
119 InitTargetWithType(setup, &datadep, Target::EXECUTABLE); 119 InitTargetWithType(setup, &datadep, Target::EXECUTABLE);
120 datadep.private_deps().push_back(LabelTargetPair(&final_in)); 120 datadep.private_deps().push_back(LabelTargetPair(&final_in));
121 ASSERT_TRUE(datadep.OnResolved(&err)); 121 ASSERT_TRUE(datadep.OnResolved(&err));
122 122
123 Target final_out(setup.settings(), Label(SourceDir("//"), "final_out")); 123 Target final_out(setup.settings(), Label(SourceDir("//"), "final_out"));
124 InitTargetWithType(setup, &final_out, Target::SOURCE_SET); 124 InitTargetWithType(setup, &final_out, Target::SOURCE_SET);
125 final_out.data().push_back(SourceFile("//final_out.dat")); 125 final_out.data().push_back("//final_out.dat");
126 ASSERT_TRUE(final_out.OnResolved(&err)); 126 ASSERT_TRUE(final_out.OnResolved(&err));
127 127
128 Target dep(setup.settings(), Label(SourceDir("//"), "dep")); 128 Target dep(setup.settings(), Label(SourceDir("//"), "dep"));
129 InitTargetWithType(setup, &dep, Target::EXECUTABLE); 129 InitTargetWithType(setup, &dep, Target::EXECUTABLE);
130 dep.private_deps().push_back(LabelTargetPair(&final_out)); 130 dep.private_deps().push_back(LabelTargetPair(&final_out));
131 ASSERT_TRUE(dep.OnResolved(&err)); 131 ASSERT_TRUE(dep.OnResolved(&err));
132 132
133 Target main(setup.settings(), Label(SourceDir("//"), "main")); 133 Target main(setup.settings(), Label(SourceDir("//"), "main"));
134 InitTargetWithType(setup, &main, Target::EXECUTABLE); 134 InitTargetWithType(setup, &main, Target::EXECUTABLE);
135 main.private_deps().push_back(LabelTargetPair(&dep)); 135 main.private_deps().push_back(LabelTargetPair(&dep));
(...skipping 25 matching lines...) Expand all
161 TestWithScope setup; 161 TestWithScope setup;
162 Err err; 162 Err err;
163 163
164 // Dependency hierarchy: main(exe) -> datadep (action) 164 // Dependency hierarchy: main(exe) -> datadep (action)
165 // -> datadep_copy (copy) 165 // -> datadep_copy (copy)
166 // -> dep (action) 166 // -> dep (action)
167 // -> dep_copy (copy) 167 // -> dep_copy (copy)
168 168
169 Target datadep(setup.settings(), Label(SourceDir("//"), "datadep")); 169 Target datadep(setup.settings(), Label(SourceDir("//"), "datadep"));
170 InitTargetWithType(setup, &datadep, Target::ACTION); 170 InitTargetWithType(setup, &datadep, Target::ACTION);
171 datadep.data().push_back(SourceFile("//datadep.data")); 171 datadep.data().push_back("//datadep.data");
172 datadep.action_values().outputs() = 172 datadep.action_values().outputs() =
173 SubstitutionList::MakeForTest("//datadep.output"); 173 SubstitutionList::MakeForTest("//datadep.output");
174 ASSERT_TRUE(datadep.OnResolved(&err)); 174 ASSERT_TRUE(datadep.OnResolved(&err));
175 175
176 Target datadep_copy(setup.settings(), Label(SourceDir("//"), "datadep_copy")); 176 Target datadep_copy(setup.settings(), Label(SourceDir("//"), "datadep_copy"));
177 InitTargetWithType(setup, &datadep_copy, Target::COPY_FILES); 177 InitTargetWithType(setup, &datadep_copy, Target::COPY_FILES);
178 datadep_copy.sources().push_back(SourceFile("//input")); 178 datadep_copy.sources().push_back(SourceFile("//input"));
179 datadep_copy.data().push_back(SourceFile("//datadep_copy.data")); 179 datadep_copy.data().push_back("//datadep_copy.data");
180 datadep_copy.action_values().outputs() = 180 datadep_copy.action_values().outputs() =
181 SubstitutionList::MakeForTest("//datadep_copy.output"); 181 SubstitutionList::MakeForTest("//datadep_copy.output");
182 ASSERT_TRUE(datadep_copy.OnResolved(&err)); 182 ASSERT_TRUE(datadep_copy.OnResolved(&err));
183 183
184 Target dep(setup.settings(), Label(SourceDir("//"), "dep")); 184 Target dep(setup.settings(), Label(SourceDir("//"), "dep"));
185 InitTargetWithType(setup, &dep, Target::ACTION); 185 InitTargetWithType(setup, &dep, Target::ACTION);
186 dep.data().push_back(SourceFile("//dep.data")); 186 dep.data().push_back("//dep.data");
187 dep.action_values().outputs() = 187 dep.action_values().outputs() =
188 SubstitutionList::MakeForTest("//dep.output"); 188 SubstitutionList::MakeForTest("//dep.output");
189 ASSERT_TRUE(dep.OnResolved(&err)); 189 ASSERT_TRUE(dep.OnResolved(&err));
190 190
191 Target dep_copy(setup.settings(), Label(SourceDir("//"), "dep_copy")); 191 Target dep_copy(setup.settings(), Label(SourceDir("//"), "dep_copy"));
192 InitTargetWithType(setup, &dep_copy, Target::COPY_FILES); 192 InitTargetWithType(setup, &dep_copy, Target::COPY_FILES);
193 dep_copy.sources().push_back(SourceFile("//input")); 193 dep_copy.sources().push_back(SourceFile("//input"));
194 dep_copy.data().push_back(SourceFile("//dep_copy.data")); 194 dep_copy.data().push_back("//dep_copy/data/"); // Tests a directory.
195 dep_copy.action_values().outputs() = 195 dep_copy.action_values().outputs() =
196 SubstitutionList::MakeForTest("//dep_copy.output"); 196 SubstitutionList::MakeForTest("//dep_copy.output");
197 ASSERT_TRUE(dep_copy.OnResolved(&err)); 197 ASSERT_TRUE(dep_copy.OnResolved(&err));
198 198
199 Target main(setup.settings(), Label(SourceDir("//"), "main")); 199 Target main(setup.settings(), Label(SourceDir("//"), "main"));
200 InitTargetWithType(setup, &main, Target::EXECUTABLE); 200 InitTargetWithType(setup, &main, Target::EXECUTABLE);
201 main.private_deps().push_back(LabelTargetPair(&dep)); 201 main.private_deps().push_back(LabelTargetPair(&dep));
202 main.private_deps().push_back(LabelTargetPair(&dep_copy)); 202 main.private_deps().push_back(LabelTargetPair(&dep_copy));
203 main.data_deps().push_back(LabelTargetPair(&datadep)); 203 main.data_deps().push_back(LabelTargetPair(&datadep));
204 main.data_deps().push_back(LabelTargetPair(&datadep_copy)); 204 main.data_deps().push_back(LabelTargetPair(&datadep_copy));
(...skipping 19 matching lines...) Expand all
224 EXPECT_TRUE(std::find(result.begin(), result.end(), 224 EXPECT_TRUE(std::find(result.begin(), result.end(),
225 MakePair("../../datadep.output", &datadep)) != 225 MakePair("../../datadep.output", &datadep)) !=
226 result.end()) << GetVectorDescription(result); 226 result.end()) << GetVectorDescription(result);
227 EXPECT_TRUE(std::find(result.begin(), result.end(), 227 EXPECT_TRUE(std::find(result.begin(), result.end(),
228 MakePair("../../datadep_copy.output", &datadep_copy)) != 228 MakePair("../../datadep_copy.output", &datadep_copy)) !=
229 result.end()) << GetVectorDescription(result); 229 result.end()) << GetVectorDescription(result);
230 EXPECT_TRUE(std::find(result.begin(), result.end(), 230 EXPECT_TRUE(std::find(result.begin(), result.end(),
231 MakePair("../../dep.data", &dep)) != 231 MakePair("../../dep.data", &dep)) !=
232 result.end()) << GetVectorDescription(result); 232 result.end()) << GetVectorDescription(result);
233 EXPECT_TRUE(std::find(result.begin(), result.end(), 233 EXPECT_TRUE(std::find(result.begin(), result.end(),
234 MakePair("../../dep_copy.data", &dep_copy)) != 234 MakePair("../../dep_copy/data/", &dep_copy)) !=
235 result.end()) << GetVectorDescription(result); 235 result.end()) << GetVectorDescription(result);
236 236
237 // Explicitly asking for the runtime deps of an action target only includes 237 // Explicitly asking for the runtime deps of an action target only includes
238 // the data and not all outputs. 238 // the data and not all outputs.
239 result = ComputeRuntimeDeps(&dep); 239 result = ComputeRuntimeDeps(&dep);
240 ASSERT_EQ(1u, result.size()); 240 ASSERT_EQ(1u, result.size());
241 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]); 241 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]);
242 } 242 }
OLDNEW
« no previous file with comments | « tools/gn/runtime_deps.cc ('k') | tools/gn/target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698