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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 TestTarget existent_generator(setup, "//foo:existent_generator", | 620 TestTarget existent_generator(setup, "//foo:existent_generator", |
621 Target::EXECUTABLE); | 621 Target::EXECUTABLE); |
622 existent_generator.sources().push_back(generated_file); | 622 existent_generator.sources().push_back(generated_file); |
623 EXPECT_TRUE(existent_generator.OnResolved(&err)); | 623 EXPECT_TRUE(existent_generator.OnResolved(&err)); |
624 scheduler.AddWrittenFile(generated_file); | 624 scheduler.AddWrittenFile(generated_file); |
625 | 625 |
626 // Should be OK. | 626 // Should be OK. |
627 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); | 627 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); |
628 } | 628 } |
629 | 629 |
| 630 TEST(Target, WriteRuntimeDepsGeneratedInputs) { |
| 631 Scheduler scheduler; |
| 632 TestWithScope setup; |
| 633 Err err; |
| 634 |
| 635 SourceFile source_file("//out/Debug/generated.runtime_deps"); |
| 636 OutputFile output_file(setup.build_settings(), source_file); |
| 637 |
| 638 TestTarget generator(setup, "//foo:generator", Target::EXECUTABLE); |
| 639 generator.set_write_runtime_deps_output(output_file); |
| 640 g_scheduler->AddWriteRuntimeDepsTarget(&generator); |
| 641 |
| 642 TestTarget middle_data_dep(setup, "//foo:middle", Target::EXECUTABLE); |
| 643 middle_data_dep.data_deps().push_back(LabelTargetPair(&generator)); |
| 644 |
| 645 // This target has a generated input and no dependency makes it. |
| 646 TestTarget dep_missing(setup, "//foo:no_dep", Target::EXECUTABLE); |
| 647 dep_missing.sources().push_back(source_file); |
| 648 EXPECT_TRUE(dep_missing.OnResolved(&err)); |
| 649 AssertSchedulerHasOneUnknownFileMatching(&dep_missing, source_file); |
| 650 scheduler.ClearUnknownGeneratedInputsAndWrittenFiles(); |
| 651 |
| 652 // This target has a generated file and we've directly dependended on it. |
| 653 TestTarget dep_present(setup, "//foo:with_dep", Target::EXECUTABLE); |
| 654 dep_present.sources().push_back(source_file); |
| 655 dep_present.private_deps().push_back(LabelTargetPair(&generator)); |
| 656 EXPECT_TRUE(dep_present.OnResolved(&err)); |
| 657 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); |
| 658 |
| 659 // This target has a generated file and we've indirectly dependended on it |
| 660 // via data_deps. |
| 661 TestTarget dep_indirect(setup, "//foo:with_dep", Target::EXECUTABLE); |
| 662 dep_indirect.sources().push_back(source_file); |
| 663 dep_indirect.data_deps().push_back(LabelTargetPair(&middle_data_dep)); |
| 664 EXPECT_TRUE(dep_indirect.OnResolved(&err)); |
| 665 AssertSchedulerHasOneUnknownFileMatching(&dep_indirect, source_file); |
| 666 scheduler.ClearUnknownGeneratedInputsAndWrittenFiles(); |
| 667 |
| 668 // This target has a generated file and we've directly dependended on it |
| 669 // via data_deps. |
| 670 TestTarget data_dep_present(setup, "//foo:with_dep", Target::EXECUTABLE); |
| 671 data_dep_present.sources().push_back(source_file); |
| 672 data_dep_present.data_deps().push_back(LabelTargetPair(&generator)); |
| 673 EXPECT_TRUE(data_dep_present.OnResolved(&err)); |
| 674 EXPECT_TRUE(scheduler.GetUnknownGeneratedInputs().empty()); |
| 675 } |
| 676 |
630 // Tests that intermediate object files generated by binary targets are also | 677 // Tests that intermediate object files generated by binary targets are also |
631 // considered generated for the purposes of input checking. Above, we tested | 678 // considered generated for the purposes of input checking. Above, we tested |
632 // the failure cases for generated inputs, so here only test .o files that are | 679 // the failure cases for generated inputs, so here only test .o files that are |
633 // present. | 680 // present. |
634 TEST(Target, ObjectGeneratedInputs) { | 681 TEST(Target, ObjectGeneratedInputs) { |
635 Scheduler scheduler; | 682 Scheduler scheduler; |
636 TestWithScope setup; | 683 TestWithScope setup; |
637 Err err; | 684 Err err; |
638 | 685 |
639 // This target compiles the source. | 686 // This target compiles the source. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); | 874 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); |
828 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); | 875 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); |
829 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); | 876 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); |
830 | 877 |
831 // E does not have any bundle_data information but gets a list of | 878 // E does not have any bundle_data information but gets a list of |
832 // bundle_deps to propagate them during target resolution. | 879 // bundle_deps to propagate them during target resolution. |
833 ASSERT_TRUE(e.bundle_data().file_rules().empty()); | 880 ASSERT_TRUE(e.bundle_data().file_rules().empty()); |
834 ASSERT_TRUE(e.bundle_data().asset_catalog_sources().empty()); | 881 ASSERT_TRUE(e.bundle_data().asset_catalog_sources().empty()); |
835 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); | 882 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); |
836 } | 883 } |
OLD | NEW |