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/build_settings.h" | 6 #include "tools/gn/build_settings.h" |
7 #include "tools/gn/config.h" | 7 #include "tools/gn/config.h" |
8 #include "tools/gn/scheduler.h" | 8 #include "tools/gn/scheduler.h" |
9 #include "tools/gn/settings.h" | 9 #include "tools/gn/settings.h" |
10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // This target has a generated file and we've decared we write it. | 551 // This target has a generated file and we've decared we write it. |
552 TestTarget existent_generator(setup, "//foo:existent_generator", | 552 TestTarget existent_generator(setup, "//foo:existent_generator", |
553 Target::EXECUTABLE); | 553 Target::EXECUTABLE); |
554 existent_generator.sources().push_back(generated_file); | 554 existent_generator.sources().push_back(generated_file); |
555 EXPECT_TRUE(existent_generator.OnResolved(&err)); | 555 EXPECT_TRUE(existent_generator.OnResolved(&err)); |
556 scheduler.AddWrittenFile(generated_file); | 556 scheduler.AddWrittenFile(generated_file); |
557 | 557 |
558 // Should be OK. | 558 // Should be OK. |
559 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); | 559 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); |
560 } | 560 } |
| 561 |
| 562 TEST(Target, ResolvePrecompiledHeaders) { |
| 563 TestWithScope setup; |
| 564 Err err; |
| 565 |
| 566 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 567 |
| 568 // Target with no settings, no configs, should be a no-op. |
| 569 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
| 570 |
| 571 // Config with PCH values. |
| 572 Config config_1(setup.settings(), Label(SourceDir("//foo/"), "c1")); |
| 573 std::string pch_1("pch.h"); |
| 574 SourceFile pcs_1("//pcs.cc"); |
| 575 config_1.config_values().set_precompiled_header(pch_1); |
| 576 config_1.config_values().set_precompiled_source(pcs_1); |
| 577 target.configs().push_back(LabelConfigPair(&config_1)); |
| 578 |
| 579 // No PCH info specified on target, but the config specifies one, the |
| 580 // values should get copied to the target. |
| 581 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
| 582 EXPECT_EQ(pch_1, target.config_values().precompiled_header()); |
| 583 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); |
| 584 |
| 585 // Now both target and config have matching PCH values. Resolving again |
| 586 // should be a no-op since they all match. |
| 587 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
| 588 EXPECT_TRUE(target.config_values().precompiled_header() == pch_1); |
| 589 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); |
| 590 |
| 591 // Second config with different PCH values. |
| 592 Config config_2(setup.settings(), Label(SourceDir("//foo/"), "c2")); |
| 593 std::string pch_2("pch2.h"); |
| 594 SourceFile pcs_2("//pcs2.cc"); |
| 595 config_2.config_values().set_precompiled_header(pch_2); |
| 596 config_2.config_values().set_precompiled_source(pcs_2); |
| 597 target.configs().push_back(LabelConfigPair(&config_2)); |
| 598 |
| 599 // This should be an error since they don't match. |
| 600 EXPECT_FALSE(target.ResolvePrecompiledHeaders(&err)); |
| 601 |
| 602 // Make sure the proper labels are blamed. |
| 603 EXPECT_EQ( |
| 604 "The target //foo:bar\n" |
| 605 "has conflicting precompiled header settings.\n" |
| 606 "\n" |
| 607 "From //foo:bar\n" |
| 608 " header: pch.h\n" |
| 609 " source: //pcs.cc\n" |
| 610 "\n" |
| 611 "From //foo:c2\n" |
| 612 " header: pch2.h\n" |
| 613 " source: //pcs2.cc", |
| 614 err.help_text()); |
| 615 } |
OLD | NEW |