Chromium Code Reviews| 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 "tools/gn/target.h" | 5 #include "tools/gn/target.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "tools/gn/config_values_extractors.h" | 10 #include "tools/gn/config_values_extractors.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 return Err(from->defined_from(), "Test-only dependency not allowed.", | 42 return Err(from->defined_from(), "Test-only dependency not allowed.", |
| 43 from->label().GetUserVisibleName(false) + "\n" | 43 from->label().GetUserVisibleName(false) + "\n" |
| 44 "which is NOT marked testonly can't depend on\n" + | 44 "which is NOT marked testonly can't depend on\n" + |
| 45 to->label().GetUserVisibleName(false) + "\n" | 45 to->label().GetUserVisibleName(false) + "\n" |
| 46 "which is marked testonly. Only targets with \"testonly = true\"\n" | 46 "which is marked testonly. Only targets with \"testonly = true\"\n" |
| 47 "can depend on other test-only targets.\n" | 47 "can depend on other test-only targets.\n" |
| 48 "\n" | 48 "\n" |
| 49 "Either mark it test-only or don't do this dependency."); | 49 "Either mark it test-only or don't do this dependency."); |
| 50 } | 50 } |
| 51 | 51 |
| 52 Err MakeStaticLibDepsError(const Target* from, const Target* to) { | |
| 53 return Err(from->defined_from(), | |
| 54 "Complete static libraries can't depend on static libraries.", | |
| 55 from->label().GetUserVisibleName(false) + | |
| 56 "\n" | |
| 57 "which is a complete static library can't depend on\n" + | |
| 58 to->label().GetUserVisibleName(false) + | |
| 59 "\n" | |
| 60 "which is a static library.\n" | |
| 61 "\n" | |
| 62 "Use source sets for intermediate targets instead."); | |
| 63 } | |
| 64 | |
| 52 } // namespace | 65 } // namespace |
| 53 | 66 |
| 54 Target::Target(const Settings* settings, const Label& label) | 67 Target::Target(const Settings* settings, const Label& label) |
| 55 : Item(settings, label), | 68 : Item(settings, label), |
| 56 output_type_(UNKNOWN), | 69 output_type_(UNKNOWN), |
| 57 all_headers_public_(true), | 70 all_headers_public_(true), |
| 58 check_includes_(true), | 71 check_includes_(true), |
| 59 complete_static_lib_(false), | 72 complete_static_lib_(false), |
| 60 testonly_(false), | 73 testonly_(false), |
| 61 hard_dep_(false), | 74 hard_dep_(false), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 PullDependentTargetInfo(); | 132 PullDependentTargetInfo(); |
| 120 PullForwardedDependentConfigs(); | 133 PullForwardedDependentConfigs(); |
| 121 PullRecursiveHardDeps(); | 134 PullRecursiveHardDeps(); |
| 122 | 135 |
| 123 FillOutputFiles(); | 136 FillOutputFiles(); |
| 124 | 137 |
| 125 if (!CheckVisibility(err)) | 138 if (!CheckVisibility(err)) |
| 126 return false; | 139 return false; |
| 127 if (!CheckTestonly(err)) | 140 if (!CheckTestonly(err)) |
| 128 return false; | 141 return false; |
| 142 if (!CheckNoNestedStaticLibs(err)) | |
| 143 return false; | |
| 129 | 144 |
| 130 return true; | 145 return true; |
| 131 } | 146 } |
| 132 | 147 |
| 133 bool Target::IsLinkable() const { | 148 bool Target::IsLinkable() const { |
| 134 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; | 149 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
| 135 } | 150 } |
| 136 | 151 |
| 137 bool Target::IsFinal() const { | 152 bool Target::IsFinal() const { |
| 138 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || | 153 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 334 |
| 320 bool Target::CheckVisibility(Err* err) const { | 335 bool Target::CheckVisibility(Err* err) const { |
| 321 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | 336 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { |
| 322 if (!Visibility::CheckItemVisibility(this, iter.target(), err)) | 337 if (!Visibility::CheckItemVisibility(this, iter.target(), err)) |
| 323 return false; | 338 return false; |
| 324 } | 339 } |
| 325 return true; | 340 return true; |
| 326 } | 341 } |
| 327 | 342 |
| 328 bool Target::CheckTestonly(Err* err) const { | 343 bool Target::CheckTestonly(Err* err) const { |
| 329 // If there current target is marked testonly, it can include both testonly | 344 // If the current target is marked testonly, it can include both testonly |
| 330 // and non-testonly targets, so there's nothing to check. | 345 // and non-testonly targets, so there's nothing to check. |
| 331 if (testonly()) | 346 if (testonly()) |
| 332 return true; | 347 return true; |
| 333 | 348 |
| 334 // Verify no deps have "testonly" set. | 349 // Verify no deps have "testonly" set. |
| 335 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | 350 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { |
| 336 if (iter.target()->testonly()) { | 351 if (iter.target()->testonly()) { |
| 337 *err = MakeTestOnlyError(this, iter.target()); | 352 *err = MakeTestOnlyError(this, iter.target()); |
| 338 return false; | 353 return false; |
| 339 } | 354 } |
| 340 } | 355 } |
| 341 | 356 |
| 342 return true; | 357 return true; |
| 343 } | 358 } |
| 359 | |
| 360 bool Target::CheckNoNestedStaticLibs(Err* err) const { | |
| 361 // If the current target is not a complete static library, it can depend on | |
| 362 // static library targets with no problem. | |
| 363 if (!(output_type() == Target::STATIC_LIBRARY && complete_static_lib())) | |
| 364 return true; | |
| 365 | |
| 366 // Verify no deps are static libraries. | |
| 367 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | |
|
brettw
2014/09/18 19:51:24
I think you'll also need to check inherited_librar
Chris Masone
2014/09/18 20:32:42
Done.
| |
| 368 if (iter.target()->output_type() == Target::STATIC_LIBRARY) { | |
| 369 *err = MakeStaticLibDepsError(this, iter.target()); | |
| 370 return false; | |
| 371 } | |
| 372 } | |
| 373 return true; | |
| 374 } | |
| OLD | NEW |