OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include "base/stl_util.h" |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/runtime_deps.h" | 9 #include "tools/gn/runtime_deps.h" |
11 #include "tools/gn/scheduler.h" | 10 #include "tools/gn/scheduler.h" |
12 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
13 #include "tools/gn/test_with_scope.h" | 12 #include "tools/gn/test_with_scope.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 void InitTargetWithType(TestWithScope& setup, | 16 void InitTargetWithType(TestWithScope& setup, |
18 Target* target, | 17 Target* target, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ComputeRuntimeDeps(&main); | 83 ComputeRuntimeDeps(&main); |
85 | 84 |
86 // The result should have deps of main, all 5 dat files, libshared.so, and | 85 // The result should have deps of main, all 5 dat files, libshared.so, and |
87 // libloadable.so. | 86 // libloadable.so. |
88 ASSERT_EQ(8u, result.size()) << GetVectorDescription(result); | 87 ASSERT_EQ(8u, result.size()) << GetVectorDescription(result); |
89 | 88 |
90 // The first one should always be the main exe. | 89 // The first one should always be the main exe. |
91 EXPECT_TRUE(MakePair("./main", &main) == result[0]); | 90 EXPECT_TRUE(MakePair("./main", &main) == result[0]); |
92 | 91 |
93 // The rest of the ordering is undefined. First the data files. | 92 // The rest of the ordering is undefined. First the data files. |
94 EXPECT_TRUE(std::find(result.begin(), result.end(), | 93 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../stat.dat", &stat))) |
95 MakePair("../../stat.dat", &stat)) != | 94 << GetVectorDescription(result); |
96 result.end()) << GetVectorDescription(result); | 95 EXPECT_TRUE( |
97 EXPECT_TRUE(std::find(result.begin(), result.end(), | 96 base::ContainsValue(result, MakePair("../../shared.dat", &shared))) |
98 MakePair("../../shared.dat", &shared)) != | 97 << GetVectorDescription(result); |
99 result.end()) << GetVectorDescription(result); | 98 EXPECT_TRUE( |
100 EXPECT_TRUE(std::find(result.begin(), result.end(), | 99 base::ContainsValue(result, MakePair("../../loadable.dat", &loadable))) |
101 MakePair("../../loadable.dat", &loadable)) != | 100 << GetVectorDescription(result); |
102 result.end()) << GetVectorDescription(result); | 101 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../set.dat", &set))) |
103 EXPECT_TRUE(std::find(result.begin(), result.end(), | 102 << GetVectorDescription(result); |
104 MakePair("../../set.dat", &set)) != | 103 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../main.dat", &main))) |
105 result.end()) << GetVectorDescription(result); | 104 << GetVectorDescription(result); |
106 EXPECT_TRUE(std::find(result.begin(), result.end(), | |
107 MakePair("../../main.dat", &main)) != | |
108 result.end()) << GetVectorDescription(result); | |
109 | 105 |
110 // Check the static library and loadable module. | 106 // Check the static library and loadable module. |
111 EXPECT_TRUE(std::find(result.begin(), result.end(), | 107 EXPECT_TRUE(base::ContainsValue(result, MakePair("./libshared.so", &shared))) |
112 MakePair("./libshared.so", &shared)) != | 108 << GetVectorDescription(result); |
113 result.end()) << GetVectorDescription(result); | 109 EXPECT_TRUE( |
114 EXPECT_TRUE(std::find(result.begin(), result.end(), | 110 base::ContainsValue(result, MakePair("./libloadable.so", &loadable))) |
115 MakePair("./libloadable.so", &loadable)) != | 111 << GetVectorDescription(result); |
116 result.end()) << GetVectorDescription(result); | |
117 } | 112 } |
118 | 113 |
119 // Tests that executables that aren't listed as data deps aren't included in | 114 // Tests that executables that aren't listed as data deps aren't included in |
120 // the output, but executables that are data deps are included. | 115 // the output, but executables that are data deps are included. |
121 TEST(RuntimeDeps, ExeDataDep) { | 116 TEST(RuntimeDeps, ExeDataDep) { |
122 TestWithScope setup; | 117 TestWithScope setup; |
123 Err err; | 118 Err err; |
124 | 119 |
125 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set) | 120 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set) |
126 // -> dep(exe) -> final_out(source set) | 121 // -> dep(exe) -> final_out(source set) |
(...skipping 29 matching lines...) Expand all Loading... |
156 std::vector<std::pair<OutputFile, const Target*>> result = | 151 std::vector<std::pair<OutputFile, const Target*>> result = |
157 ComputeRuntimeDeps(&main); | 152 ComputeRuntimeDeps(&main); |
158 | 153 |
159 // The result should have deps of main, datadep, final_in.dat | 154 // The result should have deps of main, datadep, final_in.dat |
160 ASSERT_EQ(3u, result.size()) << GetVectorDescription(result); | 155 ASSERT_EQ(3u, result.size()) << GetVectorDescription(result); |
161 | 156 |
162 // The first one should always be the main exe. | 157 // The first one should always be the main exe. |
163 EXPECT_TRUE(MakePair("./main", &main) == result[0]); | 158 EXPECT_TRUE(MakePair("./main", &main) == result[0]); |
164 | 159 |
165 // The rest of the ordering is undefined. | 160 // The rest of the ordering is undefined. |
166 EXPECT_TRUE(std::find(result.begin(), result.end(), | 161 EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &datadep))) |
167 MakePair("./datadep", &datadep)) != | 162 << GetVectorDescription(result); |
168 result.end()) << GetVectorDescription(result); | 163 EXPECT_TRUE( |
169 EXPECT_TRUE(std::find(result.begin(), result.end(), | 164 base::ContainsValue(result, MakePair("../../final_in.dat", &final_in))) |
170 MakePair("../../final_in.dat", &final_in)) != | 165 << GetVectorDescription(result); |
171 result.end()) << GetVectorDescription(result); | |
172 } | 166 } |
173 | 167 |
174 // Tests that action and copy outputs are considered if they're data deps, but | 168 // Tests that action and copy outputs are considered if they're data deps, but |
175 // not if they're regular deps. Action and copy "data" files are always | 169 // not if they're regular deps. Action and copy "data" files are always |
176 // included. | 170 // included. |
177 TEST(RuntimeDeps, ActionOutputs) { | 171 TEST(RuntimeDeps, ActionOutputs) { |
178 TestWithScope setup; | 172 TestWithScope setup; |
179 Err err; | 173 Err err; |
180 | 174 |
181 // Dependency hierarchy: main(exe) -> datadep (action) | 175 // Dependency hierarchy: main(exe) -> datadep (action) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ComputeRuntimeDeps(&main); | 219 ComputeRuntimeDeps(&main); |
226 | 220 |
227 // The result should have deps of main, both datadeps files, but only | 221 // The result should have deps of main, both datadeps files, but only |
228 // the data file from dep. | 222 // the data file from dep. |
229 ASSERT_EQ(7u, result.size()) << GetVectorDescription(result); | 223 ASSERT_EQ(7u, result.size()) << GetVectorDescription(result); |
230 | 224 |
231 // The first one should always be the main exe. | 225 // The first one should always be the main exe. |
232 EXPECT_TRUE(MakePair("./main", &main) == result[0]); | 226 EXPECT_TRUE(MakePair("./main", &main) == result[0]); |
233 | 227 |
234 // The rest of the ordering is undefined. | 228 // The rest of the ordering is undefined. |
235 EXPECT_TRUE(std::find(result.begin(), result.end(), | 229 EXPECT_TRUE( |
236 MakePair("../../datadep.data", &datadep)) != | 230 base::ContainsValue(result, MakePair("../../datadep.data", &datadep))) |
237 result.end()) << GetVectorDescription(result); | 231 << GetVectorDescription(result); |
238 EXPECT_TRUE(std::find(result.begin(), result.end(), | 232 EXPECT_TRUE(base::ContainsValue( |
239 MakePair("../../datadep_copy.data", &datadep_copy)) != | 233 result, MakePair("../../datadep_copy.data", &datadep_copy))) |
240 result.end()) << GetVectorDescription(result); | 234 << GetVectorDescription(result); |
241 EXPECT_TRUE(std::find(result.begin(), result.end(), | 235 EXPECT_TRUE( |
242 MakePair("../../datadep.output", &datadep)) != | 236 base::ContainsValue(result, MakePair("../../datadep.output", &datadep))) |
243 result.end()) << GetVectorDescription(result); | 237 << GetVectorDescription(result); |
244 EXPECT_TRUE(std::find(result.begin(), result.end(), | 238 EXPECT_TRUE(base::ContainsValue( |
245 MakePair("../../datadep_copy.output", &datadep_copy)) != | 239 result, MakePair("../../datadep_copy.output", &datadep_copy))) |
246 result.end()) << GetVectorDescription(result); | 240 << GetVectorDescription(result); |
247 EXPECT_TRUE(std::find(result.begin(), result.end(), | 241 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dep.data", &dep))) |
248 MakePair("../../dep.data", &dep)) != | 242 << GetVectorDescription(result); |
249 result.end()) << GetVectorDescription(result); | 243 EXPECT_TRUE( |
250 EXPECT_TRUE(std::find(result.begin(), result.end(), | 244 base::ContainsValue(result, MakePair("../../dep_copy/data/", &dep_copy))) |
251 MakePair("../../dep_copy/data/", &dep_copy)) != | 245 << GetVectorDescription(result); |
252 result.end()) << GetVectorDescription(result); | |
253 | 246 |
254 // Explicitly asking for the runtime deps of an action target only includes | 247 // Explicitly asking for the runtime deps of an action target only includes |
255 // the data and not all outputs. | 248 // the data and not all outputs. |
256 result = ComputeRuntimeDeps(&dep); | 249 result = ComputeRuntimeDeps(&dep); |
257 ASSERT_EQ(1u, result.size()); | 250 ASSERT_EQ(1u, result.size()); |
258 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]); | 251 EXPECT_TRUE(MakePair("../../dep.data", &dep) == result[0]); |
259 } | 252 } |
260 | 253 |
261 // Tests that the search for dependencies terminates at a bundle target, | 254 // Tests that the search for dependencies terminates at a bundle target, |
262 // ignoring any shared libraries or loadable modules that get copied into the | 255 // ignoring any shared libraries or loadable modules that get copied into the |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 330 |
338 // The result should have deps of main, datadep, final_in.dat | 331 // The result should have deps of main, datadep, final_in.dat |
339 ASSERT_EQ(5u, result.size()) << GetVectorDescription(result); | 332 ASSERT_EQ(5u, result.size()) << GetVectorDescription(result); |
340 | 333 |
341 // The first one should always be the main exe. | 334 // The first one should always be the main exe. |
342 EXPECT_EQ(MakePair("./main", &main), result[0]); | 335 EXPECT_EQ(MakePair("./main", &main), result[0]); |
343 | 336 |
344 // The rest of the ordering is undefined. | 337 // The rest of the ordering is undefined. |
345 | 338 |
346 // The framework bundle's internal dependencies should not be incldued. | 339 // The framework bundle's internal dependencies should not be incldued. |
347 EXPECT_TRUE(std::find(result.begin(), result.end(), | 340 EXPECT_TRUE( |
348 MakePair("Bundle.framework/", &bundle)) != | 341 base::ContainsValue(result, MakePair("Bundle.framework/", &bundle))) |
349 result.end()) << GetVectorDescription(result); | 342 << GetVectorDescription(result); |
350 // But direct data and data dependencies should be. | 343 // But direct data and data dependencies should be. |
351 EXPECT_TRUE(std::find(result.begin(), result.end(), | 344 EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &data_dep))) |
352 MakePair("./datadep", &data_dep)) != | 345 << GetVectorDescription(result); |
353 result.end()) << GetVectorDescription(result); | 346 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dd.data", &data_dep))) |
354 EXPECT_TRUE(std::find(result.begin(), result.end(), | 347 << GetVectorDescription(result); |
355 MakePair("../../dd.data", &data_dep)) != | 348 EXPECT_TRUE(base::ContainsValue(result, MakePair("../../b.data", &bundle))) |
356 result.end()) << GetVectorDescription(result); | 349 << GetVectorDescription(result); |
357 EXPECT_TRUE(std::find(result.begin(), result.end(), | |
358 MakePair("../../b.data", &bundle)) != | |
359 result.end()) << GetVectorDescription(result); | |
360 } | 350 } |
361 | 351 |
362 // Tests that a dependency duplicated in regular and data deps is processed | 352 // Tests that a dependency duplicated in regular and data deps is processed |
363 // as a data dep. | 353 // as a data dep. |
364 TEST(RuntimeDeps, Dupe) { | 354 TEST(RuntimeDeps, Dupe) { |
365 TestWithScope setup; | 355 TestWithScope setup; |
366 Err err; | 356 Err err; |
367 | 357 |
368 Target action(setup.settings(), Label(SourceDir("//"), "action")); | 358 Target action(setup.settings(), Label(SourceDir("//"), "action")); |
369 InitTargetWithType(setup, &action, Target::ACTION); | 359 InitTargetWithType(setup, &action, Target::ACTION); |
370 action.action_values().outputs() = | 360 action.action_values().outputs() = |
371 SubstitutionList::MakeForTest("//action.output"); | 361 SubstitutionList::MakeForTest("//action.output"); |
372 ASSERT_TRUE(action.OnResolved(&err)); | 362 ASSERT_TRUE(action.OnResolved(&err)); |
373 | 363 |
374 Target target(setup.settings(), Label(SourceDir("//"), "foo")); | 364 Target target(setup.settings(), Label(SourceDir("//"), "foo")); |
375 InitTargetWithType(setup, &target, Target::EXECUTABLE); | 365 InitTargetWithType(setup, &target, Target::EXECUTABLE); |
376 target.private_deps().push_back(LabelTargetPair(&action)); | 366 target.private_deps().push_back(LabelTargetPair(&action)); |
377 target.data_deps().push_back(LabelTargetPair(&action)); | 367 target.data_deps().push_back(LabelTargetPair(&action)); |
378 ASSERT_TRUE(target.OnResolved(&err)); | 368 ASSERT_TRUE(target.OnResolved(&err)); |
379 | 369 |
380 // The results should be the executable and the copy output. | 370 // The results should be the executable and the copy output. |
381 std::vector<std::pair<OutputFile, const Target*>> result = | 371 std::vector<std::pair<OutputFile, const Target*>> result = |
382 ComputeRuntimeDeps(&target); | 372 ComputeRuntimeDeps(&target); |
383 EXPECT_TRUE(std::find(result.begin(), result.end(), | 373 EXPECT_TRUE( |
384 MakePair("../../action.output", &action)) != | 374 base::ContainsValue(result, MakePair("../../action.output", &action))) |
385 result.end()) << GetVectorDescription(result); | 375 << GetVectorDescription(result); |
386 } | 376 } |
387 | 377 |
388 // Tests that actions can't have output substitutions. | 378 // Tests that actions can't have output substitutions. |
389 TEST(RuntimeDeps, WriteRuntimeDepsVariable) { | 379 TEST(RuntimeDeps, WriteRuntimeDepsVariable) { |
390 Scheduler scheduler; | 380 Scheduler scheduler; |
391 TestWithScope setup; | 381 TestWithScope setup; |
392 Err err; | 382 Err err; |
393 | 383 |
394 // Should refuse to write files outside of the output dir. | 384 // Should refuse to write files outside of the output dir. |
395 EXPECT_FALSE(setup.ExecuteSnippet( | 385 EXPECT_FALSE(setup.ExecuteSnippet( |
396 "group(\"foo\") { write_runtime_deps = \"//foo.txt\" }", &err)); | 386 "group(\"foo\") { write_runtime_deps = \"//foo.txt\" }", &err)); |
397 | 387 |
398 // Should fail for garbage inputs. | 388 // Should fail for garbage inputs. |
399 err = Err(); | 389 err = Err(); |
400 EXPECT_FALSE(setup.ExecuteSnippet( | 390 EXPECT_FALSE(setup.ExecuteSnippet( |
401 "group(\"foo\") { write_runtime_deps = 0 }", &err)); | 391 "group(\"foo\") { write_runtime_deps = 0 }", &err)); |
402 | 392 |
403 // Should be able to write inside the out dir, and shouldn't write the one | 393 // Should be able to write inside the out dir, and shouldn't write the one |
404 // in the else clause. | 394 // in the else clause. |
405 err = Err(); | 395 err = Err(); |
406 EXPECT_TRUE(setup.ExecuteSnippet( | 396 EXPECT_TRUE(setup.ExecuteSnippet( |
407 "if (true) {\n" | 397 "if (true) {\n" |
408 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" | 398 " group(\"foo\") { write_runtime_deps = \"//out/Debug/foo.txt\" }\n" |
409 "} else {\n" | 399 "} else {\n" |
410 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" | 400 " group(\"bar\") { write_runtime_deps = \"//out/Debug/bar.txt\" }\n" |
411 "}", &err)); | 401 "}", &err)); |
412 EXPECT_EQ(1U, setup.items().size()); | 402 EXPECT_EQ(1U, setup.items().size()); |
413 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); | 403 EXPECT_EQ(1U, scheduler.GetWriteRuntimeDepsTargets().size()); |
414 } | 404 } |
OLD | NEW |