| 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 19 matching lines...) Expand all Loading... |
| 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.SetToolchain(setup.toolchain()); | 41 base_target.SetToolchain(setup.toolchain()); |
| 41 base_target.action_values().set_script(SourceFile("//foo/script.py")); | 42 base_target.action_values().set_script(SourceFile("//foo/script.py")); |
| 42 | 43 |
| 43 // Dependent target that also includes a source prerequisite (should get | 44 // Dependent target that also includes a source prerequisite (should get |
| 44 // included) and a source (should not be included). | 45 // included) and a source (should not be included). |
| 45 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); | 46 Target target(setup.settings(), Label(SourceDir("//foo/"), "target")); |
| 46 target.set_output_type(Target::EXECUTABLE); | 47 target.set_output_type(Target::EXECUTABLE); |
| 48 target.visibility().SetPublic(); |
| 47 target.SetToolchain(setup.toolchain()); | 49 target.SetToolchain(setup.toolchain()); |
| 48 target.inputs().push_back(SourceFile("//foo/input.txt")); | 50 target.inputs().push_back(SourceFile("//foo/input.txt")); |
| 49 target.sources().push_back(SourceFile("//foo/source.txt")); | 51 target.sources().push_back(SourceFile("//foo/source.txt")); |
| 50 target.deps().push_back(LabelTargetPair(&base_target)); | 52 target.public_deps().push_back(LabelTargetPair(&base_target)); |
| 51 | 53 |
| 52 // 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 |
| 53 // inputs. | 55 // inputs. |
| 54 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 56 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); |
| 55 action.set_output_type(Target::ACTION); | 57 action.set_output_type(Target::ACTION); |
| 58 action.visibility().SetPublic(); |
| 56 action.SetToolchain(setup.toolchain()); | 59 action.SetToolchain(setup.toolchain()); |
| 57 action.action_values().set_script(SourceFile("//foo/script.py")); | 60 action.action_values().set_script(SourceFile("//foo/script.py")); |
| 58 action.sources().push_back(SourceFile("//foo/action_source.txt")); | 61 action.sources().push_back(SourceFile("//foo/action_source.txt")); |
| 59 action.deps().push_back(LabelTargetPair(&target)); | 62 action.public_deps().push_back(LabelTargetPair(&target)); |
| 60 | 63 |
| 61 ASSERT_TRUE(base_target.OnResolved(&err)); | 64 ASSERT_TRUE(base_target.OnResolved(&err)); |
| 62 ASSERT_TRUE(target.OnResolved(&err)); | 65 ASSERT_TRUE(target.OnResolved(&err)); |
| 63 ASSERT_TRUE(action.OnResolved(&err)); | 66 ASSERT_TRUE(action.OnResolved(&err)); |
| 64 | 67 |
| 65 // Input deps for the base (should be only the script itself). | 68 // Input deps for the base (should be only the script itself). |
| 66 { | 69 { |
| 67 std::ostringstream stream; | 70 std::ostringstream stream; |
| 68 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); | 71 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); |
| 69 OutputFile dep = | 72 OutputFile dep = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 std::ostringstream stream; | 131 std::ostringstream stream; |
| 129 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 132 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
| 130 OutputFile dep = | 133 OutputFile dep = |
| 131 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | 134 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
| 132 | 135 |
| 133 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); | 136 EXPECT_EQ("obj/foo/target.inputdeps.stamp", dep.value()); |
| 134 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " | 137 EXPECT_EQ("build obj/foo/target.inputdeps.stamp: stamp " |
| 135 "obj/foo/setup.stamp\n", | 138 "obj/foo/setup.stamp\n", |
| 136 stream.str()); | 139 stream.str()); |
| 137 } | 140 } |
| OLD | NEW |