| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/ninja_target_writer.h" | 8 #include "tools/gn/ninja_target_writer.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 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { | 33 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { |
| 34 TestWithScope setup; | 34 TestWithScope setup; |
| 35 Err err; | 35 Err err; |
| 36 | 36 |
| 37 // Make a base target that's a hard dep (action). | 37 // Make a base target that's a hard dep (action). |
| 38 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); | 38 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base"), {}); |
| 39 base_target.set_output_type(Target::ACTION); | 39 base_target.set_output_type(Target::ACTION); |
| 40 base_target.visibility().SetPublic(); | 40 base_target.visibility().SetPublic(); |
| 41 base_target.SetToolchain(setup.toolchain()); | 41 base_target.SetToolchain(setup.toolchain()); |
| 42 base_target.action_values().set_script(SourceFile("//foo/script.py")); | 42 base_target.action_values().set_script(SourceFile("//foo/script.py")); |
| 43 | 43 |
| 44 // Dependent target that also includes a source prerequisite (should get | 44 // Dependent target that also includes a source prerequisite (should get |
| 45 // included) and a source (should not be included). | 45 // included) and a source (should not be included). |
| 46 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 46 Target target(setup.settings(), Label(SourceDir("//foo/"), "target"), {}); |
| 47 target.set_output_type(Target::EXECUTABLE); | 47 target.set_output_type(Target::EXECUTABLE); |
| 48 target.visibility().SetPublic(); | 48 target.visibility().SetPublic(); |
| 49 target.SetToolchain(setup.toolchain()); | 49 target.SetToolchain(setup.toolchain()); |
| 50 target.inputs().push_back(SourceFile("//foo/input.txt")); | 50 target.inputs().push_back(SourceFile("//foo/input.txt")); |
| 51 target.sources().push_back(SourceFile("//foo/source.txt")); | 51 target.sources().push_back(SourceFile("//foo/source.txt")); |
| 52 target.public_deps().push_back(LabelTargetPair(&base_target)); | 52 target.public_deps().push_back(LabelTargetPair(&base_target)); |
| 53 | 53 |
| 54 // Dependent action to test that action sources will be treated the same as | 54 // Dependent action to test that action sources will be treated the same as |
| 55 // inputs. | 55 // inputs. |
| 56 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 56 Target action(setup.settings(), Label(SourceDir("//foo/"), "action"), {}); |
| 57 action.set_output_type(Target::ACTION); | 57 action.set_output_type(Target::ACTION); |
| 58 action.visibility().SetPublic(); | 58 action.visibility().SetPublic(); |
| 59 action.SetToolchain(setup.toolchain()); | 59 action.SetToolchain(setup.toolchain()); |
| 60 action.action_values().set_script(SourceFile("//foo/script.py")); | 60 action.action_values().set_script(SourceFile("//foo/script.py")); |
| 61 action.sources().push_back(SourceFile("//foo/action_source.txt")); | 61 action.sources().push_back(SourceFile("//foo/action_source.txt")); |
| 62 action.public_deps().push_back(LabelTargetPair(&target)); | 62 action.public_deps().push_back(LabelTargetPair(&target)); |
| 63 | 63 |
| 64 ASSERT_TRUE(base_target.OnResolved(&err)); | 64 ASSERT_TRUE(base_target.OnResolved(&err)); |
| 65 ASSERT_TRUE(target.OnResolved(&err)); | 65 ASSERT_TRUE(target.OnResolved(&err)); |
| 66 ASSERT_TRUE(action.OnResolved(&err)); | 66 ASSERT_TRUE(action.OnResolved(&err)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. | 108 // Tests WriteInputDepsStampAndGetDep when toolchain deps are present. |
| 109 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { | 109 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDepWithToolchainDeps) { |
| 110 TestWithScope setup; | 110 TestWithScope setup; |
| 111 Err err; | 111 Err err; |
| 112 | 112 |
| 113 // Toolchain dependency. Here we make a target in the same toolchain for | 113 // Toolchain dependency. Here we make a target in the same toolchain for |
| 114 // simplicity, but in real life (using the Builder) this would be rejected | 114 // simplicity, but in real life (using the Builder) this would be rejected |
| 115 // because it would be a circular dependency (the target depends on its | 115 // because it would be a circular dependency (the target depends on its |
| 116 // toolchain, and the toolchain depends on this target). | 116 // toolchain, and the toolchain depends on this target). |
| 117 Target toolchain_dep_target(setup.settings(), | 117 Target toolchain_dep_target(setup.settings(), |
| 118 Label(SourceDir("//foo/"), "setup")); | 118 Label(SourceDir("//foo/"), "setup"), {}); |
| 119 toolchain_dep_target.set_output_type(Target::ACTION); | 119 toolchain_dep_target.set_output_type(Target::ACTION); |
| 120 toolchain_dep_target.SetToolchain(setup.toolchain()); | 120 toolchain_dep_target.SetToolchain(setup.toolchain()); |
| 121 ASSERT_TRUE(toolchain_dep_target.OnResolved(&err)); | 121 ASSERT_TRUE(toolchain_dep_target.OnResolved(&err)); |
| 122 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); | 122 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target)); |
| 123 | 123 |
| 124 // Make a binary target | 124 // Make a binary target |
| 125 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 125 Target target(setup.settings(), Label(SourceDir("//foo/"), "target"), {}); |
| 126 target.set_output_type(Target::EXECUTABLE); | 126 target.set_output_type(Target::EXECUTABLE); |
| 127 target.SetToolchain(setup.toolchain()); | 127 target.SetToolchain(setup.toolchain()); |
| 128 ASSERT_TRUE(target.OnResolved(&err)); | 128 ASSERT_TRUE(target.OnResolved(&err)); |
| 129 | 129 |
| 130 std::ostringstream stream; | 130 std::ostringstream stream; |
| 131 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 131 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
| 132 OutputFile dep = | 132 OutputFile dep = |
| 133 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 133 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
| 134 | 134 |
| 135 // Since there is more than one dependency, a stamp file will be returned | 135 // Since there is more than one dependency, a stamp file will be returned |
| 136 // and the rule for the stamp file will be written to the stream. | 136 // and the rule for the stamp file will be written to the stream. |
| 137 EXPECT_EQ("obj/foo/setup.stamp", dep.value()); | 137 EXPECT_EQ("obj/foo/setup.stamp", dep.value()); |
| 138 EXPECT_EQ("", stream.str()); | 138 EXPECT_EQ("", stream.str()); |
| 139 } | 139 } |
| OLD | NEW |