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 <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 25 matching lines...) Loading... |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 // Tests an exe depending on different types of libraries. | 41 // Tests an exe depending on different types of libraries. |
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) -> static library |
47 // -> shared | 47 // -> shared library |
48 // -> set | 48 // -> loadable module |
| 49 // -> source set |
49 | 50 |
50 Target stat(setup.settings(), Label(SourceDir("//"), "stat")); | 51 Target stat(setup.settings(), Label(SourceDir("//"), "stat")); |
51 InitTargetWithType(setup, &stat, Target::STATIC_LIBRARY); | 52 InitTargetWithType(setup, &stat, Target::STATIC_LIBRARY); |
52 stat.data().push_back("//stat.dat"); | 53 stat.data().push_back("//stat.dat"); |
53 ASSERT_TRUE(stat.OnResolved(&err)); | 54 ASSERT_TRUE(stat.OnResolved(&err)); |
54 | 55 |
55 Target shared(setup.settings(), Label(SourceDir("//"), "shared")); | 56 Target shared(setup.settings(), Label(SourceDir("//"), "shared")); |
56 InitTargetWithType(setup, &shared, Target::SHARED_LIBRARY); | 57 InitTargetWithType(setup, &shared, Target::SHARED_LIBRARY); |
57 shared.data().push_back("//shared.dat"); | 58 shared.data().push_back("//shared.dat"); |
58 ASSERT_TRUE(shared.OnResolved(&err)); | 59 ASSERT_TRUE(shared.OnResolved(&err)); |
59 | 60 |
| 61 Target loadable(setup.settings(), Label(SourceDir("//"), "loadable")); |
| 62 InitTargetWithType(setup, &loadable, Target::LOADABLE_MODULE); |
| 63 loadable.data().push_back("//loadable.dat"); |
| 64 ASSERT_TRUE(loadable.OnResolved(&err)); |
| 65 |
60 Target set(setup.settings(), Label(SourceDir("//"), "set")); | 66 Target set(setup.settings(), Label(SourceDir("//"), "set")); |
61 InitTargetWithType(setup, &set, Target::SOURCE_SET); | 67 InitTargetWithType(setup, &set, Target::SOURCE_SET); |
62 set.data().push_back("//set.dat"); | 68 set.data().push_back("//set.dat"); |
63 ASSERT_TRUE(set.OnResolved(&err)); | 69 ASSERT_TRUE(set.OnResolved(&err)); |
64 | 70 |
65 Target main(setup.settings(), Label(SourceDir("//"), "main")); | 71 Target main(setup.settings(), Label(SourceDir("//"), "main")); |
66 InitTargetWithType(setup, &main, Target::EXECUTABLE); | 72 InitTargetWithType(setup, &main, Target::EXECUTABLE); |
67 main.private_deps().push_back(LabelTargetPair(&stat)); | 73 main.private_deps().push_back(LabelTargetPair(&stat)); |
68 main.private_deps().push_back(LabelTargetPair(&shared)); | 74 main.private_deps().push_back(LabelTargetPair(&shared)); |
| 75 main.private_deps().push_back(LabelTargetPair(&loadable)); |
69 main.private_deps().push_back(LabelTargetPair(&set)); | 76 main.private_deps().push_back(LabelTargetPair(&set)); |
70 main.data().push_back("//main.dat"); | 77 main.data().push_back("//main.dat"); |
71 ASSERT_TRUE(main.OnResolved(&err)); | 78 ASSERT_TRUE(main.OnResolved(&err)); |
72 | 79 |
73 std::vector<std::pair<OutputFile, const Target*>> result = | 80 std::vector<std::pair<OutputFile, const Target*>> result = |
74 ComputeRuntimeDeps(&main); | 81 ComputeRuntimeDeps(&main); |
75 | 82 |
76 // The result should have deps of main, all 4 dat files, and libshared.so | 83 // The result should have deps of main, all 5 dat files, libshared.so, and |
77 ASSERT_EQ(6u, result.size()) << GetVectorDescription(result); | 84 // libloadable.so. |
| 85 ASSERT_EQ(8u, result.size()) << GetVectorDescription(result); |
78 | 86 |
79 // The first one should always be the main exe. | 87 // The first one should always be the main exe. |
80 EXPECT_TRUE(MakePair("./main", &main) == result[0]); | 88 EXPECT_TRUE(MakePair("./main", &main) == result[0]); |
81 | 89 |
82 // The rest of the ordering is undefined. First the data files. | 90 // The rest of the ordering is undefined. First the data files. |
83 EXPECT_TRUE(std::find(result.begin(), result.end(), | 91 EXPECT_TRUE(std::find(result.begin(), result.end(), |
84 MakePair("../../stat.dat", &stat)) != | 92 MakePair("../../stat.dat", &stat)) != |
85 result.end()) << GetVectorDescription(result); | 93 result.end()) << GetVectorDescription(result); |
86 EXPECT_TRUE(std::find(result.begin(), result.end(), | 94 EXPECT_TRUE(std::find(result.begin(), result.end(), |
87 MakePair("../../shared.dat", &shared)) != | 95 MakePair("../../shared.dat", &shared)) != |
88 result.end()) << GetVectorDescription(result); | 96 result.end()) << GetVectorDescription(result); |
89 EXPECT_TRUE(std::find(result.begin(), result.end(), | 97 EXPECT_TRUE(std::find(result.begin(), result.end(), |
| 98 MakePair("../../loadable.dat", &loadable)) != |
| 99 result.end()) << GetVectorDescription(result); |
| 100 EXPECT_TRUE(std::find(result.begin(), result.end(), |
90 MakePair("../../set.dat", &set)) != | 101 MakePair("../../set.dat", &set)) != |
91 result.end()) << GetVectorDescription(result); | 102 result.end()) << GetVectorDescription(result); |
92 EXPECT_TRUE(std::find(result.begin(), result.end(), | 103 EXPECT_TRUE(std::find(result.begin(), result.end(), |
93 MakePair("../../main.dat", &main)) != | 104 MakePair("../../main.dat", &main)) != |
94 result.end()) << GetVectorDescription(result); | 105 result.end()) << GetVectorDescription(result); |
95 | 106 |
96 // Check the static library | 107 // Check the static library and loadable module. |
97 EXPECT_TRUE(std::find(result.begin(), result.end(), | 108 EXPECT_TRUE(std::find(result.begin(), result.end(), |
98 MakePair("./libshared.so", &shared)) != | 109 MakePair("./libshared.so", &shared)) != |
99 result.end()) << GetVectorDescription(result); | 110 result.end()) << GetVectorDescription(result); |
| 111 EXPECT_TRUE(std::find(result.begin(), result.end(), |
| 112 MakePair("./libloadable.so", &loadable)) != |
| 113 result.end()) << GetVectorDescription(result); |
100 } | 114 } |
101 | 115 |
102 // Tests that executables that aren't listed as data deps aren't included in | 116 // Tests that executables that aren't listed as data deps aren't included in |
103 // the output, but executables that are data deps are included. | 117 // the output, but executables that are data deps are included. |
104 TEST(RuntimeDeps, ExeDataDep) { | 118 TEST(RuntimeDeps, ExeDataDep) { |
105 TestWithScope setup; | 119 TestWithScope setup; |
106 Err err; | 120 Err err; |
107 | 121 |
108 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set) | 122 // Dependency hierarchy: main(exe) -> datadep(exe) -> final_in(source set) |
109 // -> dep(exe) -> final_out(source set) | 123 // -> dep(exe) -> final_out(source set) |
(...skipping 149 matching lines...) Loading... |
259 target.data_deps().push_back(LabelTargetPair(&action)); | 273 target.data_deps().push_back(LabelTargetPair(&action)); |
260 ASSERT_TRUE(target.OnResolved(&err)); | 274 ASSERT_TRUE(target.OnResolved(&err)); |
261 | 275 |
262 // The results should be the executable and the copy output. | 276 // The results should be the executable and the copy output. |
263 std::vector<std::pair<OutputFile, const Target*>> result = | 277 std::vector<std::pair<OutputFile, const Target*>> result = |
264 ComputeRuntimeDeps(&target); | 278 ComputeRuntimeDeps(&target); |
265 EXPECT_TRUE(std::find(result.begin(), result.end(), | 279 EXPECT_TRUE(std::find(result.begin(), result.end(), |
266 MakePair("../../action.output", &action)) != | 280 MakePair("../../action.output", &action)) != |
267 result.end()) << GetVectorDescription(result); | 281 result.end()) << GetVectorDescription(result); |
268 } | 282 } |
OLD | NEW |