| OLD | NEW |
| 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/builder.h" | 6 #include "tools/gn/builder.h" |
| 7 #include "tools/gn/loader.h" | 7 #include "tools/gn/loader.h" |
| 8 #include "tools/gn/target.h" | 8 #include "tools/gn/target.h" |
| 9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
| 10 #include "tools/gn/toolchain.h" | 10 #include "tools/gn/toolchain.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // Construct a dependency chain: A -> B -> C. Define A first with a | 93 // Construct a dependency chain: A -> B -> C. Define A first with a |
| 94 // forward-reference to B, then C, then B to test the different orders that | 94 // forward-reference to B, then C, then B to test the different orders that |
| 95 // the dependencies are hooked up. | 95 // the dependencies are hooked up. |
| 96 Label a_label(SourceDir("//a/"), "a", toolchain_dir, toolchain_name); | 96 Label a_label(SourceDir("//a/"), "a", toolchain_dir, toolchain_name); |
| 97 Label b_label(SourceDir("//b/"), "b", toolchain_dir, toolchain_name); | 97 Label b_label(SourceDir("//b/"), "b", toolchain_dir, toolchain_name); |
| 98 Label c_label(SourceDir("//c/"), "c", toolchain_dir, toolchain_name); | 98 Label c_label(SourceDir("//c/"), "c", toolchain_dir, toolchain_name); |
| 99 | 99 |
| 100 // The builder will take ownership of the pointers. | 100 // The builder will take ownership of the pointers. |
| 101 Target* a = new Target(&settings_, a_label); | 101 Target* a = new Target(&settings_, a_label); |
| 102 a->deps().push_back(LabelTargetPair(b_label)); | 102 a->public_deps().push_back(LabelTargetPair(b_label)); |
| 103 a->set_output_type(Target::EXECUTABLE); | 103 a->set_output_type(Target::EXECUTABLE); |
| 104 builder_->ItemDefined(scoped_ptr<Item>(a)); | 104 builder_->ItemDefined(scoped_ptr<Item>(a)); |
| 105 | 105 |
| 106 // Should have requested that B and the toolchain is loaded. | 106 // Should have requested that B and the toolchain is loaded. |
| 107 EXPECT_TRUE(loader_->HasLoadedTwo(SourceFile("//tc/BUILD.gn"), | 107 EXPECT_TRUE(loader_->HasLoadedTwo(SourceFile("//tc/BUILD.gn"), |
| 108 SourceFile("//b/BUILD.gn"))); | 108 SourceFile("//b/BUILD.gn"))); |
| 109 | 109 |
| 110 // Define the toolchain. | 110 // Define the toolchain. |
| 111 DefineToolchain(); | 111 DefineToolchain(); |
| 112 BuilderRecord* toolchain_record = | 112 BuilderRecord* toolchain_record = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 137 EXPECT_NE(a_record->unresolved_deps().end(), | 137 EXPECT_NE(a_record->unresolved_deps().end(), |
| 138 a_record->unresolved_deps().find(b_record)); | 138 a_record->unresolved_deps().find(b_record)); |
| 139 | 139 |
| 140 // B should be marked as having A waiting on it. | 140 // B should be marked as having A waiting on it. |
| 141 EXPECT_EQ(1u, b_record->waiting_on_resolution().size()); | 141 EXPECT_EQ(1u, b_record->waiting_on_resolution().size()); |
| 142 EXPECT_NE(b_record->waiting_on_resolution().end(), | 142 EXPECT_NE(b_record->waiting_on_resolution().end(), |
| 143 b_record->waiting_on_resolution().find(a_record)); | 143 b_record->waiting_on_resolution().find(a_record)); |
| 144 | 144 |
| 145 // Add the C target. | 145 // Add the C target. |
| 146 Target* c = new Target(&settings_, c_label); | 146 Target* c = new Target(&settings_, c_label); |
| 147 c->visibility().SetPublic(); |
| 147 c->set_output_type(Target::STATIC_LIBRARY); | 148 c->set_output_type(Target::STATIC_LIBRARY); |
| 148 builder_->ItemDefined(scoped_ptr<Item>(c)); | 149 builder_->ItemDefined(scoped_ptr<Item>(c)); |
| 149 | 150 |
| 150 // C only depends on the already-loaded toolchain so we shouldn't have | 151 // C only depends on the already-loaded toolchain so we shouldn't have |
| 151 // requested anything else. | 152 // requested anything else. |
| 152 EXPECT_TRUE(loader_->HasLoadedNone()); | 153 EXPECT_TRUE(loader_->HasLoadedNone()); |
| 153 | 154 |
| 154 // Add the B target. | 155 // Add the B target. |
| 155 Target* b = new Target(&settings_, b_label); | 156 Target* b = new Target(&settings_, b_label); |
| 156 a->deps().push_back(LabelTargetPair(c_label)); | 157 b->visibility().SetPublic(); |
| 158 a->public_deps().push_back(LabelTargetPair(c_label)); |
| 157 b->set_output_type(Target::SHARED_LIBRARY); | 159 b->set_output_type(Target::SHARED_LIBRARY); |
| 158 builder_->ItemDefined(scoped_ptr<Item>(b)); | 160 builder_->ItemDefined(scoped_ptr<Item>(b)); |
| 159 | 161 |
| 160 // B depends only on the already-loaded C and toolchain so we shouldn't have | 162 // B depends only on the already-loaded C and toolchain so we shouldn't have |
| 161 // requested anything else. | 163 // requested anything else. |
| 162 EXPECT_TRUE(loader_->HasLoadedNone()); | 164 EXPECT_TRUE(loader_->HasLoadedNone()); |
| 163 | 165 |
| 164 // All targets should now be resolved. | 166 // All targets should now be resolved. |
| 165 BuilderRecord* c_record = builder_->GetRecord(c_label); | 167 BuilderRecord* c_record = builder_->GetRecord(c_label); |
| 166 EXPECT_TRUE(a_record->resolved()); | 168 EXPECT_TRUE(a_record->resolved()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 190 | 192 |
| 191 // Construct a dependency chain: A -> B. A is in the default toolchain, B | 193 // Construct a dependency chain: A -> B. A is in the default toolchain, B |
| 192 // is not. | 194 // is not. |
| 193 Label a_label(SourceDir("//foo/"), "a", | 195 Label a_label(SourceDir("//foo/"), "a", |
| 194 settings_.toolchain_label().dir(), "a"); | 196 settings_.toolchain_label().dir(), "a"); |
| 195 Label b_label(SourceDir("//foo/"), "b", | 197 Label b_label(SourceDir("//foo/"), "b", |
| 196 toolchain_label2.dir(), toolchain_label2.name()); | 198 toolchain_label2.dir(), toolchain_label2.name()); |
| 197 | 199 |
| 198 // First define B. | 200 // First define B. |
| 199 Target* b = new Target(&settings2, b_label); | 201 Target* b = new Target(&settings2, b_label); |
| 202 b->visibility().SetPublic(); |
| 200 b->set_output_type(Target::EXECUTABLE); | 203 b->set_output_type(Target::EXECUTABLE); |
| 201 builder_->ItemDefined(scoped_ptr<Item>(b)); | 204 builder_->ItemDefined(scoped_ptr<Item>(b)); |
| 202 | 205 |
| 203 // B should not be marked generated by default. | 206 // B should not be marked generated by default. |
| 204 BuilderRecord* b_record = builder_->GetRecord(b_label); | 207 BuilderRecord* b_record = builder_->GetRecord(b_label); |
| 205 EXPECT_FALSE(b_record->should_generate()); | 208 EXPECT_FALSE(b_record->should_generate()); |
| 206 | 209 |
| 207 // Define A with a dependency on B. | 210 // Define A with a dependency on B. |
| 208 Target* a = new Target(&settings_, a_label); | 211 Target* a = new Target(&settings_, a_label); |
| 209 a->deps().push_back(LabelTargetPair(b_label)); | 212 a->public_deps().push_back(LabelTargetPair(b_label)); |
| 210 a->set_output_type(Target::EXECUTABLE); | 213 a->set_output_type(Target::EXECUTABLE); |
| 211 builder_->ItemDefined(scoped_ptr<Item>(a)); | 214 builder_->ItemDefined(scoped_ptr<Item>(a)); |
| 212 | 215 |
| 213 // A should have the generate bit set since it's in the default toolchain. | 216 // A should have the generate bit set since it's in the default toolchain. |
| 214 BuilderRecord* a_record = builder_->GetRecord(a_label); | 217 BuilderRecord* a_record = builder_->GetRecord(a_label); |
| 215 EXPECT_TRUE(a_record->should_generate()); | 218 EXPECT_TRUE(a_record->should_generate()); |
| 216 | 219 |
| 217 // It should have gotten pushed to B. | 220 // It should have gotten pushed to B. |
| 218 EXPECT_TRUE(b_record->should_generate()); | 221 EXPECT_TRUE(b_record->should_generate()); |
| 219 } | 222 } |
| OLD | NEW |